diff options
| author | David T. Sadler <davidtsadler@googlemail.com> | 2021-10-07 21:31:17 +0100 | 
|---|---|---|
| committer | David T. Sadler <davidtsadler@googlemail.com> | 2021-10-07 21:31:17 +0100 | 
| commit | 0f273c0a8ead390346571c4be2296fa6e384eff6 (patch) | |
| tree | 292fc180a277a5324df73c5c8b02c8c673e812a3 /src/DTS/BookmarkRepository.php | |
| parent | 34ba17ceeecd3ac6be9e31be45ee76757da2dec0 (diff) | |
Add bookmarks
Diffstat (limited to 'src/DTS/BookmarkRepository.php')
| -rw-r--r-- | src/DTS/BookmarkRepository.php | 25 | 
1 files changed, 23 insertions, 2 deletions
diff --git a/src/DTS/BookmarkRepository.php b/src/DTS/BookmarkRepository.php index deb188c..ab54594 100644 --- a/src/DTS/BookmarkRepository.php +++ b/src/DTS/BookmarkRepository.php @@ -31,8 +31,9 @@ class BookmarkRepository implements \Iterator              $this->repository[] = new Bookmark(                  $data[0],       // Id.                  $data[1],       // Url. -                $data[2],       // Tag. -                $data[3],       // Added At. +                $data[2],       // Title. +                $data[3],       // Tag. +                $data[4],       // Added At.                  (bool)$data[4], // Read.              );          } @@ -60,6 +61,26 @@ class BookmarkRepository implements \Iterator          return $this;      } +    public function add(Bookmark $bookmark): bool +    { +        if (($fp = fopen($this->pathToRepository, 'a')) === FALSE) { +            throw new \Exception("Unable to open repository {$this->pathToRepository}"); +        } + +        $saved = fputcsv($fp, [ +            $bookmark->id, +            $bookmark->url, +            $bookmark->title, +            $bookmark->tag, +            $bookmark->addedAt, +            (int)$bookmark->unread, +        ]); + +        fclose($fp); + +        return $saved !== false; +    } +      public function current(): mixed      {          return $this->repository[$this->position];  | 
