|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace WebStream\Annotation\Reader\Extend; |
|
4
|
|
|
|
|
5
|
|
|
use WebStream\Container\Container; |
|
|
|
|
|
|
6
|
|
|
use WebStream\Annotation\Container\AnnotationListContainer; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* FilterExtendReader |
|
10
|
|
|
* @author Ryuichi Tanaka |
|
11
|
|
|
* @since 2017/01/08 |
|
12
|
|
|
* @version 0.7 |
|
13
|
|
|
*/ |
|
14
|
|
|
class FilterExtendReader extends ExtendReader |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var array<Container> アノテーション情報リスト |
|
18
|
|
|
*/ |
|
19
|
|
|
private $annotationInfo; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* {@inheritdoc} |
|
23
|
|
|
*/ |
|
24
|
20 |
|
public function getAnnotationInfo() |
|
25
|
|
|
{ |
|
26
|
20 |
|
return $this->annotationInfo; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* {@inheritdoc} |
|
31
|
|
|
*/ |
|
32
|
20 |
|
public function read(array $annotationInfoList) |
|
33
|
|
|
{ |
|
34
|
20 |
|
$filterListContainer = new Container(); |
|
35
|
20 |
|
$filterListContainer->initialize = new AnnotationListContainer(); |
|
36
|
20 |
|
$filterListContainer->before = new AnnotationListContainer(); |
|
37
|
20 |
|
$filterListContainer->after = new AnnotationListContainer(); |
|
38
|
|
|
|
|
39
|
20 |
|
$exceptMethods = []; |
|
40
|
|
|
// アクションメソッドの@Filter(type="skip")をチェックする |
|
41
|
|
|
// 1メソッドに対して複数の@Filterが指定されてもエラーにはしない |
|
42
|
20 |
|
foreach ($annotationInfoList as $annotationInfo) { |
|
43
|
20 |
|
if ($annotationInfo['classpath'] . "#" . $annotationInfo['action'] === $annotationInfo['refMethod']->class . "#" . $annotationInfo['refMethod']->name) { |
|
44
|
2 |
|
if ($annotationInfo['annotation']->type === 'skip') { |
|
45
|
2 |
|
$exceptMethods = $annotationInfo['annotation']->except; |
|
46
|
2 |
|
if (!is_array($exceptMethods)) { |
|
47
|
1 |
|
$exceptMethods = [$exceptMethods]; |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
20 |
|
$isInitialized = false; |
|
54
|
20 |
|
foreach ($annotationInfoList as $annotationInfo) { |
|
55
|
20 |
|
$type = $annotationInfo['annotation']->type; |
|
56
|
20 |
|
$only = $annotationInfo['annotation']->only; |
|
57
|
20 |
|
$except = $annotationInfo['annotation']->except; |
|
58
|
20 |
|
$refMethod = $annotationInfo['refMethod']; |
|
59
|
20 |
|
$action = $annotationInfo['action']; |
|
60
|
|
|
// initializeはCoreControllerでのみ使用可能なため複数回指定されたら例外 |
|
61
|
20 |
|
if ($type === "initialize") { |
|
62
|
|
|
if ($isInitialized) { |
|
63
|
|
|
throw new AnnotationException("Can not multiple define @Filter(type=\"initialize\") at method."); |
|
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
$isInitialized = true; |
|
66
|
20 |
|
} elseif (array_key_exists($type, array_flip(["before", "after"]))) { |
|
67
|
|
|
// skip filterが有効なら適用しない |
|
68
|
|
|
// クラスに関係なくメソッド名が一致した場合すべて適用しない |
|
69
|
20 |
|
if (array_key_exists($refMethod->name, array_flip($exceptMethods))) { |
|
70
|
2 |
|
continue; |
|
71
|
|
|
} |
|
72
|
|
|
// only |
|
73
|
19 |
|
if ($only !== null) { |
|
74
|
9 |
|
$onlyList = $only; |
|
75
|
9 |
|
if (!is_array($onlyList)) { |
|
76
|
5 |
|
$onlyList = [$onlyList]; |
|
77
|
|
|
} |
|
78
|
|
|
// アクションメソッド名がonlyListに含まれていれば実行対象とする |
|
79
|
9 |
|
if (!array_key_exists($action, array_flip($onlyList))) { |
|
80
|
8 |
|
continue; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
// exceptは親クラス以上すべてのメソッドに対して適用するのでメソッド名のみ取得 |
|
84
|
17 |
|
if ($except !== null) { |
|
85
|
9 |
|
$exceptList = $except; |
|
86
|
9 |
|
if (!is_array($exceptList)) { |
|
87
|
5 |
|
$exceptList = [$exceptList]; |
|
88
|
|
|
} |
|
89
|
|
|
// アクションメソッド名がexceptListに含まれていれば実行対象としない |
|
90
|
9 |
|
if (array_key_exists($action, array_flip($exceptList))) { |
|
91
|
7 |
|
continue; |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
} else { |
|
95
|
2 |
|
continue; |
|
96
|
|
|
} |
|
97
|
|
|
// 実行時に動的にインスタンスを渡すようにしないと、各メソッドでの実行結果が反映されないため |
|
98
|
|
|
// この時点でのクロージャへのインスタンス設定はせず、リストとして保持するに留める |
|
99
|
16 |
|
$filterListContainer->{$type}->push($refMethod); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
20 |
|
$this->annotationInfo = $filterListContainer; |
|
|
|
|
|
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|
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