|
1
|
|
|
<?php |
|
2
|
|
|
namespace WebStream\Delegate; |
|
3
|
|
|
|
|
4
|
|
|
use WebStream\Core\CoreController; |
|
5
|
|
|
use WebStream\Core\CoreService; |
|
6
|
|
|
use WebStream\Core\CoreModel; |
|
7
|
|
|
use WebStream\Core\CoreHelper; |
|
8
|
|
|
use WebStream\Container\Container; |
|
9
|
|
|
use WebStream\IO\File; |
|
10
|
|
|
use WebStream\Exception\Extend\RouterException; |
|
11
|
|
|
use WebStream\Exception\Extend\ResourceNotFoundException; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Resolver |
|
15
|
|
|
* @author Ryuichi TANAKA. |
|
16
|
|
|
* @since 2012/12/22 |
|
17
|
|
|
* @version 0.7 |
|
18
|
|
|
*/ |
|
19
|
|
|
class Resolver |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @var Router ルーティングオブジェクト |
|
23
|
|
|
*/ |
|
24
|
|
|
private $router; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var Request リクエストオブジェクト |
|
|
|
|
|
|
28
|
|
|
*/ |
|
29
|
|
|
private $request; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var Response レスポンスオブジェクト |
|
|
|
|
|
|
33
|
|
|
*/ |
|
34
|
|
|
private $response; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var Session セッションオブジェクト |
|
|
|
|
|
|
38
|
|
|
*/ |
|
39
|
|
|
private $session; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @var Container DIコンテナ |
|
43
|
|
|
*/ |
|
44
|
|
|
private $container; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @var AnnotationContainer アノテーションコンテナ |
|
|
|
|
|
|
48
|
|
|
*/ |
|
49
|
|
|
private $annotation; |
|
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* コンストラクタ |
|
53
|
|
|
* @param Object DIコンテナ |
|
|
|
|
|
|
54
|
|
|
*/ |
|
55
|
|
|
public function __construct(Container $container) |
|
56
|
|
|
{ |
|
57
|
|
|
$this->container = $container; |
|
58
|
|
|
$this->request = $container->request; |
|
|
|
|
|
|
59
|
|
|
$this->response = $container->response; |
|
|
|
|
|
|
60
|
|
|
$this->session = $container->session; |
|
|
|
|
|
|
61
|
|
|
$this->router = $container->router; |
|
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Controllerを起動する |
|
66
|
|
|
*/ |
|
67
|
|
|
public function runController() |
|
68
|
|
|
{ |
|
69
|
|
|
// セッションスタート |
|
70
|
|
|
$this->session->start(); |
|
71
|
|
|
// バッファリング開始 |
|
72
|
|
|
$this->response->start(); |
|
73
|
|
|
|
|
74
|
|
|
if ($this->router->controller !== null && $this->router->action !== null) { |
|
75
|
|
|
$iterator = []; |
|
76
|
|
|
$file = new File($this->container->applicationInfo->applicationRoot . "/app/controllers"); |
|
|
|
|
|
|
77
|
|
|
if ($file->exists() && $file->isDirectory()) { |
|
78
|
|
|
$iterator = new \RecursiveIteratorIterator( |
|
79
|
|
|
new \RecursiveDirectoryIterator($file->getFilePath()), |
|
80
|
|
|
\RecursiveIteratorIterator::LEAVES_ONLY, |
|
81
|
|
|
\RecursiveIteratorIterator::CATCH_GET_CHILD // for Permission deny |
|
82
|
|
|
); |
|
83
|
|
|
} |
|
84
|
|
|
foreach ($iterator as $filepath => $fileObject) { |
|
85
|
|
|
if (strpos($filepath, $this->router->controller . ".php") !== false) { |
|
86
|
|
|
include_once $filepath; |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
$controllerDelegator = new CoreExecuteDelegator($this->container->coreDelegator->getController(), $this->container); |
|
|
|
|
|
|
90
|
|
|
$controllerDelegator->run($this->router->action, [$this->router->params]); |
|
91
|
|
|
} elseif ($this->router->staticFile !== null) { |
|
92
|
|
|
$controller = new CoreController(); |
|
93
|
|
|
$controller->inject('coreDelegator', $this->container->coreDelegator) |
|
94
|
|
|
->inject('logger', $this->container->logger); |
|
|
|
|
|
|
95
|
|
|
|
|
96
|
|
|
$controller->__callStaticFile($this->router->staticFile); |
|
97
|
|
|
} else { |
|
98
|
|
|
$this->response->clean(); |
|
99
|
|
|
$errorMsg = "Failed to resolve the routing: " . $this->request->requestUri; |
|
100
|
|
|
throw new ResourceNotFoundException($errorMsg); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
$this->response->end(); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Serviceを起動する |
|
108
|
|
|
* @return CoreService Serviceオブジェクト |
|
109
|
|
|
*/ |
|
110
|
|
|
public function runService() |
|
111
|
|
|
{ |
|
112
|
|
|
$service = $this->container->coreDelegator->getService(); |
|
|
|
|
|
|
113
|
|
|
$service = $service instanceof CoreService ? new CoreExecuteDelegator($service, $this->container) : $this->runModel(); |
|
114
|
|
|
|
|
115
|
|
|
return $service; |
|
|
|
|
|
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* Modelを起動する |
|
120
|
|
|
* @return CoreModel Modelオブジェクト |
|
121
|
|
|
*/ |
|
122
|
|
|
public function runModel() |
|
123
|
|
|
{ |
|
124
|
|
|
$model = $this->container->coreDelegator->getModel(); |
|
|
|
|
|
|
125
|
|
|
$model = $model instanceof CoreModel ? new CoreExecuteDelegator($model, $this->container) : $model; |
|
126
|
|
|
|
|
127
|
|
|
return $model; |
|
|
|
|
|
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* Viewを起動する |
|
132
|
|
|
* @return CoreView Viewオブジェクト |
|
|
|
|
|
|
133
|
|
|
*/ |
|
134
|
|
|
public function runView() |
|
135
|
|
|
{ |
|
136
|
|
|
return new CoreExecuteDelegator($this->container->coreDelegator->getView(), $this->container); |
|
|
|
|
|
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* Helperを起動する |
|
141
|
|
|
* @return CoreHelper Helperオブジェクト |
|
142
|
|
|
*/ |
|
143
|
|
|
public function runHelper() |
|
144
|
|
|
{ |
|
145
|
|
|
$helper = $this->container->coreDelegator->getHelper(); |
|
|
|
|
|
|
146
|
|
|
$helper = $helper instanceof CoreHelper ? new CoreExecuteDelegator($helper, $this->container) : $helper; |
|
147
|
|
|
|
|
148
|
|
|
return $helper; |
|
|
|
|
|
|
149
|
|
|
} |
|
150
|
|
|
} |
|
151
|
|
|
|
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