@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | public function getPermission(string $controller, string $action): Permission |
46 | 46 | { |
47 | 47 | $key = sprintf('%s:%s', $controller, $action); |
48 | - if (!array_key_exists($key, $this->cache)) { |
|
48 | + if (!array_key_exists($key, $this->cache)){ |
|
49 | 49 | $this->cache[$key] = $this->generatePermission($controller, $action); |
50 | 50 | } |
51 | 51 | |
@@ -54,20 +54,20 @@ discard block |
||
54 | 54 | |
55 | 55 | private function generatePermission(string $controller, string $action): Permission |
56 | 56 | { |
57 | - try { |
|
57 | + try{ |
|
58 | 58 | $method = new \ReflectionMethod($controller, $action); |
59 | - } catch (\ReflectionException $e) { |
|
59 | + }catch (\ReflectionException $e){ |
|
60 | 60 | return Permission::failed(); |
61 | 61 | } |
62 | 62 | |
63 | 63 | $guarded = $this->reader->getMethodAnnotation($method, Guarded::class); |
64 | - if (!$guarded instanceof Guarded) { |
|
64 | + if (!$guarded instanceof Guarded){ |
|
65 | 65 | return Permission::failed(); |
66 | 66 | } |
67 | 67 | |
68 | 68 | $namespace = $this->reader->getClassAnnotation($method->getDeclaringClass(), GuardNamespace::class); |
69 | 69 | |
70 | - if ($guarded->permission || ($namespace instanceof GuardNamespace && $namespace->namespace)) { |
|
70 | + if ($guarded->permission || ($namespace instanceof GuardNamespace && $namespace->namespace)){ |
|
71 | 71 | return Permission::ok( |
72 | 72 | $this->makePermission($guarded, $method, $namespace), |
73 | 73 | $this->mapFailureException($guarded), |
@@ -90,11 +90,11 @@ discard block |
||
90 | 90 | private function makePermission(Guarded $guarded, \ReflectionMethod $method, ?GuardNamespace $ns): string |
91 | 91 | { |
92 | 92 | $permission = []; |
93 | - if ($this->namespace) { |
|
93 | + if ($this->namespace){ |
|
94 | 94 | $permission[] = $this->namespace; |
95 | 95 | } |
96 | 96 | |
97 | - if ($ns !== null && $ns->namespace) { |
|
97 | + if ($ns !== null && $ns->namespace){ |
|
98 | 98 | $permission[] = $ns->namespace; |
99 | 99 | } |
100 | 100 |
@@ -45,7 +45,8 @@ discard block |
||
45 | 45 | public function getPermission(string $controller, string $action): Permission |
46 | 46 | { |
47 | 47 | $key = sprintf('%s:%s', $controller, $action); |
48 | - if (!array_key_exists($key, $this->cache)) { |
|
48 | + if (!array_key_exists($key, $this->cache)) |
|
49 | + { |
|
49 | 50 | $this->cache[$key] = $this->generatePermission($controller, $action); |
50 | 51 | } |
51 | 52 | |
@@ -54,20 +55,25 @@ discard block |
||
54 | 55 | |
55 | 56 | private function generatePermission(string $controller, string $action): Permission |
56 | 57 | { |
57 | - try { |
|
58 | + try |
|
59 | + { |
|
58 | 60 | $method = new \ReflectionMethod($controller, $action); |
59 | - } catch (\ReflectionException $e) { |
|
61 | + } |
|
62 | + catch (\ReflectionException $e) |
|
63 | + { |
|
60 | 64 | return Permission::failed(); |
61 | 65 | } |
62 | 66 | |
63 | 67 | $guarded = $this->reader->getMethodAnnotation($method, Guarded::class); |
64 | - if (!$guarded instanceof Guarded) { |
|
68 | + if (!$guarded instanceof Guarded) |
|
69 | + { |
|
65 | 70 | return Permission::failed(); |
66 | 71 | } |
67 | 72 | |
68 | 73 | $namespace = $this->reader->getClassAnnotation($method->getDeclaringClass(), GuardNamespace::class); |
69 | 74 | |
70 | - if ($guarded->permission || ($namespace instanceof GuardNamespace && $namespace->namespace)) { |
|
75 | + if ($guarded->permission || ($namespace instanceof GuardNamespace && $namespace->namespace)) |
|
76 | + { |
|
71 | 77 | return Permission::ok( |
72 | 78 | $this->makePermission($guarded, $method, $namespace), |
73 | 79 | $this->mapFailureException($guarded), |
@@ -90,11 +96,13 @@ discard block |
||
90 | 96 | private function makePermission(Guarded $guarded, \ReflectionMethod $method, ?GuardNamespace $ns): string |
91 | 97 | { |
92 | 98 | $permission = []; |
93 | - if ($this->namespace) { |
|
99 | + if ($this->namespace) |
|
100 | + { |
|
94 | 101 | $permission[] = $this->namespace; |
95 | 102 | } |
96 | 103 | |
97 | - if ($ns !== null && $ns->namespace) { |
|
104 | + if ($ns !== null && $ns->namespace) |
|
105 | + { |
|
98 | 106 | $permission[] = $ns->namespace; |
99 | 107 | } |
100 | 108 |
@@ -41,7 +41,7 @@ |
||
41 | 41 | { |
42 | 42 | $permission = $this->permissions->getPermission($controller, $action); |
43 | 43 | |
44 | - if ($permission->ok && !$this->guard->allows($permission->permission, $parameters)) { |
|
44 | + if ($permission->ok && !$this->guard->allows($permission->permission, $parameters)){ |
|
45 | 45 | throw new ControllerException($permission->message, $permission->code); |
46 | 46 | } |
47 | 47 |
@@ -41,7 +41,8 @@ |
||
41 | 41 | { |
42 | 42 | $permission = $this->permissions->getPermission($controller, $action); |
43 | 43 | |
44 | - if ($permission->ok && !$this->guard->allows($permission->permission, $parameters)) { |
|
44 | + if ($permission->ok && !$this->guard->allows($permission->permission, $parameters)) |
|
45 | + { |
|
45 | 46 | throw new ControllerException($permission->message, $permission->code); |
46 | 47 | } |
47 | 48 |