summaryrefslogtreecommitdiff
path: root/src/DTS
diff options
context:
space:
mode:
Diffstat (limited to 'src/DTS')
-rw-r--r--src/DTS/Bookmark.php9
-rw-r--r--src/DTS/BookmarkRepository.php25
-rw-r--r--src/DTS/Functions.php2
3 files changed, 30 insertions, 6 deletions
diff --git a/src/DTS/Bookmark.php b/src/DTS/Bookmark.php
index 93c7a29..560fad4 100644
--- a/src/DTS/Bookmark.php
+++ b/src/DTS/Bookmark.php
@@ -10,18 +10,21 @@ class Bookmark
public string $url;
+ public string $title;
+
public string $tag;
public string $addedAt;
- public bool $read;
+ public bool $unread;
- function __construct(string $id, string $url, string $tag, string $addedAt, bool $read)
+ function __construct(string $id, string $url, string $title, string $tag, string $addedAt, bool $unread)
{
$this->id = $id;
$this->url = $url;
+ $this->title = $title;
$this->tag = $tag;
$this->addedAt = $addedAt;
- $this->read = $read;
+ $this->unread = $unread;
}
}
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];
diff --git a/src/DTS/Functions.php b/src/DTS/Functions.php
index b7f9cb3..d7ca835 100644
--- a/src/DTS/Functions.php
+++ b/src/DTS/Functions.php
@@ -4,7 +4,7 @@ declare(strict_types=1);
namespace DTS\Functions;
-function respondAndExit(int $responseCode, string $header, string $body, array $headers = []): void
+function respondAndExit(int $responseCode, string $header, string $body = '', array $headers = []): void
{
header($header, false, $responseCode);