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