1
|
|
|
<?php |
2
|
|
|
namespace WebStream\Delegate; |
3
|
|
|
|
4
|
|
|
use WebStream\Core\CoreInterface; |
5
|
|
|
use WebStream\Core\CoreController; |
6
|
|
|
use WebStream\Core\CoreService; |
7
|
|
|
use WebStream\Core\CoreModel; |
8
|
|
|
use WebStream\Core\CoreView; |
9
|
|
|
use WebStream\Core\CoreHelper; |
10
|
|
|
use WebStream\Container\Container; |
11
|
|
|
use WebStream\Annotation\Base\IAnnotatable; |
12
|
|
|
use WebStream\Annotation\Reader\AnnotationReader; |
13
|
|
|
use WebStream\Annotation\Container\AnnotationContainer; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* AnnotationDelegator |
17
|
|
|
* @author Ryuichi TANAKA. |
18
|
|
|
* @since 2015/02/11 |
19
|
|
|
* @version 0.4 |
20
|
|
|
*/ |
21
|
|
|
class AnnotationDelegator |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var Container コンテナ |
25
|
|
|
*/ |
26
|
|
|
private $container; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var Logger ロガー |
|
|
|
|
30
|
|
|
*/ |
31
|
|
|
private $logger; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Constructor |
35
|
|
|
* @param CoreInterface インスタンス |
36
|
|
|
* @param Container DIContainer |
37
|
|
|
*/ |
|
|
|
|
38
|
|
|
public function __construct(Container $container) |
39
|
|
|
{ |
40
|
|
|
$this->container = $container; |
41
|
|
|
$this->logger = $container->logger; |
|
|
|
|
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Destructor |
46
|
|
|
*/ |
47
|
|
|
public function __destruct() |
48
|
|
|
{ |
49
|
|
|
$this->logger->debug("AnnotationDelegator container is clear."); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* アノテーション情報をロードする |
54
|
|
|
* @param object インスタンス |
55
|
|
|
* @param string メソッド |
56
|
|
|
* @param string アノテーションクラスパス |
57
|
|
|
* @return Container コンテナ |
58
|
|
|
*/ |
|
|
|
|
59
|
|
|
public function read($instance, $method = null, $classpath = null) |
60
|
|
|
{ |
61
|
|
|
if (!$instance instanceof IAnnotatable) { |
62
|
|
|
$this->logger->warn("Annotation is not available this class: " . get_class($instance)); |
63
|
|
|
return; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$this->container->executeMethod = $method ?: ""; |
|
|
|
|
67
|
|
|
|
68
|
|
|
if ($instance instanceof CoreController) { |
69
|
|
|
return $this->readController($instance, $classpath); |
70
|
|
|
} elseif ($instance instanceof CoreService) { |
71
|
|
|
return $this->readService($instance, $classpath); |
72
|
|
|
} elseif ($instance instanceof CoreModel) { |
73
|
|
|
return $this->readModel($instance, $classpath); |
74
|
|
|
} elseif ($instance instanceof CoreView) { |
75
|
|
|
return $this->readView($instance, $classpath); |
76
|
|
|
} elseif ($instance instanceof CoreHelper) { |
77
|
|
|
return $this->readHelper($instance, $classpath); |
78
|
|
|
} else { |
79
|
|
|
return $this->readModule($instance, $classpath); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Controllerのアノテーション情報をロードする |
85
|
|
|
* @param CoreController インスタンス |
86
|
|
|
* @param string アノテーションクラスパス |
87
|
|
|
* @return Container コンテナ |
88
|
|
|
*/ |
|
|
|
|
89
|
|
|
private function readController(CoreController $instance, $classpath) |
90
|
|
|
{ |
91
|
|
|
$container = $this->container; |
92
|
|
|
$reader = new AnnotationReader($instance, $container); |
|
|
|
|
93
|
|
|
$reader->read($classpath); |
|
|
|
|
94
|
|
|
$injectedAnnotation = $reader->getInjectedAnnotationInfo(); |
|
|
|
|
95
|
|
|
|
96
|
|
|
$factory = new AnnotationDelegatorFactory($injectedAnnotation, $container); |
97
|
|
|
$annotationContainer = new AnnotationContainer(); |
98
|
|
|
|
99
|
|
|
// exceptions |
100
|
|
|
$annotationContainer->exception = $reader->getException(); |
|
|
|
|
101
|
|
|
|
102
|
|
|
// @Header |
103
|
|
|
$annotationContainer->header = $factory->createAnnotationCallable("header"); |
|
|
|
|
104
|
|
|
|
105
|
|
|
// @Filter |
106
|
|
|
$annotationContainer->filter = $factory->createAnnotationCallable("filter"); |
|
|
|
|
107
|
|
|
|
108
|
|
|
// @Template |
109
|
|
|
$annotationContainer->template = $factory->createAnnotationCallable("template"); |
|
|
|
|
110
|
|
|
|
111
|
|
|
// @ExceptionHandler |
112
|
|
|
$annotationContainer->exceptionHandler = $factory->createAnnotationCallable("exceptionHandler"); |
|
|
|
|
113
|
|
|
|
114
|
|
|
// @Alias |
115
|
|
|
$annotationContainer->alias = $factory->createAnnotationCallable("alias"); |
|
|
|
|
116
|
|
|
|
117
|
|
|
// custom annotation |
118
|
|
|
$annotationContainer->customAnnotations = $factory->createCustomAnnotationCallable(); |
|
|
|
|
119
|
|
|
|
120
|
|
|
return $annotationContainer; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Serviceのアノテーション情報をロードする |
125
|
|
|
* @param CoreService インスタンス |
126
|
|
|
* @param string アノテーションクラスパス |
127
|
|
|
* @return Container コンテナ |
128
|
|
|
*/ |
|
|
|
|
129
|
|
|
private function readService(CoreService $instance, $classpath) |
130
|
|
|
{ |
131
|
|
|
$container = $this->container; |
132
|
|
|
$reader = new AnnotationReader($instance, $container); |
|
|
|
|
133
|
|
|
$reader->read($classpath); |
|
|
|
|
134
|
|
|
$injectedAnnotation = $reader->getInjectedAnnotationInfo(); |
135
|
|
|
|
136
|
|
|
$factory = new AnnotationDelegatorFactory($injectedAnnotation, $container); |
137
|
|
|
$annotationContainer = new AnnotationContainer(); |
138
|
|
|
|
139
|
|
|
// exceptions |
140
|
|
|
$annotationContainer->exception = $reader->getException(); |
|
|
|
|
141
|
|
|
|
142
|
|
|
// @Filter |
143
|
|
|
$annotationContainer->filter = $factory->createAnnotationCallable("filter"); |
|
|
|
|
144
|
|
|
|
145
|
|
|
// @ExceptionHandler |
146
|
|
|
$annotationContainer->exceptionHandler = $factory->createAnnotationCallable("exceptionHandler"); |
|
|
|
|
147
|
|
|
|
148
|
|
|
// @Alias |
149
|
|
|
$annotationContainer->alias = $factory->createAnnotationCallable("alias"); |
|
|
|
|
150
|
|
|
|
151
|
|
|
// custom annotation |
152
|
|
|
$annotationContainer->customAnnotations = $factory->createCustomAnnotationCallable(); |
|
|
|
|
153
|
|
|
|
154
|
|
|
return $annotationContainer; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Modelのアノテーション情報をロードする |
159
|
|
|
* @param CoreModel インスタンス |
160
|
|
|
* @param string アノテーションクラスパス |
161
|
|
|
* @return Container コンテナ |
162
|
|
|
*/ |
|
|
|
|
163
|
|
|
private function readModel(CoreModel $instance, $classpath) |
164
|
|
|
{ |
165
|
|
|
$container = $this->container; |
166
|
|
|
$reader = new AnnotationReader($instance, $container); |
|
|
|
|
167
|
|
|
$reader->read($classpath); |
|
|
|
|
168
|
|
|
$injectedAnnotation = $reader->getInjectedAnnotationInfo(); |
169
|
|
|
|
170
|
|
|
$factory = new AnnotationDelegatorFactory($injectedAnnotation, $container); |
171
|
|
|
$annotationContainer = new AnnotationContainer(); |
172
|
|
|
|
173
|
|
|
// exceptions |
174
|
|
|
$annotationContainer->exception = $reader->getException(); |
|
|
|
|
175
|
|
|
|
176
|
|
|
// @Filter |
177
|
|
|
$annotationContainer->filter = $factory->createAnnotationCallable("filter"); |
|
|
|
|
178
|
|
|
|
179
|
|
|
// @ExceptionHandler |
180
|
|
|
$annotationContainer->exceptionHandler = $factory->createAnnotationCallable("exceptionHandler"); |
|
|
|
|
181
|
|
|
|
182
|
|
|
// @Database |
183
|
|
|
$annotationContainer->database = $factory->createAnnotationCallable("database"); |
|
|
|
|
184
|
|
|
|
185
|
|
|
// @Query |
186
|
|
|
$annotationContainer->query = $factory->createAnnotationCallable("query"); |
|
|
|
|
187
|
|
|
|
188
|
|
|
// @Alias |
189
|
|
|
$annotationContainer->alias = $factory->createAnnotationCallable("alias"); |
|
|
|
|
190
|
|
|
|
191
|
|
|
// custom annotation |
192
|
|
|
$annotationContainer->customAnnotations = $factory->createCustomAnnotationCallable(); |
|
|
|
|
193
|
|
|
|
194
|
|
|
return $annotationContainer; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* Viewのアノテーション情報をロードする |
199
|
|
|
* @param CoreView インスタンス |
200
|
|
|
* @param string アノテーションクラスパス |
201
|
|
|
* @return Container コンテナ |
202
|
|
|
*/ |
|
|
|
|
203
|
|
|
private function readView(CoreView $instance, $classpath) |
204
|
|
|
{ |
205
|
|
|
$container = $this->container; |
206
|
|
|
$reader = new AnnotationReader($instance, $container); |
|
|
|
|
207
|
|
|
$reader->read($classpath); |
|
|
|
|
208
|
|
|
$injectedAnnotation = $reader->getInjectedAnnotationInfo(); |
209
|
|
|
|
210
|
|
|
$factory = new AnnotationDelegatorFactory($injectedAnnotation, $container); |
211
|
|
|
$annotationContainer = new AnnotationContainer(); |
212
|
|
|
|
213
|
|
|
// exceptions |
214
|
|
|
$annotationContainer->exception = $reader->getException(); |
|
|
|
|
215
|
|
|
|
216
|
|
|
// @Filter |
217
|
|
|
$annotationContainer->filter = $factory->createAnnotationCallable("filter"); |
|
|
|
|
218
|
|
|
|
219
|
|
|
return $annotationContainer; |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* Helperのアノテーション情報をロードする |
224
|
|
|
* @param CoreHelper インスタンス |
225
|
|
|
* @param string アノテーションクラスパス |
226
|
|
|
* @return Container コンテナ |
227
|
|
|
*/ |
|
|
|
|
228
|
|
|
private function readHelper(CoreHelper $instance, $classpath) |
229
|
|
|
{ |
230
|
|
|
$container = $this->container; |
231
|
|
|
$reader = new AnnotationReader($instance, $container); |
|
|
|
|
232
|
|
|
$reader->read($classpath); |
|
|
|
|
233
|
|
|
$injectedAnnotation = $reader->getInjectedAnnotationInfo(); |
234
|
|
|
|
235
|
|
|
$factory = new AnnotationDelegatorFactory($injectedAnnotation, $container); |
236
|
|
|
$annotationContainer = new AnnotationContainer(); |
237
|
|
|
|
238
|
|
|
// exceptions |
239
|
|
|
$annotationContainer->exception = $reader->getException(); |
|
|
|
|
240
|
|
|
|
241
|
|
|
// @Filter |
242
|
|
|
$annotationContainer->filter = $factory->createAnnotationCallable("filter"); |
|
|
|
|
243
|
|
|
|
244
|
|
|
// @ExceptionHandler |
245
|
|
|
$annotationContainer->exceptionHandler = $factory->createAnnotationCallable("exceptionHandler"); |
|
|
|
|
246
|
|
|
|
247
|
|
|
// @Alias |
248
|
|
|
$annotationContainer->alias = $factory->createAnnotationCallable("alias"); |
|
|
|
|
249
|
|
|
|
250
|
|
|
// custom annotation |
251
|
|
|
$annotationContainer->customAnnotations = $factory->createCustomAnnotationCallable(); |
|
|
|
|
252
|
|
|
|
253
|
|
|
return $annotationContainer; |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
/** |
257
|
|
|
* 他のモジュールのアノテーション情報をロードする |
258
|
|
|
* @param object インスタンス |
259
|
|
|
* @param string アノテーションクラスパス |
260
|
|
|
* @return Container コンテナ |
261
|
|
|
*/ |
|
|
|
|
262
|
|
|
private function readModule(IAnnotatable $instance, $classpath) |
263
|
|
|
{ |
264
|
|
|
$container = $this->container; |
265
|
|
|
$reader = new AnnotationReader($instance, $container); |
|
|
|
|
266
|
|
|
$reader->read($classpath); |
|
|
|
|
267
|
|
|
$injectedAnnotation = $reader->getInjectedAnnotationInfo(); |
268
|
|
|
|
269
|
|
|
$factory = new AnnotationDelegatorFactory($injectedAnnotation, $container); |
270
|
|
|
$annotationContainer = new AnnotationContainer(); |
271
|
|
|
|
272
|
|
|
// @Filter |
273
|
|
|
$annotationContainer->filter = $factory->createAnnotationCallable("filter"); |
|
|
|
|
274
|
|
|
|
275
|
|
|
// @Alias |
276
|
|
|
$annotationContainer->alias = $factory->createAnnotationCallable("alias"); |
|
|
|
|
277
|
|
|
|
278
|
|
|
// custom annotation |
279
|
|
|
$annotationContainer->customAnnotations = $factory->createCustomAnnotationCallable(); |
|
|
|
|
280
|
|
|
|
281
|
|
|
return $annotationContainer; |
282
|
|
|
} |
283
|
|
|
} |
284
|
|
|
|
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