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
|
|
|
// @Query |
249
|
|
|
$container = new Container(); |
250
|
|
|
$container->rootPath = $this->container->applicationInfo->applicationRoot; |
251
|
|
|
$reader->readable(Query::class, $container); |
|
|
|
|
252
|
|
|
$reader->useExtendReader(Query::class, QueryExtendReader::class); |
|
|
|
|
253
|
|
|
|
254
|
|
|
// @Alias |
255
|
|
|
$container = new Container(); |
256
|
|
|
$container->action = $this->container->executeMethod; |
257
|
|
|
$container->logger = $this->container->logger; |
258
|
|
|
$reader->readable(Alias::class, $container); |
259
|
|
|
|
260
|
|
|
// TODO custom annotation |
261
|
|
|
|
262
|
|
|
$reader->readClass(); |
263
|
|
|
$reader->readMethod(); |
264
|
|
|
|
265
|
|
|
$annotationContainer = new AnnotationContainer(); |
266
|
|
|
$annotationContainer->annotationInfoList = $reader->getAnnotationInfoList(); |
|
|
|
|
267
|
|
|
$annotationContainer->exception = $reader->getException(); |
|
|
|
|
268
|
|
|
|
269
|
|
|
return $annotationContainer; |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
/** |
273
|
|
|
* Viewのアノテーション情報をロードする |
274
|
|
|
* @param CoreView インスタンス |
275
|
|
|
* @param string アノテーションクラスパス |
276
|
|
|
* @return Container コンテナ |
277
|
|
|
*/ |
|
|
|
|
278
|
|
|
private function readView(CoreView $instance, $classpath) |
|
|
|
|
279
|
|
|
{ |
280
|
|
|
$reader = new AnnotationReader($instance); |
281
|
|
|
// $reader->setActionMethod($this->container->executeMethod); |
282
|
|
|
|
283
|
|
|
// @Filter |
284
|
|
|
$container = new Container(); |
285
|
|
|
$container->action = $this->container->executeMethod; |
|
|
|
|
286
|
|
|
$container->logger = $this->container->logger; |
|
|
|
|
287
|
|
|
$reader->readable(Filter::class, $container); |
288
|
|
|
$reader->useExtendReader(Filter::class, FilterExtendReader::class); |
289
|
|
|
$reader->readMethod(); |
290
|
|
|
|
291
|
|
|
$annotationContainer = new AnnotationContainer(); |
292
|
|
|
$annotationContainer->annotationInfoList = $reader->getAnnotationInfoList(); |
|
|
|
|
293
|
|
|
$annotationContainer->exception = $reader->getException(); |
|
|
|
|
294
|
|
|
|
295
|
|
|
// |
296
|
|
|
// $container = $this->container; |
297
|
|
|
// $reader = new AnnotationReader($instance, $container); |
298
|
|
|
// $reader->read($classpath); |
299
|
|
|
// $injectedAnnotation = $reader->getInjectedAnnotationInfo(); |
300
|
|
|
// |
301
|
|
|
// $factory = new AnnotationDelegatorFactory($injectedAnnotation, $container); |
302
|
|
|
// $annotationContainer = new AnnotationContainer(); |
303
|
|
|
// |
304
|
|
|
// // exceptions |
305
|
|
|
// $annotationContainer->exception = $reader->getException(); |
306
|
|
|
// |
307
|
|
|
// // @Filter |
308
|
|
|
// $annotationContainer->filter = $factory->createAnnotationCallable("filter"); |
309
|
|
|
|
310
|
|
|
return $annotationContainer; |
311
|
|
|
} |
312
|
|
|
|
313
|
|
|
/** |
314
|
|
|
* Helperのアノテーション情報をロードする |
315
|
|
|
* @param CoreHelper インスタンス |
316
|
|
|
* @param string アノテーションクラスパス |
317
|
|
|
* @return Container コンテナ |
318
|
|
|
*/ |
|
|
|
|
319
|
|
|
private function readHelper(CoreHelper $instance, $classpath) |
320
|
|
|
{ |
321
|
|
|
$container = $this->container; |
322
|
|
|
$reader = new AnnotationReader($instance, $container); |
|
|
|
|
323
|
|
|
$reader->read($classpath); |
|
|
|
|
324
|
|
|
$injectedAnnotation = $reader->getInjectedAnnotationInfo(); |
|
|
|
|
325
|
|
|
|
326
|
|
|
$factory = new AnnotationDelegatorFactory($injectedAnnotation, $container); |
327
|
|
|
$annotationContainer = new AnnotationContainer(); |
328
|
|
|
|
329
|
|
|
// exceptions |
330
|
|
|
$annotationContainer->exception = $reader->getException(); |
|
|
|
|
331
|
|
|
|
332
|
|
|
// @Filter |
333
|
|
|
$annotationContainer->filter = $factory->createAnnotationCallable("filter"); |
|
|
|
|
334
|
|
|
|
335
|
|
|
// @ExceptionHandler |
336
|
|
|
$annotationContainer->exceptionHandler = $factory->createAnnotationCallable("exceptionHandler"); |
|
|
|
|
337
|
|
|
|
338
|
|
|
// @Alias |
339
|
|
|
$annotationContainer->alias = $factory->createAnnotationCallable("alias"); |
|
|
|
|
340
|
|
|
|
341
|
|
|
// custom annotation |
342
|
|
|
$annotationContainer->customAnnotations = $factory->createCustomAnnotationCallable(); |
|
|
|
|
343
|
|
|
|
344
|
|
|
return $annotationContainer; |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
/** |
348
|
|
|
* 他のモジュールのアノテーション情報をロードする |
349
|
|
|
* @param object インスタンス |
350
|
|
|
* @param string アノテーションクラスパス |
351
|
|
|
* @return Container コンテナ |
352
|
|
|
*/ |
|
|
|
|
353
|
|
|
private function readModule(IAnnotatable $instance, $classpath) |
354
|
|
|
{ |
355
|
|
|
$container = $this->container; |
356
|
|
|
$reader = new AnnotationReader($instance, $container); |
|
|
|
|
357
|
|
|
$reader->read($classpath); |
|
|
|
|
358
|
|
|
$injectedAnnotation = $reader->getInjectedAnnotationInfo(); |
359
|
|
|
|
360
|
|
|
$factory = new AnnotationDelegatorFactory($injectedAnnotation, $container); |
361
|
|
|
$annotationContainer = new AnnotationContainer(); |
362
|
|
|
|
363
|
|
|
// @Filter |
364
|
|
|
$annotationContainer->filter = $factory->createAnnotationCallable("filter"); |
|
|
|
|
365
|
|
|
|
366
|
|
|
// @Alias |
367
|
|
|
$annotationContainer->alias = $factory->createAnnotationCallable("alias"); |
|
|
|
|
368
|
|
|
|
369
|
|
|
// custom annotation |
370
|
|
|
$annotationContainer->customAnnotations = $factory->createCustomAnnotationCallable(); |
|
|
|
|
371
|
|
|
|
372
|
|
|
return $annotationContainer; |
373
|
|
|
} |
374
|
|
|
} |
375
|
|
|
|
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