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\Module\Container; |
9
|
|
|
use WebStream\Module\Utility\FileUtils; |
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
|
|
|
use FileUtils; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var Router ルーティングオブジェクト |
25
|
|
|
*/ |
26
|
|
|
private $router; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var Request リクエストオブジェクト |
30
|
|
|
*/ |
31
|
|
|
private $request; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var Response レスポンスオブジェクト |
35
|
|
|
*/ |
36
|
|
|
private $response; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var Session セッションオブジェクト |
40
|
|
|
*/ |
41
|
|
|
private $session; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var Container DIコンテナ |
45
|
|
|
*/ |
46
|
|
|
private $container; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var AnnotationContainer アノテーションコンテナ |
50
|
|
|
*/ |
51
|
|
|
private $annotation; |
|
|
|
|
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* コンストラクタ |
55
|
|
|
* @param Object DIコンテナ |
56
|
|
|
*/ |
57
|
|
|
public function __construct(Container $container) |
58
|
|
|
{ |
59
|
|
|
$this->container = $container; |
60
|
|
|
$this->request = $container->request; |
|
|
|
|
61
|
|
|
$this->response = $container->response; |
|
|
|
|
62
|
|
|
$this->session = $container->session; |
|
|
|
|
63
|
|
|
$this->router = $container->router; |
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Controllerを起動する |
68
|
|
|
*/ |
69
|
|
|
public function runController() |
70
|
|
|
{ |
71
|
|
|
// セッションスタート |
72
|
|
|
$this->session->start(); |
73
|
|
|
// バッファリング開始 |
74
|
|
|
$this->response->start(); |
75
|
|
|
|
76
|
|
|
if ($this->router->controller !== null && $this->router->action !== null) { |
|
|
|
|
77
|
|
|
$iterator = $this->getFileSearchIterator($this->container->applicationInfo->applicationRoot . "/app/controllers"); |
|
|
|
|
78
|
|
|
foreach ($iterator as $filepath => $fileObject) { |
79
|
|
|
if (strpos($filepath, $this->router->controller . ".php") !== false) { |
|
|
|
|
80
|
|
|
include_once $filepath; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
$controllerDelegator = new CoreExecuteDelegator($this->container->coreDelegator->getController(), $this->container); |
|
|
|
|
84
|
|
|
$controllerDelegator->run($this->router->action, [$this->router->params]); |
|
|
|
|
85
|
|
|
} elseif ($this->router->staticFile !== null) { |
|
|
|
|
86
|
|
|
$controller = new CoreController($this->container); |
87
|
|
|
$controller->__callStaticFile($this->router->staticFile); |
|
|
|
|
88
|
|
|
} else { |
89
|
|
|
$this->response->clean(); |
90
|
|
|
$errorMsg = "Failed to resolve the routing: " . $this->request->requestUri; |
91
|
|
|
throw new ResourceNotFoundException($errorMsg); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
$this->response->end(); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Serviceを起動する |
99
|
|
|
* @return CoreService Serviceオブジェクト |
100
|
|
|
*/ |
101
|
|
|
public function runService() |
102
|
|
|
{ |
103
|
|
|
$service = $this->container->coreDelegator->getService(); |
|
|
|
|
104
|
|
|
$service = $service instanceof CoreService ? new CoreExecuteDelegator($service, $this->container) : $this->runModel(); |
105
|
|
|
|
106
|
|
|
return $service; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Modelを起動する |
111
|
|
|
* @return CoreModel Modelオブジェクト |
112
|
|
|
*/ |
113
|
|
|
public function runModel() |
114
|
|
|
{ |
115
|
|
|
$model = $this->container->coreDelegator->getModel(); |
|
|
|
|
116
|
|
|
$model = $model instanceof CoreModel ? new CoreExecuteDelegator($model, $this->container) : $model; |
117
|
|
|
|
118
|
|
|
return $model; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Viewを起動する |
123
|
|
|
* @return CoreView Viewオブジェクト |
124
|
|
|
*/ |
125
|
|
|
public function runView() |
126
|
|
|
{ |
127
|
|
|
return new CoreExecuteDelegator($this->container->coreDelegator->getView(), $this->container); |
|
|
|
|
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Helperを起動する |
132
|
|
|
* @return CoreHelper Helperオブジェクト |
133
|
|
|
*/ |
134
|
|
|
public function runHelper() |
135
|
|
|
{ |
136
|
|
|
$helper = $this->container->coreDelegator->getHelper(); |
|
|
|
|
137
|
|
|
$helper = $helper instanceof CoreHelper ? new CoreExecuteDelegator($helper, $this->container) : $helper; |
138
|
|
|
|
139
|
|
|
return $helper; |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.