aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/bookmark/exception/InvalidBookmarkException.php
blob: 10c84a6d2b66cb7d5a6c7ee2015c96f805d5acf0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php

namespace Shaarli\Bookmark\Exception;

use Shaarli\Bookmark\Bookmark;

class InvalidBookmarkException extends \Exception
{
    public function __construct($bookmark)
    {
        if ($bookmark instanceof Bookmark) {
            if ($bookmark->getCreated() instanceof \DateTime) {
                $created = $bookmark->getCreated()->format(\DateTime::ATOM);
            } elseif (empty($bookmark->getCreated())) {
                $created = '';
            } else {
                $created = 'Not a DateTime object';
            }
            $this->message = 'This bookmark is not valid'. PHP_EOL;
            $this->message .= ' - ID: '. $bookmark->getId() . PHP_EOL;
            $this->message .= ' - Title: '. $bookmark->getTitle() . PHP_EOL;
            $this->message .= ' - Url: '. $bookmark->getUrl() . PHP_EOL;
            $this->message .= ' - ShortUrl: '. $bookmark->getShortUrl() . PHP_EOL;
            $this->message .= ' - Created: '. $created . PHP_EOL;
        } else {
            $this->message = 'The provided data is not a bookmark'. PHP_EOL;
            $this->message .= var_export($bookmark, true);
        }
    }
}