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\Attributes\Alias; |
12
|
|
|
use WebStream\Annotation\Attributes\ExceptionHandler; |
13
|
|
|
use WebStream\Annotation\Attributes\Filter; |
14
|
|
|
use WebStream\Annotation\Attributes\Header; |
15
|
|
|
use WebStream\Annotation\Attributes\Template; |
16
|
|
|
use WebStream\Annotation\Base\IAnnotatable; |
17
|
|
|
use WebStream\Annotation\Reader\AnnotationReader; |
18
|
|
|
use WebStream\Annotation\Reader\Extend\FilterExtendReader; |
19
|
|
|
use WebStream\Annotation\Container\AnnotationContainer; |
20
|
|
|
use WebStream\Template\Basic; |
21
|
|
|
use WebStream\Template\Twig; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* AnnotationDelegator |
25
|
|
|
* @author Ryuichi TANAKA. |
26
|
|
|
* @since 2015/02/11 |
27
|
|
|
* @version 0.4 |
28
|
|
|
*/ |
29
|
|
|
class AnnotationDelegator |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* @var Container コンテナ |
33
|
|
|
*/ |
34
|
|
|
private $container; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var Logger ロガー |
|
|
|
|
38
|
|
|
*/ |
39
|
|
|
private $logger; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Constructor |
43
|
|
|
* @param CoreInterface インスタンス |
44
|
|
|
* @param Container DIContainer |
45
|
|
|
*/ |
|
|
|
|
46
|
|
|
public function __construct(Container $container) |
47
|
|
|
{ |
48
|
|
|
$this->container = $container; |
49
|
|
|
$this->logger = $container->logger; |
|
|
|
|
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Destructor |
54
|
|
|
*/ |
55
|
|
|
public function __destruct() |
56
|
|
|
{ |
57
|
|
|
$this->logger->debug("AnnotationDelegator container is clear."); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* アノテーション情報をロードする |
62
|
|
|
* @param object インスタンス |
63
|
|
|
* @param string メソッド |
64
|
|
|
* @param string アノテーションクラスパス |
65
|
|
|
* @return Container コンテナ |
66
|
|
|
*/ |
|
|
|
|
67
|
|
|
public function read($instance, $method = null, $classpath = null) |
68
|
|
|
{ |
69
|
|
|
if (!$instance instanceof IAnnotatable) { |
70
|
|
|
$this->logger->warn("Annotation is not available this class: " . get_class($instance)); |
71
|
|
|
return; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
$this->container->executeMethod = $method ?: ""; |
|
|
|
|
75
|
|
|
|
76
|
|
|
if ($instance instanceof CoreController) { |
77
|
|
|
return $this->readController($instance, $classpath); |
78
|
|
|
} elseif ($instance instanceof CoreService) { |
79
|
|
|
return $this->readService($instance, $classpath); |
80
|
|
|
} elseif ($instance instanceof CoreModel) { |
81
|
|
|
return $this->readModel($instance, $classpath); |
82
|
|
|
} elseif ($instance instanceof CoreView) { |
83
|
|
|
return $this->readView($instance, $classpath); |
84
|
|
|
} elseif ($instance instanceof CoreHelper) { |
85
|
|
|
return $this->readHelper($instance, $classpath); |
86
|
|
|
} else { |
87
|
|
|
return $this->readModule($instance, $classpath); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Controllerのアノテーション情報をロードする |
93
|
|
|
* @param CoreController インスタンス |
94
|
|
|
* @param string アノテーションクラスパス |
95
|
|
|
* @return Container コンテナ |
96
|
|
|
*/ |
|
|
|
|
97
|
|
|
private function readController(CoreController $instance, $classpath) |
|
|
|
|
98
|
|
|
{ |
99
|
|
|
$reader = new AnnotationReader($instance); |
100
|
|
|
$reader->setActionMethod($this->container->executeMethod); |
|
|
|
|
101
|
|
|
|
102
|
|
|
// @Header |
103
|
|
|
$container = new Container(); |
104
|
|
|
$container->requestMethod = $this->container->request->requestMethod; |
|
|
|
|
105
|
|
|
$container->contentType = 'html'; |
|
|
|
|
106
|
|
|
$container->logger = $this->container->logger; |
|
|
|
|
107
|
|
|
$reader->readable(Header::class, $container); |
108
|
|
|
|
109
|
|
|
// @Filter |
110
|
|
|
$container = new Container(); |
111
|
|
|
$container->action = $this->container->executeMethod; |
|
|
|
|
112
|
|
|
$container->logger = $this->container->logger; |
113
|
|
|
$reader->readable(Filter::class, $container); |
114
|
|
|
$reader->useExtendReader(Filter::class, FilterExtendReader::class); |
115
|
|
|
|
116
|
|
|
// @Template |
117
|
|
|
$container = new Container(); |
118
|
|
|
$container->action = $this->container->executeMethod; |
119
|
|
|
$container->engine = [ |
|
|
|
|
120
|
|
|
'basic' => Basic::class, |
121
|
|
|
'twig' => Twig::class |
122
|
|
|
]; |
123
|
|
|
$container->logger = $this->container->logger; |
124
|
|
|
$reader->readable(Template::class, $container); |
125
|
|
|
|
126
|
|
|
// @ExceptionHandler |
127
|
|
|
$container = new Container(); |
128
|
|
|
$container->logger = $this->container->logger; |
129
|
|
|
$reader->readable(ExceptionHandler::class, $container); |
130
|
|
|
|
131
|
|
|
// @Alias |
132
|
|
|
$container = new Container(); |
133
|
|
|
$container->action = $this->container->executeMethod; |
134
|
|
|
$container->logger = $this->container->logger; |
135
|
|
|
$reader->readable(Alias::class, $container); |
136
|
|
|
|
137
|
|
|
// TODO custom annotation |
138
|
|
|
|
139
|
|
|
$reader->readMethod(); |
140
|
|
|
|
141
|
|
|
$annotationContainer = new AnnotationContainer(); |
142
|
|
|
$annotationContainer->annotationInfoList = $reader->getAnnotationInfoList(); |
|
|
|
|
143
|
|
|
$annotationContainer->exception = $reader->getException(); |
|
|
|
|
144
|
|
|
|
145
|
|
|
|
146
|
|
|
// var_dump($reader->getAnnotationInfoList()); |
147
|
|
|
// exit; |
148
|
|
|
// |
149
|
|
|
// // $reader->read($classpath); |
150
|
|
|
// // $injectedAnnotation = $reader->getInjectedAnnotationInfo(); |
151
|
|
|
// |
152
|
|
|
// $factory = new AnnotationDelegatorFactory($injectedAnnotation, $container); |
153
|
|
|
// $annotationContainer = new AnnotationContainer(); |
154
|
|
|
// |
155
|
|
|
// // exceptions |
156
|
|
|
// $annotationContainer->exception = $reader->getException(); |
157
|
|
|
// |
158
|
|
|
// // @Header |
159
|
|
|
// $annotationContainer->header = $factory->createAnnotationCallable("header"); |
160
|
|
|
// |
161
|
|
|
// // @Filter |
162
|
|
|
// $annotationContainer->filter = $factory->createAnnotationCallable("filter"); |
163
|
|
|
// |
164
|
|
|
// // @Template |
165
|
|
|
// $annotationContainer->template = $factory->createAnnotationCallable("template"); |
166
|
|
|
// |
167
|
|
|
// // @ExceptionHandler |
168
|
|
|
// $annotationContainer->exceptionHandler = $factory->createAnnotationCallable("exceptionHandler"); |
169
|
|
|
// |
170
|
|
|
// // @Alias |
171
|
|
|
// $annotationContainer->alias = $factory->createAnnotationCallable("alias"); |
172
|
|
|
// |
173
|
|
|
// // custom annotation |
174
|
|
|
// $annotationContainer->customAnnotations = $factory->createCustomAnnotationCallable(); |
175
|
|
|
|
176
|
|
|
return $annotationContainer; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* Serviceのアノテーション情報をロードする |
181
|
|
|
* @param CoreService インスタンス |
182
|
|
|
* @param string アノテーションクラスパス |
183
|
|
|
* @return Container コンテナ |
184
|
|
|
*/ |
|
|
|
|
185
|
|
|
private function readService(CoreService $instance, $classpath) |
186
|
|
|
{ |
187
|
|
|
$container = $this->container; |
188
|
|
|
$reader = new AnnotationReader($instance, $container); |
|
|
|
|
189
|
|
|
$reader->read($classpath); |
|
|
|
|
190
|
|
|
$injectedAnnotation = $reader->getInjectedAnnotationInfo(); |
|
|
|
|
191
|
|
|
|
192
|
|
|
$factory = new AnnotationDelegatorFactory($injectedAnnotation, $container); |
193
|
|
|
$annotationContainer = new AnnotationContainer(); |
194
|
|
|
|
195
|
|
|
// exceptions |
196
|
|
|
$annotationContainer->exception = $reader->getException(); |
|
|
|
|
197
|
|
|
|
198
|
|
|
// @Filter |
199
|
|
|
$annotationContainer->filter = $factory->createAnnotationCallable("filter"); |
|
|
|
|
200
|
|
|
|
201
|
|
|
// @ExceptionHandler |
202
|
|
|
$annotationContainer->exceptionHandler = $factory->createAnnotationCallable("exceptionHandler"); |
|
|
|
|
203
|
|
|
|
204
|
|
|
// @Alias |
205
|
|
|
$annotationContainer->alias = $factory->createAnnotationCallable("alias"); |
|
|
|
|
206
|
|
|
|
207
|
|
|
// custom annotation |
208
|
|
|
$annotationContainer->customAnnotations = $factory->createCustomAnnotationCallable(); |
|
|
|
|
209
|
|
|
|
210
|
|
|
return $annotationContainer; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* Modelのアノテーション情報をロードする |
215
|
|
|
* @param CoreModel インスタンス |
216
|
|
|
* @param string アノテーションクラスパス |
217
|
|
|
* @return Container コンテナ |
218
|
|
|
*/ |
|
|
|
|
219
|
|
|
private function readModel(CoreModel $instance, $classpath) |
220
|
|
|
{ |
221
|
|
|
$container = $this->container; |
222
|
|
|
$reader = new AnnotationReader($instance, $container); |
|
|
|
|
223
|
|
|
$reader->read($classpath); |
|
|
|
|
224
|
|
|
$injectedAnnotation = $reader->getInjectedAnnotationInfo(); |
225
|
|
|
|
226
|
|
|
$factory = new AnnotationDelegatorFactory($injectedAnnotation, $container); |
227
|
|
|
$annotationContainer = new AnnotationContainer(); |
228
|
|
|
|
229
|
|
|
// exceptions |
230
|
|
|
$annotationContainer->exception = $reader->getException(); |
|
|
|
|
231
|
|
|
|
232
|
|
|
// @Filter |
233
|
|
|
$annotationContainer->filter = $factory->createAnnotationCallable("filter"); |
|
|
|
|
234
|
|
|
|
235
|
|
|
// @ExceptionHandler |
236
|
|
|
$annotationContainer->exceptionHandler = $factory->createAnnotationCallable("exceptionHandler"); |
|
|
|
|
237
|
|
|
|
238
|
|
|
// @Database |
239
|
|
|
$annotationContainer->database = $factory->createAnnotationCallable("database"); |
|
|
|
|
240
|
|
|
|
241
|
|
|
// @Query |
242
|
|
|
$annotationContainer->query = $factory->createAnnotationCallable("query"); |
|
|
|
|
243
|
|
|
|
244
|
|
|
// @Alias |
245
|
|
|
$annotationContainer->alias = $factory->createAnnotationCallable("alias"); |
|
|
|
|
246
|
|
|
|
247
|
|
|
// custom annotation |
248
|
|
|
$annotationContainer->customAnnotations = $factory->createCustomAnnotationCallable(); |
|
|
|
|
249
|
|
|
|
250
|
|
|
return $annotationContainer; |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* Viewのアノテーション情報をロードする |
255
|
|
|
* @param CoreView インスタンス |
256
|
|
|
* @param string アノテーションクラスパス |
257
|
|
|
* @return Container コンテナ |
258
|
|
|
*/ |
|
|
|
|
259
|
|
|
private function readView(CoreView $instance, $classpath) |
|
|
|
|
260
|
|
|
{ |
261
|
|
|
$reader = new AnnotationReader($instance); |
262
|
|
|
// $reader->setActionMethod($this->container->executeMethod); |
263
|
|
|
|
264
|
|
|
// @Filter |
265
|
|
|
$container = new Container(); |
266
|
|
|
// $container->action = $this->container->executeMethod; |
267
|
|
|
$container->logger = $this->container->logger; |
|
|
|
|
268
|
|
|
$reader->readable(Filter::class, $container); |
269
|
|
|
$reader->useExtendReader(Filter::class, FilterExtendReader::class); |
270
|
|
|
$reader->readMethod(); |
271
|
|
|
|
272
|
|
|
$annotationContainer = new AnnotationContainer(); |
273
|
|
|
$annotationContainer->annotationInfoList = $reader->getAnnotationInfoList(); |
|
|
|
|
274
|
|
|
$annotationContainer->exception = $reader->getException(); |
|
|
|
|
275
|
|
|
|
276
|
|
|
// |
277
|
|
|
// $container = $this->container; |
278
|
|
|
// $reader = new AnnotationReader($instance, $container); |
279
|
|
|
// $reader->read($classpath); |
280
|
|
|
// $injectedAnnotation = $reader->getInjectedAnnotationInfo(); |
281
|
|
|
// |
282
|
|
|
// $factory = new AnnotationDelegatorFactory($injectedAnnotation, $container); |
283
|
|
|
$annotationContainer = new AnnotationContainer(); |
284
|
|
|
|
285
|
|
|
// exceptions |
286
|
|
|
$annotationContainer->exception = $reader->getException(); |
287
|
|
|
|
288
|
|
|
// @Filter |
289
|
|
|
$annotationContainer->filter = $factory->createAnnotationCallable("filter"); |
|
|
|
|
290
|
|
|
|
291
|
|
|
return $annotationContainer; |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
/** |
295
|
|
|
* Helperのアノテーション情報をロードする |
296
|
|
|
* @param CoreHelper インスタンス |
297
|
|
|
* @param string アノテーションクラスパス |
298
|
|
|
* @return Container コンテナ |
299
|
|
|
*/ |
|
|
|
|
300
|
|
|
private function readHelper(CoreHelper $instance, $classpath) |
301
|
|
|
{ |
302
|
|
|
$container = $this->container; |
303
|
|
|
$reader = new AnnotationReader($instance, $container); |
|
|
|
|
304
|
|
|
$reader->read($classpath); |
|
|
|
|
305
|
|
|
$injectedAnnotation = $reader->getInjectedAnnotationInfo(); |
306
|
|
|
|
307
|
|
|
$factory = new AnnotationDelegatorFactory($injectedAnnotation, $container); |
308
|
|
|
$annotationContainer = new AnnotationContainer(); |
309
|
|
|
|
310
|
|
|
// exceptions |
311
|
|
|
$annotationContainer->exception = $reader->getException(); |
|
|
|
|
312
|
|
|
|
313
|
|
|
// @Filter |
314
|
|
|
$annotationContainer->filter = $factory->createAnnotationCallable("filter"); |
|
|
|
|
315
|
|
|
|
316
|
|
|
// @ExceptionHandler |
317
|
|
|
$annotationContainer->exceptionHandler = $factory->createAnnotationCallable("exceptionHandler"); |
|
|
|
|
318
|
|
|
|
319
|
|
|
// @Alias |
320
|
|
|
$annotationContainer->alias = $factory->createAnnotationCallable("alias"); |
|
|
|
|
321
|
|
|
|
322
|
|
|
// custom annotation |
323
|
|
|
$annotationContainer->customAnnotations = $factory->createCustomAnnotationCallable(); |
|
|
|
|
324
|
|
|
|
325
|
|
|
return $annotationContainer; |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
/** |
329
|
|
|
* 他のモジュールのアノテーション情報をロードする |
330
|
|
|
* @param object インスタンス |
331
|
|
|
* @param string アノテーションクラスパス |
332
|
|
|
* @return Container コンテナ |
333
|
|
|
*/ |
|
|
|
|
334
|
|
|
private function readModule(IAnnotatable $instance, $classpath) |
335
|
|
|
{ |
336
|
|
|
$container = $this->container; |
337
|
|
|
$reader = new AnnotationReader($instance, $container); |
|
|
|
|
338
|
|
|
$reader->read($classpath); |
|
|
|
|
339
|
|
|
$injectedAnnotation = $reader->getInjectedAnnotationInfo(); |
340
|
|
|
|
341
|
|
|
$factory = new AnnotationDelegatorFactory($injectedAnnotation, $container); |
342
|
|
|
$annotationContainer = new AnnotationContainer(); |
343
|
|
|
|
344
|
|
|
// @Filter |
345
|
|
|
$annotationContainer->filter = $factory->createAnnotationCallable("filter"); |
|
|
|
|
346
|
|
|
|
347
|
|
|
// @Alias |
348
|
|
|
$annotationContainer->alias = $factory->createAnnotationCallable("alias"); |
|
|
|
|
349
|
|
|
|
350
|
|
|
// custom annotation |
351
|
|
|
$annotationContainer->customAnnotations = $factory->createCustomAnnotationCallable(); |
|
|
|
|
352
|
|
|
|
353
|
|
|
return $annotationContainer; |
354
|
|
|
} |
355
|
|
|
} |
356
|
|
|
|
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