| @@ 80-107 (lines=28) @@ | ||
| 77 | * |
|
| 78 | * @throws Exceptions\InvalidArgumentException |
|
| 79 | */ |
|
| 80 | private function checkUser($element) : bool |
|
| 81 | { |
|
| 82 | // Check if element has @Secured\User annotation |
|
| 83 | if ($element->hasAnnotation('Secured\User')) { |
|
| 84 | // Get user annotation |
|
| 85 | $user = $element->getAnnotation('Secured\User'); |
|
| 86 | ||
| 87 | // Annotation is single string |
|
| 88 | if (is_string($user) && in_array($user, ['loggedIn', 'guest'], TRUE)) { |
|
| 89 | // User have to be logged in and is not |
|
| 90 | if ($user === 'loggedIn' && $this->user->isLoggedIn() === FALSE) { |
|
| 91 | return FALSE; |
|
| 92 | ||
| 93 | // User have to be logged out and is logged in |
|
| 94 | } elseif ($user === 'guest' && $this->user->isLoggedIn() === TRUE) { |
|
| 95 | return FALSE; |
|
| 96 | } |
|
| 97 | ||
| 98 | // Annotation have wrong definition |
|
| 99 | } else { |
|
| 100 | throw new Exceptions\InvalidArgumentException('In @Security\User annotation is allowed only one from two strings: \'loggedIn\' & \'guest\''); |
|
| 101 | } |
|
| 102 | ||
| 103 | return TRUE; |
|
| 104 | } |
|
| 105 | ||
| 106 | return TRUE; |
|
| 107 | } |
|
| 108 | ||
| 109 | /** |
|
| 110 | * @param UI\ComponentReflection|UI\MethodReflection $element |
|
| @@ 78-105 (lines=28) @@ | ||
| 75 | * |
|
| 76 | * @throws Exceptions\InvalidArgumentException |
|
| 77 | */ |
|
| 78 | private function checkUser(Utils\ArrayHash $element) : bool |
|
| 79 | { |
|
| 80 | // Check if element has user parameter |
|
| 81 | if ($element->offsetExists('user')) { |
|
| 82 | // Get user parameter |
|
| 83 | $user = $element->offsetGet('user'); |
|
| 84 | ||
| 85 | // Parameter is single string |
|
| 86 | if (is_string($user) && in_array($user, ['loggedIn', 'guest'], TRUE)) { |
|
| 87 | // User have to be logged in and is not |
|
| 88 | if ($user === 'loggedIn' && $this->user->isLoggedIn() === FALSE) { |
|
| 89 | return FALSE; |
|
| 90 | ||
| 91 | // User have to be logged out and is logged in |
|
| 92 | } elseif ($user === 'guest' && $this->user->isLoggedIn() === TRUE) { |
|
| 93 | return FALSE; |
|
| 94 | } |
|
| 95 | ||
| 96 | // Parameter have multiple definitions |
|
| 97 | } else { |
|
| 98 | throw new Exceptions\InvalidArgumentException('In parameter \'user\' is allowed only one from two strings: \'loggedIn\' & \'guest\''); |
|
| 99 | } |
|
| 100 | ||
| 101 | return TRUE; |
|
| 102 | } |
|
| 103 | ||
| 104 | return TRUE; |
|
| 105 | } |
|
| 106 | ||
| 107 | /** |
|
| 108 | * @param Utils\ArrayHash $element |
|