diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-10-13 12:07:13 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2020-10-13 12:07:13 +0200 |
commit | d9f6275ebca035fec8331652c677981056793ccc (patch) | |
tree | 37a64baf4f0eba6b781040605965383d8aded2cc /application/updater/exception/UpdaterException.php | |
parent | 38672ba0d1c722e5d6d33a58255ceb55e9410e46 (diff) | |
parent | d63ff87a009313141ae684ec447b902562ff6ee7 (diff) | |
download | Shaarli-d9f6275ebca035fec8331652c677981056793ccc.tar.gz Shaarli-d9f6275ebca035fec8331652c677981056793ccc.tar.zst Shaarli-d9f6275ebca035fec8331652c677981056793ccc.zip |
Merge branch 'v0.11' into stablestable
Diffstat (limited to 'application/updater/exception/UpdaterException.php')
-rw-r--r-- | application/updater/exception/UpdaterException.php | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/application/updater/exception/UpdaterException.php b/application/updater/exception/UpdaterException.php new file mode 100644 index 00000000..20aceccf --- /dev/null +++ b/application/updater/exception/UpdaterException.php | |||
@@ -0,0 +1,60 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Shaarli\Updater\Exception; | ||
4 | |||
5 | use Exception; | ||
6 | |||
7 | /** | ||
8 | * Class UpdaterException. | ||
9 | */ | ||
10 | class UpdaterException extends Exception | ||
11 | { | ||
12 | /** | ||
13 | * @var string Method where the error occurred. | ||
14 | */ | ||
15 | protected $method; | ||
16 | |||
17 | /** | ||
18 | * @var Exception The parent exception. | ||
19 | */ | ||
20 | protected $previous; | ||
21 | |||
22 | /** | ||
23 | * Constructor. | ||
24 | * | ||
25 | * @param string $message Force the error message if set. | ||
26 | * @param string $method Method where the error occurred. | ||
27 | * @param Exception|bool $previous Parent exception. | ||
28 | */ | ||
29 | public function __construct($message = '', $method = '', $previous = false) | ||
30 | { | ||
31 | $this->method = $method; | ||
32 | $this->previous = $previous; | ||
33 | $this->message = $this->buildMessage($message); | ||
34 | } | ||
35 | |||
36 | /** | ||
37 | * Build the exception error message. | ||
38 | * | ||
39 | * @param string $message Optional given error message. | ||
40 | * | ||
41 | * @return string The built error message. | ||
42 | */ | ||
43 | private function buildMessage($message) | ||
44 | { | ||
45 | $out = ''; | ||
46 | if (!empty($message)) { | ||
47 | $out .= $message . PHP_EOL; | ||
48 | } | ||
49 | |||
50 | if (!empty($this->method)) { | ||
51 | $out .= t('An error occurred while running the update ') . $this->method . PHP_EOL; | ||
52 | } | ||
53 | |||
54 | if (!empty($this->previous)) { | ||
55 | $out .= ' ' . $this->previous->getMessage(); | ||
56 | } | ||
57 | |||
58 | return $out; | ||
59 | } | ||
60 | } | ||