aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/updater/exception/UpdaterException.php
diff options
context:
space:
mode:
authorVirtualTam <virtualtam@flibidi.net>2018-12-03 23:49:20 +0100
committerVirtualTam <virtualtam@flibidi.net>2019-01-12 23:11:19 +0100
commitbcf056c9d92e5240e645c76a4cdc8ae159693f9a (patch)
tree3991d2e0703276474a3fa5b0f3cccc63b2e74f19 /application/updater/exception/UpdaterException.php
parent92c6439dbc41d8a2873dfebbc44e30d75c0c473d (diff)
downloadShaarli-bcf056c9d92e5240e645c76a4cdc8ae159693f9a.tar.gz
Shaarli-bcf056c9d92e5240e645c76a4cdc8ae159693f9a.tar.zst
Shaarli-bcf056c9d92e5240e645c76a4cdc8ae159693f9a.zip
namespacing: \Shaarli\Updater
Signed-off-by: VirtualTam <virtualtam@flibidi.net>
Diffstat (limited to 'application/updater/exception/UpdaterException.php')
-rw-r--r--application/updater/exception/UpdaterException.php60
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
3namespace Shaarli\Updater\Exception;
4
5use Exception;
6
7/**
8 * Class UpdaterException.
9 */
10class 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}