1 | <?php |
||
10 | class ApplicationException extends \LogicException |
||
11 | { |
||
12 | /** |
||
13 | * @var string エラーメッセージ |
||
14 | */ |
||
15 | private $errorMessage; |
||
16 | |||
17 | /** |
||
18 | * constructor |
||
19 | * @param string $message エラーメッセージ |
||
20 | * @param int $code ステータスコード |
||
21 | * @param Exception $exception 例外オブジェクト |
||
22 | */ |
||
23 | 4 | public function __construct($message, $code = 500, $exception = null) |
|
24 | { |
||
25 | 4 | parent::__construct($message, $code); |
|
26 | |||
27 | 4 | if ($exception === null) { |
|
28 | $exception = $this; |
||
29 | } |
||
30 | |||
31 | 4 | if (!empty($message)) { |
|
32 | $message .= " "; |
||
33 | } |
||
34 | |||
35 | 4 | $this->errorMessage = get_class($exception) . " is thrown: " . $message . $exception->getFile() . "(" . $exception->getLine() . ")"; |
|
36 | 4 | $stacktraceList = explode("#", $exception->getTraceAsString()); |
|
37 | 4 | foreach ($stacktraceList as $stacktraceLine) { |
|
38 | 4 | if ($stacktraceLine === "") { |
|
39 | 4 | continue; |
|
40 | } |
||
41 | 4 | $this->errorMessage .= PHP_EOL; |
|
42 | 4 | $this->errorMessage .= "\t#" . trim($stacktraceLine); |
|
43 | } |
||
44 | 4 | } |
|
45 | |||
46 | /** |
||
47 | * エラーメッセージを返却する |
||
48 | * @return string エラーメッセージ |
||
49 | */ |
||
50 | 14 | public function getExceptionAsString(): string |
|
54 | } |
||
55 |