3 declare(strict_types
=1);
5 namespace Shaarli\Bookmark
;
7 use Shaarli\Bookmark\Exception\BookmarkNotFoundException
;
8 use Shaarli\Bookmark\Exception\NotWritableDataStoreException
;
11 * Class BookmarksService
13 * This is the entry point to manipulate the bookmark DB.
15 * Regarding return types of a list of bookmarks, it can either be an array or an ArrayAccess implementation,
16 * so until PHP 8.0 is the minimal supported version with union return types it cannot be explicitly added.
18 interface BookmarkServiceInterface
21 * Find a bookmark by hash
23 * @param string $hash Bookmark's hash
24 * @param string|null $privateKey Optional key used to access private links while logged out
30 public function findByHash(string $hash, string $privateKey = null);
35 * @return Bookmark|null
37 public function findByUrl(string $url): ?Bookmark
;
42 * @param array $request
43 * @param ?string $visibility
44 * @param bool $caseSensitive
45 * @param bool $untaggedOnly
46 * @param bool $ignoreSticky
47 * @param array $pagination This array can contain the following keys for pagination: limit, offset.
49 * @return SearchResult
51 public function search(
53 string $visibility = null,
54 bool $caseSensitive = false,
55 bool $untaggedOnly = false,
56 bool $ignoreSticky = false,
57 array $pagination = []
61 * Get a single bookmark by its ID.
63 * @param int $id Bookmark ID
64 * @param ?string $visibility all|public|private e.g. with public, accessing a private bookmark will throw an
69 * @throws BookmarkNotFoundException
72 public function get(int $id, string $visibility = null);
75 * Updates an existing bookmark (depending on its ID).
77 * @param Bookmark $bookmark
78 * @param bool $save Writes to the datastore if set to true
80 * @return Bookmark Updated bookmark
82 * @throws BookmarkNotFoundException
85 public function set(Bookmark
$bookmark, bool $save = true): Bookmark
;
88 * Adds a new bookmark (the ID must be empty).
90 * @param Bookmark $bookmark
91 * @param bool $save Writes to the datastore if set to true
93 * @return Bookmark new bookmark
97 public function add(Bookmark
$bookmark, bool $save = true): Bookmark
;
100 * Adds or updates a bookmark depending on its ID:
101 * - a Bookmark without ID will be added
102 * - a Bookmark with an existing ID will be updated
104 * @param Bookmark $bookmark
111 public function addOrSet(Bookmark
$bookmark, bool $save = true): Bookmark
;
114 * Deletes a bookmark.
116 * @param Bookmark $bookmark
121 public function remove(Bookmark
$bookmark, bool $save = true): void;
124 * Get a single bookmark by its ID.
126 * @param int $id Bookmark ID
127 * @param ?string $visibility all|public|private e.g. with public, accessing a private bookmark will throw an
132 public function exists(int $id, string $visibility = null): bool;
135 * Return the number of available bookmarks for given visibility.
137 * @param ?string $visibility public|private|all
139 * @return int Number of bookmarks
141 public function count(string $visibility = null): int;
144 * Write the datastore.
146 * @throws NotWritableDataStoreException
148 public function save(): void;
151 * Returns the list tags appearing in the bookmarks with the given tags
153 * @param array|null $filteringTags tags selecting the bookmarks to consider
154 * @param string|null $visibility process only all/private/public bookmarks
156 * @return array tag => bookmarksCount
158 public function bookmarksCountPerTag(array $filteringTags = [], ?string $visibility = null): array;
161 * Return a list of bookmark matching provided period of time.
162 * It also update directly previous and next date outside of given period found in the datastore.
164 * @param \DateTimeInterface $from Starting date.
165 * @param \DateTimeInterface $to Ending date.
166 * @param \DateTimeInterface|null $previous (by reference) updated with first created date found before $from.
167 * @param \DateTimeInterface|null $next (by reference) updated with first created date found after $to.
169 * @return array List of bookmarks matching provided period of time.
171 public function findByDate(
172 \DateTimeInterface
$from,
173 \DateTimeInterface
$to,
174 ?\DateTimeInterface
&$previous,
175 ?\DateTimeInterface
&$next
179 * Returns the latest bookmark by creation date.
181 * @return Bookmark|null Found Bookmark or null if the datastore is empty.
183 public function getLatest(): ?Bookmark
;
186 * Creates the default database after a fresh install.
188 public function initialize(): void;