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
50 public function search(
52 string $visibility = null,
53 bool $caseSensitive = false,
54 bool $untaggedOnly = false,
55 bool $ignoreSticky = false
59 * Get a single bookmark by its ID.
61 * @param int $id Bookmark ID
62 * @param ?string $visibility all|public|private e.g. with public, accessing a private bookmark will throw an
67 * @throws BookmarkNotFoundException
70 public function get(int $id, string $visibility = null);
73 * Updates an existing bookmark (depending on its ID).
75 * @param Bookmark $bookmark
76 * @param bool $save Writes to the datastore if set to true
78 * @return Bookmark Updated bookmark
80 * @throws BookmarkNotFoundException
83 public function set(Bookmark
$bookmark, bool $save = true): Bookmark
;
86 * Adds a new bookmark (the ID must be empty).
88 * @param Bookmark $bookmark
89 * @param bool $save Writes to the datastore if set to true
91 * @return Bookmark new bookmark
95 public function add(Bookmark
$bookmark, bool $save = true): Bookmark
;
98 * Adds or updates a bookmark depending on its ID:
99 * - a Bookmark without ID will be added
100 * - a Bookmark with an existing ID will be updated
102 * @param Bookmark $bookmark
109 public function addOrSet(Bookmark
$bookmark, bool $save = true): Bookmark
;
112 * Deletes a bookmark.
114 * @param Bookmark $bookmark
119 public function remove(Bookmark
$bookmark, bool $save = true): void;
122 * Get a single bookmark by its ID.
124 * @param int $id Bookmark ID
125 * @param ?string $visibility all|public|private e.g. with public, accessing a private bookmark will throw an
130 public function exists(int $id, string $visibility = null): bool;
133 * Return the number of available bookmarks for given visibility.
135 * @param ?string $visibility public|private|all
137 * @return int Number of bookmarks
139 public function count(string $visibility = null): int;
142 * Write the datastore.
144 * @throws NotWritableDataStoreException
146 public function save(): void;
149 * Returns the list tags appearing in the bookmarks with the given tags
151 * @param array|null $filteringTags tags selecting the bookmarks to consider
152 * @param string|null $visibility process only all/private/public bookmarks
154 * @return array tag => bookmarksCount
156 public function bookmarksCountPerTag(array $filteringTags = [], ?string $visibility = null): array;
159 * Return a list of bookmark matching provided period of time.
160 * It also update directly previous and next date outside of given period found in the datastore.
162 * @param \DateTimeInterface $from Starting date.
163 * @param \DateTimeInterface $to Ending date.
164 * @param \DateTimeInterface|null $previous (by reference) updated with first created date found before $from.
165 * @param \DateTimeInterface|null $next (by reference) updated with first created date found after $to.
167 * @return array List of bookmarks matching provided period of time.
169 public function findByDate(
170 \DateTimeInterface
$from,
171 \DateTimeInterface
$to,
172 ?\DateTimeInterface
&$previous,
173 ?\DateTimeInterface
&$next
177 * Returns the latest bookmark by creation date.
179 * @return Bookmark|null Found Bookmark or null if the datastore is empty.
181 public function getLatest(): ?Bookmark
;
184 * Creates the default database after a fresh install.
186 public function initialize(): void;