|
1
|
|
|
<?php |
|
2
|
|
|
namespace WebStream\Core; |
|
3
|
|
|
|
|
4
|
|
|
use WebStream\Container\Container; |
|
5
|
|
|
use WebStream\Delegate\Resolver; |
|
6
|
|
|
use WebStream\Exception\ApplicationException; |
|
7
|
|
|
use WebStream\Exception\SystemException; |
|
8
|
|
|
use WebStream\Exception\DelegateException; |
|
9
|
|
|
use WebStream\Module\ServiceLocator; |
|
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Applicationクラス |
|
13
|
|
|
* @author Ryuichi Tanaka |
|
14
|
|
|
* @since 2011/08/19 |
|
15
|
|
|
* @version 0.7 |
|
16
|
|
|
*/ |
|
17
|
|
|
class Application |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @var Container DIコンテナ |
|
21
|
|
|
*/ |
|
22
|
|
|
private $container; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* アプリケーション共通で使用するクラスを初期化する |
|
26
|
|
|
* @param Container DIコンテナ |
|
|
|
|
|
|
27
|
|
|
*/ |
|
28
|
|
|
public function __construct(Container $container) |
|
29
|
|
|
{ |
|
30
|
|
|
register_shutdown_function([&$this, 'shutdownHandler']); |
|
31
|
|
|
$this->container = $container; |
|
32
|
|
|
$this->container->logger->debug("Application start"); |
|
|
|
|
|
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* アプリケーション終了時の処理 |
|
37
|
|
|
*/ |
|
38
|
|
|
public function __destruct() |
|
39
|
|
|
{ |
|
40
|
|
|
$this->container->logger->debug("Application end"); |
|
|
|
|
|
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* アプリケーションを起動する |
|
45
|
|
|
*/ |
|
46
|
|
|
public function run() |
|
47
|
|
|
{ |
|
48
|
|
|
try { |
|
49
|
|
|
$resolver = new Resolver($this->container); |
|
50
|
|
|
$resolver->runController(); // MVCレイヤへのリクエストの振り分けを実行する |
|
51
|
|
|
} catch (ApplicationException $e) { |
|
52
|
|
|
// 内部例外の内、ハンドリングを許可している例外 |
|
53
|
|
|
try { |
|
54
|
|
|
$this->container->logger->error($e->getExceptionAsString()); |
|
|
|
|
|
|
55
|
|
|
$isHandled = false; |
|
56
|
|
|
if ($e instanceof DelegateException) { |
|
57
|
|
|
$isHandled = $e->isHandled(); |
|
58
|
|
|
$e = $e->getOriginException(); |
|
59
|
|
|
} |
|
60
|
|
|
if (!$isHandled) { |
|
61
|
|
|
$this->container->response->move($e->getCode()); |
|
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
} catch (\Exception $e) { |
|
64
|
|
|
// 開発者由来の例外は全て500 |
|
65
|
|
|
$this->container->logger->fatal($e->getExceptionAsString()); |
|
|
|
|
|
|
66
|
|
|
$this->container->response->move(500); |
|
67
|
|
|
} |
|
68
|
|
|
} catch (SystemException $e) { |
|
69
|
|
|
// 内部例外の内、ハンドリング不許可の例外 |
|
70
|
|
|
$this->container->logger->fatal($e->getExceptionAsString()); |
|
71
|
|
|
$this->container->response->move($e->getCode()); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* 例外捕捉不可な異常時のアプリケーション終了処理 |
|
77
|
|
|
*/ |
|
78
|
|
|
public function shutdownHandler() |
|
79
|
|
|
{ |
|
80
|
|
|
if ($error = error_get_last()) { |
|
81
|
|
|
$errorMsg = $error['message'] . " " . $error['file'] . "(" . $error['line'] . ")"; |
|
82
|
|
|
switch ($error['type']) { |
|
83
|
|
|
case E_ERROR: |
|
84
|
|
|
case E_CORE_ERROR: |
|
85
|
|
|
case E_COMPILE_ERROR: |
|
86
|
|
|
case E_USER_ERROR: |
|
87
|
|
|
case E_RECOVERABLE_ERROR: |
|
88
|
|
|
$this->container->logger->fatal($errorMsg); |
|
|
|
|
|
|
89
|
|
|
$this->container->logger->enableDirectWrite(); |
|
90
|
|
|
$this->container->response->move(500); |
|
|
|
|
|
|
91
|
|
|
break; |
|
92
|
|
|
case E_PARSE: |
|
93
|
|
|
$this->container->logger->error($errorMsg); |
|
94
|
|
|
$this->container->logger->enableDirectWrite(); |
|
95
|
|
|
$this->container->response->move(500); |
|
96
|
|
|
break; |
|
97
|
|
|
case E_WARNING: |
|
98
|
|
|
case E_CORE_WARNING: |
|
99
|
|
|
case E_COMPILE_WARNING: |
|
100
|
|
|
case E_USER_WARNING: |
|
101
|
|
|
case E_STRICT: |
|
102
|
|
|
case E_NOTICE: |
|
103
|
|
|
case E_USER_NOTICE: |
|
104
|
|
|
case E_DEPRECATED: |
|
105
|
|
|
case E_USER_DEPRECATED: |
|
106
|
|
|
$this->container->logger->warn($errorMsg); |
|
107
|
|
|
$this->container->logger->enableDirectWrite(); |
|
108
|
|
|
break; |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths