diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-01-18 10:01:06 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-18 10:01:06 +0100 |
commit | 3fb29fdda04ca86e04422d49b86cf646d53c4f9d (patch) | |
tree | adf8512f93f5559ba87d0c9931969ae4ebea7133 /application/bookmark/exception | |
parent | 796c4c57d085ae4589b53dfe8369ae9ba30ffdaf (diff) | |
parent | e26e2060f5470ce8bf4c5973284bae07b8af170a (diff) | |
download | Shaarli-3fb29fdda04ca86e04422d49b86cf646d53c4f9d.tar.gz Shaarli-3fb29fdda04ca86e04422d49b86cf646d53c4f9d.tar.zst Shaarli-3fb29fdda04ca86e04422d49b86cf646d53c4f9d.zip |
Store bookmarks as PHP objects and add a service layer to retriā¦ (#1307)
Store bookmarks as PHP objects and add a service layer to retrieve them
Diffstat (limited to 'application/bookmark/exception')
-rw-r--r-- | application/bookmark/exception/BookmarkNotFoundException.php (renamed from application/bookmark/exception/LinkNotFoundException.php) | 2 | ||||
-rw-r--r-- | application/bookmark/exception/EmptyDataStoreException.php | 7 | ||||
-rw-r--r-- | application/bookmark/exception/InvalidBookmarkException.php | 30 | ||||
-rw-r--r-- | application/bookmark/exception/NotWritableDataStoreException.php | 19 |
4 files changed, 57 insertions, 1 deletions
diff --git a/application/bookmark/exception/LinkNotFoundException.php b/application/bookmark/exception/BookmarkNotFoundException.php index f9414428..827a3d35 100644 --- a/application/bookmark/exception/LinkNotFoundException.php +++ b/application/bookmark/exception/BookmarkNotFoundException.php | |||
@@ -3,7 +3,7 @@ namespace Shaarli\Bookmark\Exception; | |||
3 | 3 | ||
4 | use Exception; | 4 | use Exception; |
5 | 5 | ||
6 | class LinkNotFoundException extends Exception | 6 | class BookmarkNotFoundException extends Exception |
7 | { | 7 | { |
8 | /** | 8 | /** |
9 | * LinkNotFoundException constructor. | 9 | * LinkNotFoundException constructor. |
diff --git a/application/bookmark/exception/EmptyDataStoreException.php b/application/bookmark/exception/EmptyDataStoreException.php new file mode 100644 index 00000000..cd48c1e6 --- /dev/null +++ b/application/bookmark/exception/EmptyDataStoreException.php | |||
@@ -0,0 +1,7 @@ | |||
1 | <?php | ||
2 | |||
3 | |||
4 | namespace Shaarli\Bookmark\Exception; | ||
5 | |||
6 | |||
7 | class EmptyDataStoreException extends \Exception {} | ||
diff --git a/application/bookmark/exception/InvalidBookmarkException.php b/application/bookmark/exception/InvalidBookmarkException.php new file mode 100644 index 00000000..10c84a6d --- /dev/null +++ b/application/bookmark/exception/InvalidBookmarkException.php | |||
@@ -0,0 +1,30 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Shaarli\Bookmark\Exception; | ||
4 | |||
5 | use Shaarli\Bookmark\Bookmark; | ||
6 | |||
7 | class InvalidBookmarkException extends \Exception | ||
8 | { | ||
9 | public function __construct($bookmark) | ||
10 | { | ||
11 | if ($bookmark instanceof Bookmark) { | ||
12 | if ($bookmark->getCreated() instanceof \DateTime) { | ||
13 | $created = $bookmark->getCreated()->format(\DateTime::ATOM); | ||
14 | } elseif (empty($bookmark->getCreated())) { | ||
15 | $created = ''; | ||
16 | } else { | ||
17 | $created = 'Not a DateTime object'; | ||
18 | } | ||
19 | $this->message = 'This bookmark is not valid'. PHP_EOL; | ||
20 | $this->message .= ' - ID: '. $bookmark->getId() . PHP_EOL; | ||
21 | $this->message .= ' - Title: '. $bookmark->getTitle() . PHP_EOL; | ||
22 | $this->message .= ' - Url: '. $bookmark->getUrl() . PHP_EOL; | ||
23 | $this->message .= ' - ShortUrl: '. $bookmark->getShortUrl() . PHP_EOL; | ||
24 | $this->message .= ' - Created: '. $created . PHP_EOL; | ||
25 | } else { | ||
26 | $this->message = 'The provided data is not a bookmark'. PHP_EOL; | ||
27 | $this->message .= var_export($bookmark, true); | ||
28 | } | ||
29 | } | ||
30 | } | ||
diff --git a/application/bookmark/exception/NotWritableDataStoreException.php b/application/bookmark/exception/NotWritableDataStoreException.php new file mode 100644 index 00000000..95f34b50 --- /dev/null +++ b/application/bookmark/exception/NotWritableDataStoreException.php | |||
@@ -0,0 +1,19 @@ | |||
1 | <?php | ||
2 | |||
3 | |||
4 | namespace Shaarli\Bookmark\Exception; | ||
5 | |||
6 | |||
7 | class NotWritableDataStoreException extends \Exception | ||
8 | { | ||
9 | /** | ||
10 | * NotReadableDataStore constructor. | ||
11 | * | ||
12 | * @param string $dataStore file path | ||
13 | */ | ||
14 | public function __construct($dataStore) | ||
15 | { | ||
16 | $this->message = 'Couldn\'t load data from the data store file "'. $dataStore .'". '. | ||
17 | 'Your data might be corrupted, or your file isn\'t readable.'; | ||
18 | } | ||
19 | } | ||