77use Exception ;
88use Flight ;
99use flight \Engine ;
10- use Wruczek \PhpFileCache \PhpFileCache ;
1110
12- class Permission {
11+ class Permission
12+ {
1313 /** @var array */
1414 protected $ rules = [];
1515
@@ -31,7 +31,8 @@ class Permission {
3131 * @param string $currentRole
3232 * @param Engine $f3
3333 */
34- public function __construct (string $ currentRole = '' , ?Engine $ app = null , $ Cache = null ) {
34+ public function __construct (string $ currentRole = '' , ?Engine $ app = null , $ Cache = null )
35+ {
3536 $ this ->currentRole = $ currentRole ;
3637 $ this ->app = $ app === null ? Flight::app () : $ app ;
3738 $ this ->Cache = $ Cache ;
@@ -43,7 +44,8 @@ public function __construct(string $currentRole = '', ?Engine $app = null, $Cach
4344 * @param string $currentRole the current role of the logged in user
4445 * @return void
4546 */
46- public function setCurrentRole (string $ currentRole ) {
47+ public function setCurrentRole (string $ currentRole )
48+ {
4749 $ this ->currentRole = $ currentRole ;
4850 }
4951
@@ -52,7 +54,8 @@ public function setCurrentRole(string $currentRole) {
5254 *
5355 * @return string
5456 */
55- public function getCurrentRole (): string {
57+ public function getCurrentRole (): string
58+ {
5659 return $ this ->currentRole ;
5760 }
5861
@@ -61,7 +64,8 @@ public function getCurrentRole(): string {
6164 *
6265 * @return array
6366 */
64- public function getRules (): array {
67+ public function getRules (): array
68+ {
6569 return $ this ->rules ;
6670 }
6771
@@ -82,7 +86,8 @@ public function getRules(): array {
8286 * @param bool $overwrite if true, will overwrite any existing rule with the same name
8387 * @return void
8488 */
85- public function defineRule (string $ rule , $ callableOrClassString , bool $ overwrite = false ) {
89+ public function defineRule (string $ rule , $ callableOrClassString , bool $ overwrite = false )
90+ {
8691 if ($ overwrite === false && isset ($ this ->rules [$ rule ]) === true ) {
8792 throw new \Exception ('Rule already defined: ' . $ rule );
8893 }
@@ -95,15 +100,16 @@ public function defineRule(string $rule, $callableOrClassString, bool $overwrite
95100 * @param string $className the name of the class to define rules from
96101 * @return void
97102 */
98- public function defineRulesFromClassMethods (string $ className , int $ ttl = 0 ): void {
103+ public function defineRulesFromClassMethods (string $ className , int $ ttl = 0 ): void
104+ {
99105
100106 $ useCache = false ;
101107 if ($ this ->Cache !== null && $ ttl > 0 ) {
102108 $ useCache = true ;
103109 $ Cache = $ this ->Cache ;
104110 $ cacheKey = 'flight_permissions_class_methods_ ' . $ className ;
105- if (is_a ($ Cache , PhpFileCache ::class) === true ) {
106- /** @var PhpFileCache $Cache */
111+ if (is_a ($ Cache , Cache ::class) === true ) {
112+ /** @var Cache $Cache */
107113 $ isCached = $ Cache ->isCached ($ cacheKey );
108114 if ($ isCached === true ) {
109115 $ this ->rules = $ Cache ->retrieve ($ cacheKey );
@@ -124,8 +130,8 @@ public function defineRulesFromClassMethods(string $className, int $ttl = 0): vo
124130 }
125131
126132 if ($ useCache === true ) {
127- if (is_a ($ Cache , PhpFileCache ::class) === true ) {
128- /** @var PhpFileCache $Cache */
133+ if (is_a ($ Cache , Cache ::class) === true ) {
134+ /** @var Cache $Cache */
129135 $ Cache ->store ($ cacheKey , $ classRules , $ ttl );
130136 }
131137 }
@@ -141,7 +147,8 @@ public function defineRulesFromClassMethods(string $className, int $ttl = 0): vo
141147 * @param mixed $additionalArgs any additional arguments to pass to the callback or method.
142148 * @return bool
143149 */
144- public function can (string $ permission , ...$ additionalArgs ): bool {
150+ public function can (string $ permission , ...$ additionalArgs ): bool
151+ {
145152 $ allowed = false ;
146153 $ action = '' ;
147154 if (strpos ($ permission , '. ' ) !== false ) {
@@ -187,7 +194,8 @@ public function can(string $permission, ...$additionalArgs): bool {
187194 * @param mixed $additionalArgs any additional arguments to pass to the callback or method.
188195 * @return boolean
189196 */
190- public function has (string $ permission , ...$ additionalArgs ): bool {
197+ public function has (string $ permission , ...$ additionalArgs ): bool
198+ {
191199 return $ this ->can ($ permission , ...$ additionalArgs );
192200 }
193201
@@ -197,7 +205,8 @@ public function has(string $permission, ...$additionalArgs): bool {
197205 * @param string $role [description]
198206 * @return boolean
199207 */
200- public function is (string $ role ): bool {
208+ public function is (string $ role ): bool
209+ {
201210 return $ this ->currentRole === $ role ;
202211 }
203212}
0 commit comments