From 4a40b41f386af23da54cd35b8abac1f27c8e5ef7 Mon Sep 17 00:00:00 2001 From: "David T. Sadler" Date: Mon, 8 Nov 2021 20:50:15 +0000 Subject: Filter by tag --- src/DTS/BookmarkRepository.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/DTS') diff --git a/src/DTS/BookmarkRepository.php b/src/DTS/BookmarkRepository.php index 01f6de4..fde8510 100644 --- a/src/DTS/BookmarkRepository.php +++ b/src/DTS/BookmarkRepository.php @@ -12,6 +12,8 @@ class BookmarkRepository implements \Iterator private array $repository = []; + private array $tags = []; + private int $position = 0; function __construct(string $pathToRepository) @@ -75,6 +77,11 @@ class BookmarkRepository implements \Iterator return false; } + public function tags(): array + { + return $this->tags; + } + public function current(): mixed { return $this->repository[$this->position]; @@ -122,8 +129,14 @@ class BookmarkRepository implements \Iterator $bookmark->addedAt = $data[3]; $this->repository[] = $bookmark; + + $this->tags[] = $bookmark->tag; } + $this->tags = array_filter(array_unique($this->tags)); + + sort($this->tags); + fclose($fp); } -- cgit v1.2.3-13-gbd6f