@@ -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( |
| 131 | 138 | sprintf( |
| 132 | 139 | 'Unable to apply @Guarded without name or @GuardNamespace on `%s`->`%s`', |
@@ -136,16 +143,19 @@ discard block |
||
| 136 | 143 | ); |
| 137 | 144 | } |
| 138 | 145 | |
| 139 | - if ($ns !== null) { |
|
| 146 | + if ($ns !== null) |
|
| 147 | + { |
|
| 140 | 148 | $permission[0] = sprintf('%s.%s', $ns->namespace, $permission[0]); |
| 141 | 149 | } |
| 142 | 150 | |
| 143 | - if ($this->namespace !== null) { |
|
| 151 | + if ($this->namespace !== null) |
|
| 152 | + { |
|
| 144 | 153 | // global namespace |
| 145 | 154 | $permission[0] = sprintf('%s.%s', $this->namespace, $permission[0]); |
| 146 | 155 | } |
| 147 | 156 | |
| 148 | - switch ($guarded->else) { |
|
| 157 | + switch ($guarded->else) |
|
| 158 | + { |
|
| 149 | 159 | case 'unauthorized': |
| 150 | 160 | $permission[1] = ControllerException::UNAUTHORIZED; |
| 151 | 161 | break; |