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