@@ -48,7 +48,7 @@ |
||
48 | 48 | |
49 | 49 | public function input(InputScope $i) |
50 | 50 | { |
51 | - return 'value: ' . $i->withPrefix('section')->getValue('query', 'value'); |
|
51 | + return 'value: '.$i->withPrefix('section')->getValue('query', 'value'); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | public function error(): void |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public function load(string $id): ?TokenInterface |
45 | 45 | { |
46 | - if (strpos($id, ':') === false) { |
|
46 | + if (strpos($id, ':') === false){ |
|
47 | 47 | return null; |
48 | 48 | } |
49 | 49 | |
@@ -52,14 +52,14 @@ discard block |
||
52 | 52 | /** @var Token $token */ |
53 | 53 | $token = $this->orm->getRepository(Token::class)->findByPK($pk); |
54 | 54 | |
55 | - if ($token === null || !hash_equals($token->getHashedValue(), hash('sha512', $hash))) { |
|
55 | + if ($token === null || !hash_equals($token->getHashedValue(), hash('sha512', $hash))){ |
|
56 | 56 | // hijacked or deleted |
57 | 57 | return null; |
58 | 58 | } |
59 | 59 | |
60 | 60 | $token->setSecretValue($hash); |
61 | 61 | |
62 | - if ($token->getExpiresAt() !== null && $token->getExpiresAt() < new \DateTime()) { |
|
62 | + if ($token->getExpiresAt() !== null && $token->getExpiresAt() < new \DateTime()){ |
|
63 | 63 | $this->delete($token); |
64 | 64 | return null; |
65 | 65 | } |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | */ |
73 | 73 | public function create(array $payload, \DateTimeInterface $expiresAt = null): TokenInterface |
74 | 74 | { |
75 | - try { |
|
75 | + try{ |
|
76 | 76 | $token = new Token( |
77 | 77 | $this->issueID(), |
78 | 78 | $this->randomHash(128), |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | $this->em->persist($token)->run(); |
85 | 85 | |
86 | 86 | return $token; |
87 | - } catch (\Throwable $e) { |
|
87 | + }catch (\Throwable $e){ |
|
88 | 88 | throw new TokenStorageException('Unable to create token', $e->getCode(), $e); |
89 | 89 | } |
90 | 90 | } |
@@ -94,9 +94,9 @@ discard block |
||
94 | 94 | */ |
95 | 95 | public function delete(TokenInterface $token): void |
96 | 96 | { |
97 | - try { |
|
97 | + try{ |
|
98 | 98 | $this->em->delete($token)->run(); |
99 | - } catch (\Throwable $e) { |
|
99 | + }catch (\Throwable $e){ |
|
100 | 100 | throw new TokenStorageException('Unable to delete token', $e->getCode(), $e); |
101 | 101 | } |
102 | 102 | } |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | $this->orm->getSource(Token::class)->getTable() |
116 | 116 | ); |
117 | 117 | |
118 | - while ((clone $query)->where('id', $id)->count('id') !== 0) { |
|
118 | + while ((clone $query)->where('id', $id)->count('id') !== 0){ |
|
119 | 119 | $id = $this->randomHash(64); |
120 | 120 | } |
121 | 121 |
@@ -43,7 +43,8 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public function load(string $id): ?TokenInterface |
45 | 45 | { |
46 | - if (strpos($id, ':') === false) { |
|
46 | + if (strpos($id, ':') === false) |
|
47 | + { |
|
47 | 48 | return null; |
48 | 49 | } |
49 | 50 | |
@@ -52,14 +53,16 @@ discard block |
||
52 | 53 | /** @var Token $token */ |
53 | 54 | $token = $this->orm->getRepository(Token::class)->findByPK($pk); |
54 | 55 | |
55 | - if ($token === null || !hash_equals($token->getHashedValue(), hash('sha512', $hash))) { |
|
56 | + if ($token === null || !hash_equals($token->getHashedValue(), hash('sha512', $hash))) |
|
57 | + { |
|
56 | 58 | // hijacked or deleted |
57 | 59 | return null; |
58 | 60 | } |
59 | 61 | |
60 | 62 | $token->setSecretValue($hash); |
61 | 63 | |
62 | - if ($token->getExpiresAt() !== null && $token->getExpiresAt() < new \DateTime()) { |
|
64 | + if ($token->getExpiresAt() !== null && $token->getExpiresAt() < new \DateTime()) |
|
65 | + { |
|
63 | 66 | $this->delete($token); |
64 | 67 | return null; |
65 | 68 | } |
@@ -72,7 +75,8 @@ discard block |
||
72 | 75 | */ |
73 | 76 | public function create(array $payload, \DateTimeInterface $expiresAt = null): TokenInterface |
74 | 77 | { |
75 | - try { |
|
78 | + try |
|
79 | + { |
|
76 | 80 | $token = new Token( |
77 | 81 | $this->issueID(), |
78 | 82 | $this->randomHash(128), |
@@ -84,7 +88,9 @@ discard block |
||
84 | 88 | $this->em->persist($token)->run(); |
85 | 89 | |
86 | 90 | return $token; |
87 | - } catch (\Throwable $e) { |
|
91 | + } |
|
92 | + catch (\Throwable $e) |
|
93 | + { |
|
88 | 94 | throw new TokenStorageException('Unable to create token', $e->getCode(), $e); |
89 | 95 | } |
90 | 96 | } |
@@ -94,9 +100,12 @@ discard block |
||
94 | 100 | */ |
95 | 101 | public function delete(TokenInterface $token): void |
96 | 102 | { |
97 | - try { |
|
103 | + try |
|
104 | + { |
|
98 | 105 | $this->em->delete($token)->run(); |
99 | - } catch (\Throwable $e) { |
|
106 | + } |
|
107 | + catch (\Throwable $e) |
|
108 | + { |
|
100 | 109 | throw new TokenStorageException('Unable to delete token', $e->getCode(), $e); |
101 | 110 | } |
102 | 111 | } |
@@ -115,7 +124,8 @@ discard block |
||
115 | 124 | $this->orm->getSource(Token::class)->getTable() |
116 | 125 | ); |
117 | 126 | |
118 | - while ((clone $query)->where('id', $id)->count('id') !== 0) { |
|
127 | + while ((clone $query)->where('id', $id)->count('id') !== 0) |
|
128 | + { |
|
119 | 129 | $id = $this->randomHash(64); |
120 | 130 | } |
121 | 131 |
@@ -49,15 +49,15 @@ discard block |
||
49 | 49 | */ |
50 | 50 | public function process(string $controller, string $action, array $parameters, CoreInterface $core) |
51 | 51 | { |
52 | - foreach ($this->getDeclaredFilters($controller, $action) as $parameter => $filterClass) { |
|
53 | - if (isset($parameters[$parameter])) { |
|
52 | + foreach ($this->getDeclaredFilters($controller, $action) as $parameter => $filterClass){ |
|
53 | + if (isset($parameters[$parameter])){ |
|
54 | 54 | continue; |
55 | 55 | } |
56 | 56 | |
57 | 57 | /** @var FilterInterface $filter */ |
58 | 58 | $filter = $this->container->get($filterClass); |
59 | 59 | |
60 | - if (!$filter->isValid()) { |
|
60 | + if (!$filter->isValid()){ |
|
61 | 61 | return $this->renderInvalid($filter); |
62 | 62 | } |
63 | 63 | |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | */ |
76 | 76 | protected function renderInvalid(FilterInterface $filter) |
77 | 77 | { |
78 | - switch ($this->strategy) { |
|
78 | + switch ($this->strategy){ |
|
79 | 79 | case self::STRATEGY_JSON_RESPONSE: |
80 | 80 | return [ |
81 | 81 | 'status' => 400, |
@@ -94,23 +94,23 @@ discard block |
||
94 | 94 | private function getDeclaredFilters(string $controller, string $action): array |
95 | 95 | { |
96 | 96 | $key = sprintf('%s:%s', $controller, $action); |
97 | - if (array_key_exists($key, $this->cache)) { |
|
97 | + if (array_key_exists($key, $this->cache)){ |
|
98 | 98 | return $this->cache[$key]; |
99 | 99 | } |
100 | 100 | |
101 | 101 | $this->cache[$key] = []; |
102 | - try { |
|
102 | + try{ |
|
103 | 103 | $method = new \ReflectionMethod($controller, $action); |
104 | - } catch (\ReflectionException $e) { |
|
104 | + }catch (\ReflectionException $e){ |
|
105 | 105 | return []; |
106 | 106 | } |
107 | 107 | |
108 | - foreach ($method->getParameters() as $parameter) { |
|
109 | - if ($parameter->getClass() === null) { |
|
108 | + foreach ($method->getParameters() as $parameter){ |
|
109 | + if ($parameter->getClass() === null){ |
|
110 | 110 | continue; |
111 | 111 | } |
112 | 112 | |
113 | - if ($parameter->getClass()->implementsInterface(FilterInterface::class)) { |
|
113 | + if ($parameter->getClass()->implementsInterface(FilterInterface::class)){ |
|
114 | 114 | $this->cache[$key][$parameter->getName()] = $parameter->getClass()->getName(); |
115 | 115 | } |
116 | 116 | } |
@@ -49,15 +49,18 @@ discard block |
||
49 | 49 | */ |
50 | 50 | public function process(string $controller, string $action, array $parameters, CoreInterface $core) |
51 | 51 | { |
52 | - foreach ($this->getDeclaredFilters($controller, $action) as $parameter => $filterClass) { |
|
53 | - if (isset($parameters[$parameter])) { |
|
52 | + foreach ($this->getDeclaredFilters($controller, $action) as $parameter => $filterClass) |
|
53 | + { |
|
54 | + if (isset($parameters[$parameter])) |
|
55 | + { |
|
54 | 56 | continue; |
55 | 57 | } |
56 | 58 | |
57 | 59 | /** @var FilterInterface $filter */ |
58 | 60 | $filter = $this->container->get($filterClass); |
59 | 61 | |
60 | - if (!$filter->isValid()) { |
|
62 | + if (!$filter->isValid()) |
|
63 | + { |
|
61 | 64 | return $this->renderInvalid($filter); |
62 | 65 | } |
63 | 66 | |
@@ -75,7 +78,8 @@ discard block |
||
75 | 78 | */ |
76 | 79 | protected function renderInvalid(FilterInterface $filter) |
77 | 80 | { |
78 | - switch ($this->strategy) { |
|
81 | + switch ($this->strategy) |
|
82 | + { |
|
79 | 83 | case self::STRATEGY_JSON_RESPONSE: |
80 | 84 | return [ |
81 | 85 | 'status' => 400, |
@@ -94,23 +98,30 @@ discard block |
||
94 | 98 | private function getDeclaredFilters(string $controller, string $action): array |
95 | 99 | { |
96 | 100 | $key = sprintf('%s:%s', $controller, $action); |
97 | - if (array_key_exists($key, $this->cache)) { |
|
101 | + if (array_key_exists($key, $this->cache)) |
|
102 | + { |
|
98 | 103 | return $this->cache[$key]; |
99 | 104 | } |
100 | 105 | |
101 | 106 | $this->cache[$key] = []; |
102 | - try { |
|
107 | + try |
|
108 | + { |
|
103 | 109 | $method = new \ReflectionMethod($controller, $action); |
104 | - } catch (\ReflectionException $e) { |
|
110 | + } |
|
111 | + catch (\ReflectionException $e) |
|
112 | + { |
|
105 | 113 | return []; |
106 | 114 | } |
107 | 115 | |
108 | - foreach ($method->getParameters() as $parameter) { |
|
109 | - if ($parameter->getClass() === null) { |
|
116 | + foreach ($method->getParameters() as $parameter) |
|
117 | + { |
|
118 | + if ($parameter->getClass() === null) |
|
119 | + { |
|
110 | 120 | continue; |
111 | 121 | } |
112 | 122 | |
113 | - if ($parameter->getClass()->implementsInterface(FilterInterface::class)) { |
|
123 | + if ($parameter->getClass()->implementsInterface(FilterInterface::class)) |
|
124 | + { |
|
114 | 125 | $this->cache[$key][$parameter->getName()] = $parameter->getClass()->getName(); |
115 | 126 | } |
116 | 127 | } |
@@ -38,7 +38,7 @@ |
||
38 | 38 | { |
39 | 39 | $core = new InterceptableCore($core); |
40 | 40 | |
41 | - foreach (static::INTERCEPTORS as $interceptor) { |
|
41 | + foreach (static::INTERCEPTORS as $interceptor){ |
|
42 | 42 | $core->addInterceptor($container->get($interceptor)); |
43 | 43 | } |
44 | 44 |
@@ -38,7 +38,8 @@ |
||
38 | 38 | { |
39 | 39 | $core = new InterceptableCore($core); |
40 | 40 | |
41 | - foreach (static::INTERCEPTORS as $interceptor) { |
|
41 | + foreach (static::INTERCEPTORS as $interceptor) |
|
42 | + { |
|
42 | 43 | $core->addInterceptor($container->get($interceptor)); |
43 | 44 | } |
44 | 45 |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | |
37 | 37 | public function testHasCookie(): void |
38 | 38 | { |
39 | - $this->http->setHandler(function () { |
|
39 | + $this->http->setHandler(function (){ |
|
40 | 40 | return (int)$this->cookies()->has('a'); |
41 | 41 | }); |
42 | 42 | |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | ]); |
55 | 55 | $this->http = $this->app->get(Http::class); |
56 | 56 | |
57 | - $this->http->setHandler(function () { |
|
57 | + $this->http->setHandler(function (){ |
|
58 | 58 | return (int)$this->cookies()->has('a'); |
59 | 59 | }); |
60 | 60 | |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | $this->app = $this->makeApp(['ENCRYPTER_KEY' => $key]); |
72 | 72 | $this->http = $this->app->get(Http::class); |
73 | 73 | |
74 | - $this->http->setHandler(function () { |
|
74 | + $this->http->setHandler(function (){ |
|
75 | 75 | return $this->cookies()->get('a'); |
76 | 76 | }); |
77 | 77 | |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | $this->app = $this->makeApp(['ENCRYPTER_KEY' => $key]); |
89 | 89 | $this->http = $this->app->get(Http::class); |
90 | 90 | |
91 | - $this->http->setHandler(function () { |
|
91 | + $this->http->setHandler(function (){ |
|
92 | 92 | $this->cookies()->set('a', 'value'); |
93 | 93 | |
94 | 94 | return 'ok'; |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | $this->app = $this->makeApp(['ENCRYPTER_KEY' => $key]); |
113 | 113 | $this->http = $this->app->get(Http::class); |
114 | 114 | |
115 | - $this->http->setHandler(function () { |
|
115 | + $this->http->setHandler(function (){ |
|
116 | 116 | $this->cookies()->schedule(Cookie::create('a', 'value')); |
117 | 117 | $this->assertSame([], $this->cookies()->getAll()); |
118 | 118 | $this->assertCount(1, $this->cookies()->getScheduled()); |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | $this->app = $this->makeApp(['ENCRYPTER_KEY' => $key]); |
139 | 139 | $this->http = $this->app->get(Http::class); |
140 | 140 | |
141 | - $this->http->setHandler(function () { |
|
141 | + $this->http->setHandler(function (){ |
|
142 | 142 | $this->cookies()->delete('cookie'); |
143 | 143 | |
144 | 144 | return 'ok'; |
@@ -36,7 +36,8 @@ discard block |
||
36 | 36 | |
37 | 37 | public function testHasCookie(): void |
38 | 38 | { |
39 | - $this->http->setHandler(function () { |
|
39 | + $this->http->setHandler(function () |
|
40 | + { |
|
40 | 41 | return (int)$this->cookies()->has('a'); |
41 | 42 | }); |
42 | 43 | |
@@ -54,7 +55,8 @@ discard block |
||
54 | 55 | ]); |
55 | 56 | $this->http = $this->app->get(Http::class); |
56 | 57 | |
57 | - $this->http->setHandler(function () { |
|
58 | + $this->http->setHandler(function () |
|
59 | + { |
|
58 | 60 | return (int)$this->cookies()->has('a'); |
59 | 61 | }); |
60 | 62 | |
@@ -71,7 +73,8 @@ discard block |
||
71 | 73 | $this->app = $this->makeApp(['ENCRYPTER_KEY' => $key]); |
72 | 74 | $this->http = $this->app->get(Http::class); |
73 | 75 | |
74 | - $this->http->setHandler(function () { |
|
76 | + $this->http->setHandler(function () |
|
77 | + { |
|
75 | 78 | return $this->cookies()->get('a'); |
76 | 79 | }); |
77 | 80 | |
@@ -88,7 +91,8 @@ discard block |
||
88 | 91 | $this->app = $this->makeApp(['ENCRYPTER_KEY' => $key]); |
89 | 92 | $this->http = $this->app->get(Http::class); |
90 | 93 | |
91 | - $this->http->setHandler(function () { |
|
94 | + $this->http->setHandler(function () |
|
95 | + { |
|
92 | 96 | $this->cookies()->set('a', 'value'); |
93 | 97 | |
94 | 98 | return 'ok'; |
@@ -112,7 +116,8 @@ discard block |
||
112 | 116 | $this->app = $this->makeApp(['ENCRYPTER_KEY' => $key]); |
113 | 117 | $this->http = $this->app->get(Http::class); |
114 | 118 | |
115 | - $this->http->setHandler(function () { |
|
119 | + $this->http->setHandler(function () |
|
120 | + { |
|
116 | 121 | $this->cookies()->schedule(Cookie::create('a', 'value')); |
117 | 122 | $this->assertSame([], $this->cookies()->getAll()); |
118 | 123 | $this->assertCount(1, $this->cookies()->getScheduled()); |
@@ -138,7 +143,8 @@ discard block |
||
138 | 143 | $this->app = $this->makeApp(['ENCRYPTER_KEY' => $key]); |
139 | 144 | $this->http = $this->app->get(Http::class); |
140 | 145 | |
141 | - $this->http->setHandler(function () { |
|
146 | + $this->http->setHandler(function () |
|
147 | + { |
|
142 | 148 | $this->cookies()->delete('cookie'); |
143 | 149 | |
144 | 150 | return 'ok'; |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | |
29 | 29 | public function do(GuardInterface $guard) |
30 | 30 | { |
31 | - if (!$guard->allows('do')) { |
|
31 | + if (!$guard->allows('do')){ |
|
32 | 32 | throw new ControllerException("Unauthorized permission 'do'", ControllerException::FORBIDDEN); |
33 | 33 | } |
34 | 34 | |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | |
38 | 38 | public function token(AuthContextInterface $authContext) |
39 | 39 | { |
40 | - if ($authContext->getToken() !== null) { |
|
40 | + if ($authContext->getToken() !== null){ |
|
41 | 41 | return $authContext->getToken()->getID(); |
42 | 42 | } |
43 | 43 | |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | |
56 | 56 | public function token2() |
57 | 57 | { |
58 | - if ($this->auth->getToken() !== null) { |
|
58 | + if ($this->auth->getToken() !== null){ |
|
59 | 59 | return $this->auth->getToken()->getID(); |
60 | 60 | } |
61 | 61 |
@@ -26,10 +26,12 @@ discard block |
||
26 | 26 | $this->auth = $auth; |
27 | 27 | } |
28 | 28 | |
29 | - public function do(GuardInterface $guard) |
|
29 | + public function do{ |
|
30 | + (GuardInterface $guard) |
|
30 | 31 | { |
31 | 32 | if (!$guard->allows('do')) { |
32 | 33 | throw new ControllerException("Unauthorized permission 'do'", ControllerException::FORBIDDEN); |
34 | + } |
|
33 | 35 | } |
34 | 36 | |
35 | 37 | return 'ok'; |
@@ -37,7 +39,8 @@ discard block |
||
37 | 39 | |
38 | 40 | public function token(AuthContextInterface $authContext) |
39 | 41 | { |
40 | - if ($authContext->getToken() !== null) { |
|
42 | + if ($authContext->getToken() !== null) |
|
43 | + { |
|
41 | 44 | return $authContext->getToken()->getID(); |
42 | 45 | } |
43 | 46 | |
@@ -55,7 +58,8 @@ discard block |
||
55 | 58 | |
56 | 59 | public function token2() |
57 | 60 | { |
58 | - if ($this->auth->getToken() !== null) { |
|
61 | + if ($this->auth->getToken() !== null) |
|
62 | + { |
|
59 | 63 | return $this->auth->getToken()->getID(); |
60 | 64 | } |
61 | 65 |
@@ -40,8 +40,10 @@ |
||
40 | 40 | * @Guarded("do") |
41 | 41 | * @return string |
42 | 42 | */ |
43 | - public function do() |
|
43 | + public function do{ |
|
44 | + () |
|
44 | 45 | { |
45 | 46 | return 'ok'; |
46 | 47 | } |
48 | + } |
|
47 | 49 | } |
@@ -45,22 +45,22 @@ discard block |
||
45 | 45 | { |
46 | 46 | $entities = $this->getDeclaredEntities($controller, $action); |
47 | 47 | |
48 | - foreach ($entities as $parameter => $role) { |
|
48 | + foreach ($entities as $parameter => $role){ |
|
49 | 49 | $value = $this->getParameter($parameter, $parameters, count($entities) === 1); |
50 | - if ($value === null) { |
|
50 | + if ($value === null){ |
|
51 | 51 | throw new ControllerException( |
52 | 52 | "Entity `{$parameter}` can not be found", |
53 | 53 | ControllerException::NOT_FOUND |
54 | 54 | ); |
55 | 55 | } |
56 | 56 | |
57 | - if (is_object($value)) { |
|
57 | + if (is_object($value)){ |
|
58 | 58 | // pre-filled |
59 | 59 | continue; |
60 | 60 | } |
61 | 61 | |
62 | 62 | $entity = $this->resolveEntity($role, $value); |
63 | - if ($entity === null) { |
|
63 | + if ($entity === null){ |
|
64 | 64 | throw new ControllerException( |
65 | 65 | "Entity `{$parameter}` can not be found", |
66 | 66 | ControllerException::NOT_FOUND |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | */ |
82 | 82 | protected function getParameter(string $role, array $parameters, bool $useDefault = false) |
83 | 83 | { |
84 | - if (!$useDefault) { |
|
84 | + if (!$useDefault){ |
|
85 | 85 | return $parameters[$role] ?? null; |
86 | 86 | } |
87 | 87 | |
@@ -106,23 +106,23 @@ discard block |
||
106 | 106 | private function getDeclaredEntities(string $controller, string $action): array |
107 | 107 | { |
108 | 108 | $key = sprintf('%s:%s', $controller, $action); |
109 | - if (array_key_exists($key, $this->cache)) { |
|
109 | + if (array_key_exists($key, $this->cache)){ |
|
110 | 110 | return $this->cache[$key]; |
111 | 111 | } |
112 | 112 | |
113 | 113 | $this->cache[$key] = []; |
114 | - try { |
|
114 | + try{ |
|
115 | 115 | $method = new \ReflectionMethod($controller, $action); |
116 | - } catch (\ReflectionException $e) { |
|
116 | + }catch (\ReflectionException $e){ |
|
117 | 117 | return []; |
118 | 118 | } |
119 | 119 | |
120 | - foreach ($method->getParameters() as $parameter) { |
|
121 | - if ($parameter->getClass() === null) { |
|
120 | + foreach ($method->getParameters() as $parameter){ |
|
121 | + if ($parameter->getClass() === null){ |
|
122 | 122 | continue; |
123 | 123 | } |
124 | 124 | |
125 | - if ($this->orm->getSchema()->defines($parameter->getClass()->getName())) { |
|
125 | + if ($this->orm->getSchema()->defines($parameter->getClass()->getName())){ |
|
126 | 126 | $this->cache[$key][$parameter->getName()] = $this->orm->resolveRole($parameter->getClass()->getName()); |
127 | 127 | } |
128 | 128 | } |
@@ -45,22 +45,26 @@ discard block |
||
45 | 45 | { |
46 | 46 | $entities = $this->getDeclaredEntities($controller, $action); |
47 | 47 | |
48 | - foreach ($entities as $parameter => $role) { |
|
48 | + foreach ($entities as $parameter => $role) |
|
49 | + { |
|
49 | 50 | $value = $this->getParameter($parameter, $parameters, count($entities) === 1); |
50 | - if ($value === null) { |
|
51 | + if ($value === null) |
|
52 | + { |
|
51 | 53 | throw new ControllerException( |
52 | 54 | "Entity `{$parameter}` can not be found", |
53 | 55 | ControllerException::NOT_FOUND |
54 | 56 | ); |
55 | 57 | } |
56 | 58 | |
57 | - if (is_object($value)) { |
|
59 | + if (is_object($value)) |
|
60 | + { |
|
58 | 61 | // pre-filled |
59 | 62 | continue; |
60 | 63 | } |
61 | 64 | |
62 | 65 | $entity = $this->resolveEntity($role, $value); |
63 | - if ($entity === null) { |
|
66 | + if ($entity === null) |
|
67 | + { |
|
64 | 68 | throw new ControllerException( |
65 | 69 | "Entity `{$parameter}` can not be found", |
66 | 70 | ControllerException::NOT_FOUND |
@@ -81,7 +85,8 @@ discard block |
||
81 | 85 | */ |
82 | 86 | protected function getParameter(string $role, array $parameters, bool $useDefault = false) |
83 | 87 | { |
84 | - if (!$useDefault) { |
|
88 | + if (!$useDefault) |
|
89 | + { |
|
85 | 90 | return $parameters[$role] ?? null; |
86 | 91 | } |
87 | 92 | |
@@ -106,23 +111,30 @@ discard block |
||
106 | 111 | private function getDeclaredEntities(string $controller, string $action): array |
107 | 112 | { |
108 | 113 | $key = sprintf('%s:%s', $controller, $action); |
109 | - if (array_key_exists($key, $this->cache)) { |
|
114 | + if (array_key_exists($key, $this->cache)) |
|
115 | + { |
|
110 | 116 | return $this->cache[$key]; |
111 | 117 | } |
112 | 118 | |
113 | 119 | $this->cache[$key] = []; |
114 | - try { |
|
120 | + try |
|
121 | + { |
|
115 | 122 | $method = new \ReflectionMethod($controller, $action); |
116 | - } catch (\ReflectionException $e) { |
|
123 | + } |
|
124 | + catch (\ReflectionException $e) |
|
125 | + { |
|
117 | 126 | return []; |
118 | 127 | } |
119 | 128 | |
120 | - foreach ($method->getParameters() as $parameter) { |
|
121 | - if ($parameter->getClass() === null) { |
|
129 | + foreach ($method->getParameters() as $parameter) |
|
130 | + { |
|
131 | + if ($parameter->getClass() === null) |
|
132 | + { |
|
122 | 133 | continue; |
123 | 134 | } |
124 | 135 | |
125 | - if ($this->orm->getSchema()->defines($parameter->getClass()->getName())) { |
|
136 | + if ($this->orm->getSchema()->defines($parameter->getClass()->getName())) |
|
137 | + { |
|
126 | 138 | $this->cache[$key][$parameter->getName()] = $this->orm->resolveRole($parameter->getClass()->getName()); |
127 | 139 | } |
128 | 140 | } |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | { |
53 | 53 | $permission = $this->getPermissions($controller, $action); |
54 | 54 | |
55 | - if ($permission !== null && !$this->guard->allows($permission[0], $parameters)) { |
|
55 | + if ($permission !== null && !$this->guard->allows($permission[0], $parameters)){ |
|
56 | 56 | throw new ControllerException( |
57 | 57 | sprintf( |
58 | 58 | 'Unauthorized permission `%s` for action `%s`->`%s`', |
@@ -79,14 +79,14 @@ discard block |
||
79 | 79 | private function getPermissions(string $controller, string $action): ?array |
80 | 80 | { |
81 | 81 | $key = sprintf('%s:%s', $controller, $action); |
82 | - if (array_key_exists($key, $this->cache)) { |
|
82 | + if (array_key_exists($key, $this->cache)){ |
|
83 | 83 | return $this->cache[$key]; |
84 | 84 | } |
85 | 85 | |
86 | 86 | $this->cache[$key] = null; |
87 | - try { |
|
87 | + try{ |
|
88 | 88 | $method = new \ReflectionMethod($controller, $action); |
89 | - } catch (\ReflectionException $e) { |
|
89 | + }catch (\ReflectionException $e){ |
|
90 | 90 | return null; |
91 | 91 | } |
92 | 92 | |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | Guarded::class |
105 | 105 | ); |
106 | 106 | |
107 | - if ($action === null) { |
|
107 | + if ($action === null){ |
|
108 | 108 | return null; |
109 | 109 | } |
110 | 110 | |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | ControllerException::FORBIDDEN |
127 | 127 | ]; |
128 | 128 | |
129 | - if ($guarded->permission === null && $ns === null) { |
|
129 | + if ($guarded->permission === null && $ns === null){ |
|
130 | 130 | throw new InterceptorException(sprintf( |
131 | 131 | 'Unable to apply @Guarded without name or @GuardNamespace on `%s`->`%s`', |
132 | 132 | $method->getDeclaringClass()->getName(), |
@@ -134,16 +134,16 @@ discard block |
||
134 | 134 | )); |
135 | 135 | } |
136 | 136 | |
137 | - if ($ns !== null) { |
|
137 | + if ($ns !== null){ |
|
138 | 138 | $permission[0] = sprintf('%s.%s', $ns->namespace, $permission[0]); |
139 | 139 | } |
140 | 140 | |
141 | - if ($this->namespace !== null) { |
|
141 | + if ($this->namespace !== null){ |
|
142 | 142 | // global namespace |
143 | 143 | $permission[0] = sprintf('%s.%s', $this->namespace, $permission[0]); |
144 | 144 | } |
145 | 145 | |
146 | - switch ($guarded->else) { |
|
146 | + switch ($guarded->else){ |
|
147 | 147 | case 'badAction': |
148 | 148 | $permission[1] = ControllerException::BAD_ACTION; |
149 | 149 | break; |
@@ -52,7 +52,8 @@ discard block |
||
52 | 52 | { |
53 | 53 | $permission = $this->getPermissions($controller, $action); |
54 | 54 | |
55 | - if ($permission !== null && !$this->guard->allows($permission[0], $parameters)) { |
|
55 | + if ($permission !== null && !$this->guard->allows($permission[0], $parameters)) |
|
56 | + { |
|
56 | 57 | throw new ControllerException( |
57 | 58 | sprintf( |
58 | 59 | 'Unauthorized permission `%s` for action `%s`->`%s`', |
@@ -79,14 +80,18 @@ discard block |
||
79 | 80 | private function getPermissions(string $controller, string $action): ?array |
80 | 81 | { |
81 | 82 | $key = sprintf('%s:%s', $controller, $action); |
82 | - if (array_key_exists($key, $this->cache)) { |
|
83 | + if (array_key_exists($key, $this->cache)) |
|
84 | + { |
|
83 | 85 | return $this->cache[$key]; |
84 | 86 | } |
85 | 87 | |
86 | 88 | $this->cache[$key] = null; |
87 | - try { |
|
89 | + try |
|
90 | + { |
|
88 | 91 | $method = new \ReflectionMethod($controller, $action); |
89 | - } catch (\ReflectionException $e) { |
|
92 | + } |
|
93 | + catch (\ReflectionException $e) |
|
94 | + { |
|
90 | 95 | return null; |
91 | 96 | } |
92 | 97 | |
@@ -104,7 +109,8 @@ discard block |
||
104 | 109 | Guarded::class |
105 | 110 | ); |
106 | 111 | |
107 | - if ($action === null) { |
|
112 | + if ($action === null) |
|
113 | + { |
|
108 | 114 | return null; |
109 | 115 | } |
110 | 116 | |
@@ -126,7 +132,8 @@ discard block |
||
126 | 132 | ControllerException::FORBIDDEN |
127 | 133 | ]; |
128 | 134 | |
129 | - if ($guarded->permission === null && $ns === null) { |
|
135 | + if ($guarded->permission === null && $ns === null) |
|
136 | + { |
|
130 | 137 | throw new InterceptorException(sprintf( |
131 | 138 | 'Unable to apply @Guarded without name or @GuardNamespace on `%s`->`%s`', |
132 | 139 | $method->getDeclaringClass()->getName(), |
@@ -134,16 +141,19 @@ discard block |
||
134 | 141 | )); |
135 | 142 | } |
136 | 143 | |
137 | - if ($ns !== null) { |
|
144 | + if ($ns !== null) |
|
145 | + { |
|
138 | 146 | $permission[0] = sprintf('%s.%s', $ns->namespace, $permission[0]); |
139 | 147 | } |
140 | 148 | |
141 | - if ($this->namespace !== null) { |
|
149 | + if ($this->namespace !== null) |
|
150 | + { |
|
142 | 151 | // global namespace |
143 | 152 | $permission[0] = sprintf('%s.%s', $this->namespace, $permission[0]); |
144 | 153 | } |
145 | 154 | |
146 | - switch ($guarded->else) { |
|
155 | + switch ($guarded->else) |
|
156 | + { |
|
147 | 157 | case 'badAction': |
148 | 158 | $permission[1] = ControllerException::BAD_ACTION; |
149 | 159 | break; |