@@ -44,17 +44,23 @@ discard block |
||
44 | 44 | public function process(string $controller, string $action, array $parameters, CoreInterface $core) |
45 | 45 | { |
46 | 46 | $annotation = $this->readAnnotation($controller, $action); |
47 | - if ($core instanceof InterceptorPipeline && $annotation->skipNext) { |
|
47 | + if ($core instanceof InterceptorPipeline && $annotation->skipNext) |
|
48 | + { |
|
48 | 49 | $this->removeNextInterceptorsFromOriginalPipeline($core); |
49 | 50 | } |
50 | 51 | |
51 | 52 | $pipeline = $this->getCachedPipeline($controller, $action, $annotation); |
52 | - if (!empty($pipeline)) { |
|
53 | - if ($core instanceof InterceptorPipeline) { |
|
53 | + if (!empty($pipeline)) |
|
54 | + { |
|
55 | + if ($core instanceof InterceptorPipeline) |
|
56 | + { |
|
54 | 57 | $this->injectInterceptorsIntoOriginalPipeline($core, $pipeline); |
55 | - } else { |
|
58 | + } |
|
59 | + else |
|
60 | + { |
|
56 | 61 | $core = new InterceptableCore($core); |
57 | - foreach ($pipeline as $interceptor) { |
|
62 | + foreach ($pipeline as $interceptor) |
|
63 | + { |
|
58 | 64 | $core->addInterceptor($interceptor); |
59 | 65 | } |
60 | 66 | } |
@@ -70,9 +76,12 @@ discard block |
||
70 | 76 | */ |
71 | 77 | private function readAnnotation(string $controller, string $action): Pipeline |
72 | 78 | { |
73 | - try { |
|
79 | + try |
|
80 | + { |
|
74 | 81 | $method = new \ReflectionMethod($controller, $action); |
75 | - } catch (\ReflectionException $e) { |
|
82 | + } |
|
83 | + catch (\ReflectionException $e) |
|
84 | + { |
|
76 | 85 | return new Pipeline(); |
77 | 86 | } |
78 | 87 | |
@@ -91,14 +100,17 @@ discard block |
||
91 | 100 | |
92 | 101 | $oldInterceptors = $pipelineReflection->getValue($pipeline); |
93 | 102 | $newInterceptors = []; |
94 | - foreach ($oldInterceptors as $interceptor) { |
|
103 | + foreach ($oldInterceptors as $interceptor) |
|
104 | + { |
|
95 | 105 | $newInterceptors[] = $interceptor; |
96 | - if ($interceptor instanceof self) { |
|
106 | + if ($interceptor instanceof self) |
|
107 | + { |
|
97 | 108 | break; |
98 | 109 | } |
99 | 110 | } |
100 | 111 | |
101 | - if (count($newInterceptors) !== count($oldInterceptors)) { |
|
112 | + if (count($newInterceptors) !== count($oldInterceptors)) |
|
113 | + { |
|
102 | 114 | $pipelineReflection->setValue($pipeline, $newInterceptors); |
103 | 115 | } |
104 | 116 | $pipelineReflection->setAccessible(false); |
@@ -111,16 +123,20 @@ discard block |
||
111 | 123 | |
112 | 124 | $oldInterceptors = $pipelineReflection->getValue($pipeline); |
113 | 125 | $newInterceptors = []; |
114 | - foreach ($oldInterceptors as $interceptor) { |
|
126 | + foreach ($oldInterceptors as $interceptor) |
|
127 | + { |
|
115 | 128 | $newInterceptors[] = $interceptor; |
116 | - if ($interceptor instanceof self) { |
|
117 | - foreach ($interceptors as $newInterceptor) { |
|
129 | + if ($interceptor instanceof self) |
|
130 | + { |
|
131 | + foreach ($interceptors as $newInterceptor) |
|
132 | + { |
|
118 | 133 | $newInterceptors[] = $newInterceptor; |
119 | 134 | } |
120 | 135 | } |
121 | 136 | } |
122 | 137 | |
123 | - if (count($newInterceptors) !== count($oldInterceptors)) { |
|
138 | + if (count($newInterceptors) !== count($oldInterceptors)) |
|
139 | + { |
|
124 | 140 | $pipelineReflection->setValue($pipeline, $newInterceptors); |
125 | 141 | } |
126 | 142 | $pipelineReflection->setAccessible(false); |
@@ -135,7 +151,8 @@ discard block |
||
135 | 151 | private function getCachedPipeline(string $controller, string $action, Pipeline $annotation): array |
136 | 152 | { |
137 | 153 | $key = "{$controller}:{$action}"; |
138 | - if (!array_key_exists($key, $this->cache)) { |
|
154 | + if (!array_key_exists($key, $this->cache)) |
|
155 | + { |
|
139 | 156 | $this->cache[$key] = $this->extractAnnotationPipeline($annotation); |
140 | 157 | } |
141 | 158 | |
@@ -149,10 +166,14 @@ discard block |
||
149 | 166 | private function extractAnnotationPipeline(Pipeline $annotation): array |
150 | 167 | { |
151 | 168 | $interceptors = []; |
152 | - foreach ($annotation->pipeline as $interceptor) { |
|
153 | - try { |
|
169 | + foreach ($annotation->pipeline as $interceptor) |
|
170 | + { |
|
171 | + try |
|
172 | + { |
|
154 | 173 | $interceptors[] = $this->container->get($interceptor); |
155 | - } catch (\Throwable $e) { |
|
174 | + } |
|
175 | + catch (\Throwable $e) |
|
176 | + { |
|
156 | 177 | } |
157 | 178 | } |
158 | 179 |
@@ -19,7 +19,8 @@ |
||
19 | 19 | public function process(string $controller, string $action, array $parameters, CoreInterface $core): array |
20 | 20 | { |
21 | 21 | $result = $core->callAction($controller, $action, $parameters); |
22 | - if (!is_array($result)) { |
|
22 | + if (!is_array($result)) |
|
23 | + { |
|
23 | 24 | $result = []; |
24 | 25 | } |
25 | 26 | $result[] = $this->string; |
@@ -173,7 +173,8 @@ |
||
173 | 173 | { |
174 | 174 | $core = new InterceptableCore($this->core); |
175 | 175 | |
176 | - foreach ($interceptors as $interceptor) { |
|
176 | + foreach ($interceptors as $interceptor) |
|
177 | + { |
|
177 | 178 | $core->addInterceptor(is_object($interceptor) ? $interceptor : $this->container->get($interceptor)); |
178 | 179 | } |
179 | 180 |