@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | { |
| 48 | 48 | $permission = $this->getPermissions($controller, $action); |
| 49 | 49 | |
| 50 | - if ($permission !== null && !$this->guard->allows($permission[0], $parameters)) { |
|
| 50 | + if ($permission !== null && !$this->guard->allows($permission[0], $parameters)){ |
|
| 51 | 51 | throw new ControllerException( |
| 52 | 52 | sprintf( |
| 53 | 53 | 'Unauthorized permission `%s` for action `%s`->`%s`', |
@@ -74,14 +74,14 @@ discard block |
||
| 74 | 74 | private function getPermissions(string $controller, string $action): ?array |
| 75 | 75 | { |
| 76 | 76 | $key = sprintf('%s:%s', $controller, $action); |
| 77 | - if (array_key_exists($key, $this->cache)) { |
|
| 77 | + if (array_key_exists($key, $this->cache)){ |
|
| 78 | 78 | return $this->cache[$key]; |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | $this->cache[$key] = null; |
| 82 | - try { |
|
| 82 | + try{ |
|
| 83 | 83 | $method = new \ReflectionMethod($controller, $action); |
| 84 | - } catch (\ReflectionException $e) { |
|
| 84 | + }catch (\ReflectionException $e){ |
|
| 85 | 85 | return []; |
| 86 | 86 | } |
| 87 | 87 | |
@@ -99,11 +99,11 @@ discard block |
||
| 99 | 99 | Guarded::class |
| 100 | 100 | ); |
| 101 | 101 | |
| 102 | - if ($action === null) { |
|
| 102 | + if ($action === null){ |
|
| 103 | 103 | return null; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | - if ($action->permission === null && $namespace === null) { |
|
| 106 | + if ($action->permission === null && $namespace === null){ |
|
| 107 | 107 | throw new InterceptorException( |
| 108 | 108 | 'Unable to apply @Guarded annotation without specified permission name or @GuardNamespace' |
| 109 | 109 | ); |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | ControllerException::FORBIDDEN |
| 130 | 130 | ]; |
| 131 | 131 | |
| 132 | - if ($guarded->permission === null && $ns === null) { |
|
| 132 | + if ($guarded->permission === null && $ns === null){ |
|
| 133 | 133 | throw new InterceptorException(sprintf( |
| 134 | 134 | 'Unable to apply @Guarded without name or @GuardNamespace on `%s`->`%s`', |
| 135 | 135 | $method->getDeclaringClass()->getName(), |
@@ -137,11 +137,11 @@ discard block |
||
| 137 | 137 | )); |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - if ($ns !== null) { |
|
| 140 | + if ($ns !== null){ |
|
| 141 | 141 | $permission[0] = sprintf('%s.%s', $ns->namespace, $permission[0]); |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - switch ($guarded->else) { |
|
| 144 | + switch ($guarded->else){ |
|
| 145 | 145 | case 'badAction': |
| 146 | 146 | $permission[1] = ControllerException::BAD_ACTION; |
| 147 | 147 | break; |
@@ -47,7 +47,8 @@ discard block |
||
| 47 | 47 | { |
| 48 | 48 | $permission = $this->getPermissions($controller, $action); |
| 49 | 49 | |
| 50 | - if ($permission !== null && !$this->guard->allows($permission[0], $parameters)) { |
|
| 50 | + if ($permission !== null && !$this->guard->allows($permission[0], $parameters)) |
|
| 51 | + { |
|
| 51 | 52 | throw new ControllerException( |
| 52 | 53 | sprintf( |
| 53 | 54 | 'Unauthorized permission `%s` for action `%s`->`%s`', |
@@ -74,14 +75,18 @@ discard block |
||
| 74 | 75 | private function getPermissions(string $controller, string $action): ?array |
| 75 | 76 | { |
| 76 | 77 | $key = sprintf('%s:%s', $controller, $action); |
| 77 | - if (array_key_exists($key, $this->cache)) { |
|
| 78 | + if (array_key_exists($key, $this->cache)) |
|
| 79 | + { |
|
| 78 | 80 | return $this->cache[$key]; |
| 79 | 81 | } |
| 80 | 82 | |
| 81 | 83 | $this->cache[$key] = null; |
| 82 | - try { |
|
| 84 | + try |
|
| 85 | + { |
|
| 83 | 86 | $method = new \ReflectionMethod($controller, $action); |
| 84 | - } catch (\ReflectionException $e) { |
|
| 87 | + } |
|
| 88 | + catch (\ReflectionException $e) |
|
| 89 | + { |
|
| 85 | 90 | return []; |
| 86 | 91 | } |
| 87 | 92 | |
@@ -99,11 +104,13 @@ discard block |
||
| 99 | 104 | Guarded::class |
| 100 | 105 | ); |
| 101 | 106 | |
| 102 | - if ($action === null) { |
|
| 107 | + if ($action === null) |
|
| 108 | + { |
|
| 103 | 109 | return null; |
| 104 | 110 | } |
| 105 | 111 | |
| 106 | - if ($action->permission === null && $namespace === null) { |
|
| 112 | + if ($action->permission === null && $namespace === null) |
|
| 113 | + { |
|
| 107 | 114 | throw new InterceptorException( |
| 108 | 115 | 'Unable to apply @Guarded annotation without specified permission name or @GuardNamespace' |
| 109 | 116 | ); |
@@ -129,7 +136,8 @@ discard block |
||
| 129 | 136 | ControllerException::FORBIDDEN |
| 130 | 137 | ]; |
| 131 | 138 | |
| 132 | - if ($guarded->permission === null && $ns === null) { |
|
| 139 | + if ($guarded->permission === null && $ns === null) |
|
| 140 | + { |
|
| 133 | 141 | throw new InterceptorException(sprintf( |
| 134 | 142 | 'Unable to apply @Guarded without name or @GuardNamespace on `%s`->`%s`', |
| 135 | 143 | $method->getDeclaringClass()->getName(), |
@@ -137,11 +145,13 @@ discard block |
||
| 137 | 145 | )); |
| 138 | 146 | } |
| 139 | 147 | |
| 140 | - if ($ns !== null) { |
|
| 148 | + if ($ns !== null) |
|
| 149 | + { |
|
| 141 | 150 | $permission[0] = sprintf('%s.%s', $ns->namespace, $permission[0]); |
| 142 | 151 | } |
| 143 | 152 | |
| 144 | - switch ($guarded->else) { |
|
| 153 | + switch ($guarded->else) |
|
| 154 | + { |
|
| 145 | 155 | case 'badAction': |
| 146 | 156 | $permission[1] = ControllerException::BAD_ACTION; |
| 147 | 157 | break; |