summaryrefslogtreecommitdiff
path: root/src/DTS/BookmarkRepository.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/DTS/BookmarkRepository.php')
-rw-r--r--src/DTS/BookmarkRepository.php25
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];