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