@@ -24,5 +24,5 @@ |
||
24 | 24 | public function __construct( |
25 | 25 | public readonly array $pipeline = [], |
26 | 26 | public readonly bool $skipNext = false, |
27 | - ) {} |
|
27 | + ){} |
|
28 | 28 | } |
@@ -24,5 +24,6 @@ |
||
24 | 24 | public function __construct( |
25 | 25 | public readonly array $pipeline = [], |
26 | 26 | public readonly bool $skipNext = false, |
27 | - ) {} |
|
27 | + ) { |
|
28 | +} |
|
28 | 29 | } |
@@ -25,5 +25,5 @@ |
||
25 | 25 | */ |
26 | 26 | public function __construct( |
27 | 27 | public readonly string $namespace, |
28 | - ) {} |
|
28 | + ){} |
|
29 | 29 | } |
@@ -25,5 +25,6 @@ |
||
25 | 25 | */ |
26 | 26 | public function __construct( |
27 | 27 | public readonly string $namespace, |
28 | - ) {} |
|
28 | + ) { |
|
29 | +} |
|
29 | 30 | } |
@@ -18,13 +18,13 @@ |
||
18 | 18 | public function __construct( |
19 | 19 | private readonly GuardInterface $guard, |
20 | 20 | private readonly PermissionsProviderInterface $permissions, |
21 | - ) {} |
|
21 | + ){} |
|
22 | 22 | |
23 | 23 | public function process(string $controller, string $action, array $parameters, CoreInterface $core): mixed |
24 | 24 | { |
25 | 25 | $permission = $this->permissions->getPermission($controller, $action); |
26 | 26 | |
27 | - if ($permission->ok && !$this->guard->allows($permission->permission, $parameters)) { |
|
27 | + if ($permission->ok && !$this->guard->allows($permission->permission, $parameters)){ |
|
28 | 28 | throw new ControllerException($permission->message, $permission->code); |
29 | 29 | } |
30 | 30 |
@@ -18,13 +18,15 @@ |
||
18 | 18 | public function __construct( |
19 | 19 | private readonly GuardInterface $guard, |
20 | 20 | private readonly PermissionsProviderInterface $permissions, |
21 | - ) {} |
|
21 | + ) { |
|
22 | +} |
|
22 | 23 | |
23 | 24 | public function process(string $controller, string $action, array $parameters, CoreInterface $core): mixed |
24 | 25 | { |
25 | 26 | $permission = $this->permissions->getPermission($controller, $action); |
26 | 27 | |
27 | - if ($permission->ok && !$this->guard->allows($permission->permission, $parameters)) { |
|
28 | + if ($permission->ok && !$this->guard->allows($permission->permission, $parameters)) |
|
29 | + { |
|
28 | 30 | throw new ControllerException($permission->message, $permission->code); |
29 | 31 | } |
30 | 32 |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | private ReaderInterface $reader, |
25 | 25 | private ContainerInterface $container, |
26 | 26 | private ?EventDispatcherInterface $dispatcher = null, |
27 | - ) {} |
|
27 | + ){} |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * @throws \Throwable |
@@ -32,17 +32,17 @@ discard block |
||
32 | 32 | public function process(string $controller, string $action, array $parameters, CoreInterface $core): mixed |
33 | 33 | { |
34 | 34 | $annotation = $this->readAnnotation($controller, $action); |
35 | - if ($core instanceof InterceptorPipeline && $annotation->skipNext) { |
|
35 | + if ($core instanceof InterceptorPipeline && $annotation->skipNext){ |
|
36 | 36 | $this->removeNextInterceptorsFromOriginalPipeline($core); |
37 | 37 | } |
38 | 38 | |
39 | 39 | $pipeline = $this->getCachedPipeline($controller, $action, $annotation); |
40 | - if (!empty($pipeline)) { |
|
41 | - if ($core instanceof InterceptorPipeline) { |
|
40 | + if (!empty($pipeline)){ |
|
41 | + if ($core instanceof InterceptorPipeline){ |
|
42 | 42 | $this->injectInterceptorsIntoOriginalPipeline($core, $pipeline); |
43 | - } else { |
|
43 | + }else{ |
|
44 | 44 | $core = new InterceptableCore($core, $this->dispatcher); |
45 | - foreach ($pipeline as $interceptor) { |
|
45 | + foreach ($pipeline as $interceptor){ |
|
46 | 46 | $core->addInterceptor($interceptor); |
47 | 47 | } |
48 | 48 | } |
@@ -53,9 +53,9 @@ discard block |
||
53 | 53 | |
54 | 54 | private function readAnnotation(string $controller, string $action): Pipeline |
55 | 55 | { |
56 | - try { |
|
56 | + try{ |
|
57 | 57 | $method = new \ReflectionMethod($controller, $action); |
58 | - } catch (\ReflectionException) { |
|
58 | + }catch (\ReflectionException){ |
|
59 | 59 | return new Pipeline(); |
60 | 60 | } |
61 | 61 | |
@@ -70,14 +70,14 @@ discard block |
||
70 | 70 | |
71 | 71 | $oldInterceptors = $pipelineReflection->getValue($pipeline); |
72 | 72 | $newInterceptors = []; |
73 | - foreach ($oldInterceptors as $interceptor) { |
|
73 | + foreach ($oldInterceptors as $interceptor){ |
|
74 | 74 | $newInterceptors[] = $interceptor; |
75 | - if ($interceptor instanceof self) { |
|
75 | + if ($interceptor instanceof self){ |
|
76 | 76 | break; |
77 | 77 | } |
78 | 78 | } |
79 | 79 | |
80 | - if (\count($newInterceptors) !== \count($oldInterceptors)) { |
|
80 | + if (\count($newInterceptors) !== \count($oldInterceptors)){ |
|
81 | 81 | $pipelineReflection->setValue($pipeline, $newInterceptors); |
82 | 82 | } |
83 | 83 | } |
@@ -88,16 +88,16 @@ discard block |
||
88 | 88 | |
89 | 89 | $oldInterceptors = $pipelineReflection->getValue($pipeline); |
90 | 90 | $newInterceptors = []; |
91 | - foreach ($oldInterceptors as $interceptor) { |
|
91 | + foreach ($oldInterceptors as $interceptor){ |
|
92 | 92 | $newInterceptors[] = $interceptor; |
93 | - if ($interceptor instanceof self) { |
|
94 | - foreach ($interceptors as $newInterceptor) { |
|
93 | + if ($interceptor instanceof self){ |
|
94 | + foreach ($interceptors as $newInterceptor){ |
|
95 | 95 | $newInterceptors[] = $newInterceptor; |
96 | 96 | } |
97 | 97 | } |
98 | 98 | } |
99 | 99 | |
100 | - if (\count($newInterceptors) !== \count($oldInterceptors)) { |
|
100 | + if (\count($newInterceptors) !== \count($oldInterceptors)){ |
|
101 | 101 | $pipelineReflection->setValue($pipeline, $newInterceptors); |
102 | 102 | } |
103 | 103 | } |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | private function getCachedPipeline(string $controller, string $action, Pipeline $annotation): array |
106 | 106 | { |
107 | 107 | $key = "{$controller}:{$action}"; |
108 | - if (!\array_key_exists($key, $this->cache)) { |
|
108 | + if (!\array_key_exists($key, $this->cache)){ |
|
109 | 109 | $this->cache[$key] = $this->extractAnnotationPipeline($annotation); |
110 | 110 | } |
111 | 111 | |
@@ -115,10 +115,10 @@ discard block |
||
115 | 115 | private function extractAnnotationPipeline(Pipeline $annotation): array |
116 | 116 | { |
117 | 117 | $interceptors = []; |
118 | - foreach ($annotation->pipeline as $interceptor) { |
|
119 | - try { |
|
118 | + foreach ($annotation->pipeline as $interceptor){ |
|
119 | + try{ |
|
120 | 120 | $interceptors[] = $this->container->get($interceptor); |
121 | - } catch (\Throwable) { |
|
121 | + }catch (\Throwable){ |
|
122 | 122 | } |
123 | 123 | } |
124 | 124 |
@@ -24,7 +24,8 @@ discard block |
||
24 | 24 | private ReaderInterface $reader, |
25 | 25 | private ContainerInterface $container, |
26 | 26 | private ?EventDispatcherInterface $dispatcher = null, |
27 | - ) {} |
|
27 | + ) { |
|
28 | +} |
|
28 | 29 | |
29 | 30 | /** |
30 | 31 | * @throws \Throwable |
@@ -32,17 +33,23 @@ discard block |
||
32 | 33 | public function process(string $controller, string $action, array $parameters, CoreInterface $core): mixed |
33 | 34 | { |
34 | 35 | $annotation = $this->readAnnotation($controller, $action); |
35 | - if ($core instanceof InterceptorPipeline && $annotation->skipNext) { |
|
36 | + if ($core instanceof InterceptorPipeline && $annotation->skipNext) |
|
37 | + { |
|
36 | 38 | $this->removeNextInterceptorsFromOriginalPipeline($core); |
37 | 39 | } |
38 | 40 | |
39 | 41 | $pipeline = $this->getCachedPipeline($controller, $action, $annotation); |
40 | - if (!empty($pipeline)) { |
|
41 | - if ($core instanceof InterceptorPipeline) { |
|
42 | + if (!empty($pipeline)) |
|
43 | + { |
|
44 | + if ($core instanceof InterceptorPipeline) |
|
45 | + { |
|
42 | 46 | $this->injectInterceptorsIntoOriginalPipeline($core, $pipeline); |
43 | - } else { |
|
47 | + } |
|
48 | + else |
|
49 | + { |
|
44 | 50 | $core = new InterceptableCore($core, $this->dispatcher); |
45 | - foreach ($pipeline as $interceptor) { |
|
51 | + foreach ($pipeline as $interceptor) |
|
52 | + { |
|
46 | 53 | $core->addInterceptor($interceptor); |
47 | 54 | } |
48 | 55 | } |
@@ -53,9 +60,12 @@ discard block |
||
53 | 60 | |
54 | 61 | private function readAnnotation(string $controller, string $action): Pipeline |
55 | 62 | { |
56 | - try { |
|
63 | + try |
|
64 | + { |
|
57 | 65 | $method = new \ReflectionMethod($controller, $action); |
58 | - } catch (\ReflectionException) { |
|
66 | + } |
|
67 | + catch (\ReflectionException) |
|
68 | + { |
|
59 | 69 | return new Pipeline(); |
60 | 70 | } |
61 | 71 | |
@@ -70,14 +80,17 @@ discard block |
||
70 | 80 | |
71 | 81 | $oldInterceptors = $pipelineReflection->getValue($pipeline); |
72 | 82 | $newInterceptors = []; |
73 | - foreach ($oldInterceptors as $interceptor) { |
|
83 | + foreach ($oldInterceptors as $interceptor) |
|
84 | + { |
|
74 | 85 | $newInterceptors[] = $interceptor; |
75 | - if ($interceptor instanceof self) { |
|
86 | + if ($interceptor instanceof self) |
|
87 | + { |
|
76 | 88 | break; |
77 | 89 | } |
78 | 90 | } |
79 | 91 | |
80 | - if (\count($newInterceptors) !== \count($oldInterceptors)) { |
|
92 | + if (\count($newInterceptors) !== \count($oldInterceptors)) |
|
93 | + { |
|
81 | 94 | $pipelineReflection->setValue($pipeline, $newInterceptors); |
82 | 95 | } |
83 | 96 | } |
@@ -88,16 +101,20 @@ discard block |
||
88 | 101 | |
89 | 102 | $oldInterceptors = $pipelineReflection->getValue($pipeline); |
90 | 103 | $newInterceptors = []; |
91 | - foreach ($oldInterceptors as $interceptor) { |
|
104 | + foreach ($oldInterceptors as $interceptor) |
|
105 | + { |
|
92 | 106 | $newInterceptors[] = $interceptor; |
93 | - if ($interceptor instanceof self) { |
|
94 | - foreach ($interceptors as $newInterceptor) { |
|
107 | + if ($interceptor instanceof self) |
|
108 | + { |
|
109 | + foreach ($interceptors as $newInterceptor) |
|
110 | + { |
|
95 | 111 | $newInterceptors[] = $newInterceptor; |
96 | 112 | } |
97 | 113 | } |
98 | 114 | } |
99 | 115 | |
100 | - if (\count($newInterceptors) !== \count($oldInterceptors)) { |
|
116 | + if (\count($newInterceptors) !== \count($oldInterceptors)) |
|
117 | + { |
|
101 | 118 | $pipelineReflection->setValue($pipeline, $newInterceptors); |
102 | 119 | } |
103 | 120 | } |
@@ -105,7 +122,8 @@ discard block |
||
105 | 122 | private function getCachedPipeline(string $controller, string $action, Pipeline $annotation): array |
106 | 123 | { |
107 | 124 | $key = "{$controller}:{$action}"; |
108 | - if (!\array_key_exists($key, $this->cache)) { |
|
125 | + if (!\array_key_exists($key, $this->cache)) |
|
126 | + { |
|
109 | 127 | $this->cache[$key] = $this->extractAnnotationPipeline($annotation); |
110 | 128 | } |
111 | 129 | |
@@ -115,10 +133,14 @@ discard block |
||
115 | 133 | private function extractAnnotationPipeline(Pipeline $annotation): array |
116 | 134 | { |
117 | 135 | $interceptors = []; |
118 | - foreach ($annotation->pipeline as $interceptor) { |
|
119 | - try { |
|
136 | + foreach ($annotation->pipeline as $interceptor) |
|
137 | + { |
|
138 | + try |
|
139 | + { |
|
120 | 140 | $interceptors[] = $this->container->get($interceptor); |
121 | - } catch (\Throwable) { |
|
141 | + } |
|
142 | + catch (\Throwable) |
|
143 | + { |
|
122 | 144 | } |
123 | 145 | } |
124 | 146 |
@@ -11,7 +11,7 @@ |
||
11 | 11 | public int $code; |
12 | 12 | public string $message; |
13 | 13 | |
14 | - protected function __construct() {} |
|
14 | + protected function __construct(){} |
|
15 | 15 | |
16 | 16 | public static function failed(): self |
17 | 17 | { |
@@ -11,7 +11,9 @@ |
||
11 | 11 | public int $code; |
12 | 12 | public string $message; |
13 | 13 | |
14 | - protected function __construct() {} |
|
14 | + protected function __construct() |
|
15 | + { |
|
16 | +} |
|
15 | 17 | |
16 | 18 | public static function failed(): self |
17 | 19 | { |
@@ -11,14 +11,14 @@ |
||
11 | 11 | |
12 | 12 | final class TestResponseFactory implements ResponseFactoryInterface |
13 | 13 | { |
14 | - public function __construct(protected readonly HttpConfig $config) {} |
|
14 | + public function __construct(protected readonly HttpConfig $config){} |
|
15 | 15 | |
16 | 16 | public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface |
17 | 17 | { |
18 | 18 | $response = new Response($code); |
19 | 19 | $response = $response->withStatus($code, $reasonPhrase); |
20 | 20 | |
21 | - foreach ($this->config->getBaseHeaders() as $header => $value) { |
|
21 | + foreach ($this->config->getBaseHeaders() as $header => $value){ |
|
22 | 22 | $response = $response->withAddedHeader($header, $value); |
23 | 23 | } |
24 | 24 |
@@ -11,14 +11,17 @@ |
||
11 | 11 | |
12 | 12 | final class TestResponseFactory implements ResponseFactoryInterface |
13 | 13 | { |
14 | - public function __construct(protected readonly HttpConfig $config) {} |
|
14 | + public function __construct(protected readonly HttpConfig $config) |
|
15 | + { |
|
16 | +} |
|
15 | 17 | |
16 | 18 | public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface |
17 | 19 | { |
18 | 20 | $response = new Response($code); |
19 | 21 | $response = $response->withStatus($code, $reasonPhrase); |
20 | 22 | |
21 | - foreach ($this->config->getBaseHeaders() as $header => $value) { |
|
23 | + foreach ($this->config->getBaseHeaders() as $header => $value) |
|
24 | + { |
|
22 | 25 | $response = $response->withAddedHeader($header, $value); |
23 | 26 | } |
24 | 27 |
@@ -34,17 +34,17 @@ discard block |
||
34 | 34 | public function __construct( |
35 | 35 | private readonly ResponseFactoryInterface $responseFactory, |
36 | 36 | private readonly array $allowMethods = self::ALLOW_METHODS, |
37 | - ) {} |
|
37 | + ){} |
|
38 | 38 | |
39 | 39 | public function process(Request $request, RequestHandlerInterface $handler): Response |
40 | 40 | { |
41 | 41 | $token = $request->getAttribute(CsrfMiddleware::ATTRIBUTE); |
42 | 42 | |
43 | - if (empty($token)) { |
|
43 | + if (empty($token)){ |
|
44 | 44 | throw new \LogicException('Unable to apply CSRF firewall, attribute is missing'); |
45 | 45 | } |
46 | 46 | |
47 | - if ($this->isRequired($request) && !\hash_equals($token, $this->fetchToken($request))) { |
|
47 | + if ($this->isRequired($request) && !\hash_equals($token, $this->fetchToken($request))){ |
|
48 | 48 | return $this->responseFactory->createResponse(412, 'Bad CSRF Token'); |
49 | 49 | } |
50 | 50 | |
@@ -64,12 +64,12 @@ discard block |
||
64 | 64 | */ |
65 | 65 | protected function fetchToken(Request $request): string |
66 | 66 | { |
67 | - if ($request->hasHeader(self::HEADER)) { |
|
67 | + if ($request->hasHeader(self::HEADER)){ |
|
68 | 68 | return $request->getHeaderLine(self::HEADER); |
69 | 69 | } |
70 | 70 | |
71 | 71 | $data = $request->getParsedBody(); |
72 | - if (\is_array($data) && isset($data[self::PARAMETER]) && \is_string($data[self::PARAMETER])) { |
|
72 | + if (\is_array($data) && isset($data[self::PARAMETER]) && \is_string($data[self::PARAMETER])){ |
|
73 | 73 | return $data[self::PARAMETER]; |
74 | 74 | } |
75 | 75 |
@@ -34,17 +34,20 @@ discard block |
||
34 | 34 | public function __construct( |
35 | 35 | private readonly ResponseFactoryInterface $responseFactory, |
36 | 36 | private readonly array $allowMethods = self::ALLOW_METHODS, |
37 | - ) {} |
|
37 | + ) { |
|
38 | +} |
|
38 | 39 | |
39 | 40 | public function process(Request $request, RequestHandlerInterface $handler): Response |
40 | 41 | { |
41 | 42 | $token = $request->getAttribute(CsrfMiddleware::ATTRIBUTE); |
42 | 43 | |
43 | - if (empty($token)) { |
|
44 | + if (empty($token)) |
|
45 | + { |
|
44 | 46 | throw new \LogicException('Unable to apply CSRF firewall, attribute is missing'); |
45 | 47 | } |
46 | 48 | |
47 | - if ($this->isRequired($request) && !\hash_equals($token, $this->fetchToken($request))) { |
|
49 | + if ($this->isRequired($request) && !\hash_equals($token, $this->fetchToken($request))) |
|
50 | + { |
|
48 | 51 | return $this->responseFactory->createResponse(412, 'Bad CSRF Token'); |
49 | 52 | } |
50 | 53 | |
@@ -64,12 +67,14 @@ discard block |
||
64 | 67 | */ |
65 | 68 | protected function fetchToken(Request $request): string |
66 | 69 | { |
67 | - if ($request->hasHeader(self::HEADER)) { |
|
70 | + if ($request->hasHeader(self::HEADER)) |
|
71 | + { |
|
68 | 72 | return $request->getHeaderLine(self::HEADER); |
69 | 73 | } |
70 | 74 | |
71 | 75 | $data = $request->getParsedBody(); |
72 | - if (\is_array($data) && isset($data[self::PARAMETER]) && \is_string($data[self::PARAMETER])) { |
|
76 | + if (\is_array($data) && isset($data[self::PARAMETER]) && \is_string($data[self::PARAMETER])) |
|
77 | + { |
|
73 | 78 | return $data[self::PARAMETER]; |
74 | 79 | } |
75 | 80 |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | |
41 | 41 | public function testInjection(): void |
42 | 42 | { |
43 | - $factory = new class implements LogsInterface { |
|
43 | + $factory = new class implements LogsInterface{ |
|
44 | 44 | public function getLogger(string $channel): LoggerInterface |
45 | 45 | { |
46 | 46 | $mock = \Mockery::mock(LoggerInterface::class); |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | |
58 | 58 | public function testInjectionNullableChannel(): void |
59 | 59 | { |
60 | - $factory = new class implements LogsInterface { |
|
60 | + $factory = new class implements LogsInterface{ |
|
61 | 61 | public function getLogger(?string $channel): LoggerInterface |
62 | 62 | { |
63 | 63 | $mock = \Mockery::mock(LoggerInterface::class); |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | |
75 | 75 | public function testInjectionWithAttribute(): void |
76 | 76 | { |
77 | - $factory = new class implements LogsInterface { |
|
77 | + $factory = new class implements LogsInterface{ |
|
78 | 78 | public function getLogger(?string $channel): LoggerInterface |
79 | 79 | { |
80 | 80 | $mock = \Mockery::mock(LoggerInterface::class); |
@@ -40,7 +40,8 @@ discard block |
||
40 | 40 | |
41 | 41 | public function testInjection(): void |
42 | 42 | { |
43 | - $factory = new class implements LogsInterface { |
|
43 | + $factory = new class implements LogsInterface |
|
44 | + { |
|
44 | 45 | public function getLogger(string $channel): LoggerInterface |
45 | 46 | { |
46 | 47 | $mock = \Mockery::mock(LoggerInterface::class); |
@@ -57,7 +58,8 @@ discard block |
||
57 | 58 | |
58 | 59 | public function testInjectionNullableChannel(): void |
59 | 60 | { |
60 | - $factory = new class implements LogsInterface { |
|
61 | + $factory = new class implements LogsInterface |
|
62 | + { |
|
61 | 63 | public function getLogger(?string $channel): LoggerInterface |
62 | 64 | { |
63 | 65 | $mock = \Mockery::mock(LoggerInterface::class); |
@@ -74,7 +76,8 @@ discard block |
||
74 | 76 | |
75 | 77 | public function testInjectionWithAttribute(): void |
76 | 78 | { |
77 | - $factory = new class implements LogsInterface { |
|
79 | + $factory = new class implements LogsInterface |
|
80 | + { |
|
78 | 81 | public function getLogger(?string $channel): LoggerInterface |
79 | 82 | { |
80 | 83 | $mock = \Mockery::mock(LoggerInterface::class); |
@@ -19,7 +19,7 @@ |
||
19 | 19 | public function __construct( |
20 | 20 | callable $receptor, |
21 | 21 | private readonly string $channel, |
22 | - ) { |
|
22 | + ){ |
|
23 | 23 | $this->receptor = $receptor(...); |
24 | 24 | } |
25 | 25 |