diff options
| author | David T. Sadler <davidtsadler@googlemail.com> | 2021-10-26 21:07:43 +0100 |
|---|---|---|
| committer | David T. Sadler <davidtsadler@googlemail.com> | 2021-10-26 21:07:43 +0100 |
| commit | ae205d810b62dce5e3e11aef07358c11ded48c77 (patch) | |
| tree | 0196ae98aefb93b719d6b21cc065e22c1ecf992b /src/DTS | |
| parent | d4122f116c937e0ec509d8cefe540146ec27a0cd (diff) | |
Implement old
Diffstat (limited to 'src/DTS')
| -rw-r--r-- | src/DTS/Bookmark.php | 6 | ||||
| -rw-r--r-- | src/DTS/Old.php | 30 | ||||
| -rw-r--r-- | src/DTS/Session.php | 2 | ||||
| -rw-r--r-- | src/DTS/Validated.php | 6 | ||||
| -rw-r--r-- | src/DTS/Validator.php | 3 |
5 files changed, 39 insertions, 8 deletions
diff --git a/src/DTS/Bookmark.php b/src/DTS/Bookmark.php index 543a552..da9afa9 100644 --- a/src/DTS/Bookmark.php +++ b/src/DTS/Bookmark.php @@ -8,11 +8,11 @@ class Bookmark { public string $id; - public string $url; + public string $url = ''; - public string $title; + public string $title = ''; - public string $tag; + public string $tag = ''; public string $addedAt; diff --git a/src/DTS/Old.php b/src/DTS/Old.php new file mode 100644 index 0000000..8545f8d --- /dev/null +++ b/src/DTS/Old.php @@ -0,0 +1,30 @@ +<?php + +declare(strict_types=1); + +namespace DTS; + +class Old +{ + const FIELDS = [ + 'url', + 'title', + 'tag', + ]; + + private array $old = []; + + function __construct(array $request = []) + { + foreach(self::FIELDS as $field) { + if (array_key_exists($field, $request)) { + $this->old[$field] = $request[$field]; + } + } + } + + public function get(string $key, mixed $default = null): mixed + { + return $this->old[$key] ?? $default; + } +} diff --git a/src/DTS/Session.php b/src/DTS/Session.php index e5da42f..445f31c 100644 --- a/src/DTS/Session.php +++ b/src/DTS/Session.php @@ -8,7 +8,7 @@ class Session { private static ?self $instance = null; - private array $session; + private array $session = []; public static function getInstance() { diff --git a/src/DTS/Validated.php b/src/DTS/Validated.php index 5df8af7..86c6f64 100644 --- a/src/DTS/Validated.php +++ b/src/DTS/Validated.php @@ -6,9 +6,9 @@ namespace DTS; class Validated { - public ?string $url; + public string $url = ''; - public ?string $title; + public string $title = ''; - public ?string $tag; + public string $tag = ''; } diff --git a/src/DTS/Validator.php b/src/DTS/Validator.php index 7629e3b..472b38f 100644 --- a/src/DTS/Validator.php +++ b/src/DTS/Validator.php @@ -13,7 +13,8 @@ class Validator public Validated $validated; - function __construct(array $request) { + function __construct(array $request) + { $this->errors = new Errors(); $this->validated = new Validated(); |
