@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | /** |
| 193 | 193 | * Add a new role object to the registry |
| 194 | 194 | * |
| 195 | - * @param string[] $role |
|
| 195 | + * @param string $role |
|
| 196 | 196 | * @return void |
| 197 | 197 | */ |
| 198 | 198 | public function addRole(string ...$role) |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | /** |
| 207 | 207 | * Add a new resource object to the registry |
| 208 | 208 | * |
| 209 | - * @param string[] $resource |
|
| 209 | + * @param string $resource |
|
| 210 | 210 | * @return void |
| 211 | 211 | */ |
| 212 | 212 | public function addResource(string ...$resource) |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | /** |
| 221 | 221 | * Add a new permission object to the registry |
| 222 | 222 | * |
| 223 | - * @param string[] $permission |
|
| 223 | + * @param string $permission |
|
| 224 | 224 | * @return void |
| 225 | 225 | */ |
| 226 | 226 | public function addPermission(string ...$permission) |
@@ -133,22 +133,22 @@ discard block |
||
| 133 | 133 | ); |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - $this->session["role"] = $role; |
|
| 137 | - |
|
| 138 | - return $this; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * Listen for and intercept undefined methods |
|
| 143 | - * |
|
| 144 | - * @param string $permission |
|
| 145 | - * @param string[] $args |
|
| 146 | - * @throws \Exception |
|
| 147 | - * @return boolean|null |
|
| 148 | - */ |
|
| 149 | - public function __call(string $permission, array $args) |
|
| 150 | - { |
|
| 151 | - if (!$this->permissionRegistry->exists($permission)) { |
|
| 136 | + $this->session["role"] = $role; |
|
| 137 | + |
|
| 138 | + return $this; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * Listen for and intercept undefined methods |
|
| 143 | + * |
|
| 144 | + * @param string $permission |
|
| 145 | + * @param string[] $args |
|
| 146 | + * @throws \Exception |
|
| 147 | + * @return boolean|null |
|
| 148 | + */ |
|
| 149 | + public function __call(string $permission, array $args) |
|
| 150 | + { |
|
| 151 | + if (!$this->permissionRegistry->exists($permission)) { |
|
| 152 | 152 | throw new \Exception( |
| 153 | 153 | sprintf( |
| 154 | 154 | "The permission: %s doesnt exist", |
@@ -166,123 +166,123 @@ discard block |
||
| 166 | 166 | ); |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - if ($this->session["query"]) |
|
| 170 | - { |
|
| 171 | - $result = $this->getPermissionStatus( |
|
| 169 | + if ($this->session["query"]) |
|
| 170 | + { |
|
| 171 | + $result = $this->getPermissionStatus( |
|
| 172 | 172 | $this->session["role"], |
| 173 | 173 | $permission, |
| 174 | 174 | $args[0] |
| 175 | 175 | ); |
| 176 | 176 | |
| 177 | - $this->initSession(); |
|
| 177 | + $this->initSession(); |
|
| 178 | 178 | |
| 179 | - return $result; |
|
| 180 | - } |
|
| 179 | + return $result; |
|
| 180 | + } |
|
| 181 | 181 | |
| 182 | - $this->allow( |
|
| 182 | + $this->allow( |
|
| 183 | 183 | $this->session["role"], |
| 184 | 184 | $permission, |
| 185 | 185 | $args[0], |
| 186 | 186 | (boolean)$this->session["status"] |
| 187 | 187 | ); |
| 188 | 188 | |
| 189 | - $this->initSession(); |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * Add a new role object to the registry |
|
| 194 | - * |
|
| 195 | - * @param string[] $role |
|
| 196 | - * @return void |
|
| 197 | - */ |
|
| 198 | - public function addRole(string ...$role) |
|
| 199 | - { |
|
| 200 | - foreach ($role as $_role) |
|
| 201 | - { |
|
| 202 | - $this->roleRegistry->save($_role); |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * Add a new resource object to the registry |
|
| 208 | - * |
|
| 209 | - * @param string[] $resource |
|
| 210 | - * @return void |
|
| 211 | - */ |
|
| 212 | - public function addResource(string ...$resource) |
|
| 213 | - { |
|
| 214 | - foreach ($resource as $_resource) |
|
| 215 | - { |
|
| 216 | - $this->resourceRegistry->save($_resource); |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - /** |
|
| 221 | - * Add a new permission object to the registry |
|
| 222 | - * |
|
| 223 | - * @param string[] $permission |
|
| 224 | - * @return void |
|
| 225 | - */ |
|
| 226 | - public function addPermission(string ...$permission) |
|
| 227 | - { |
|
| 228 | - foreach ($permission as $_permission) |
|
| 229 | - { |
|
| 230 | - $this->permissionRegistry->save($_permission); |
|
| 231 | - } |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - /** |
|
| 235 | - * Adds objects lazily. |
|
| 236 | - * |
|
| 237 | - * Automatically determine the type of an object and call the appropriate |
|
| 238 | - * add method on it. |
|
| 239 | - * |
|
| 240 | - * @param ObjectInterface[] $objects |
|
| 241 | - * @throws \Exception |
|
| 242 | - * @return void |
|
| 243 | - */ |
|
| 244 | - public function add(ObjectInterface ...$objects) |
|
| 245 | - { |
|
| 246 | - foreach ($objects as $object) |
|
| 247 | - { |
|
| 248 | - if ($object instanceof RoleInterface) |
|
| 249 | - { |
|
| 250 | - $this->addRole((string)$object); |
|
| 251 | - } |
|
| 252 | - else if ($object instanceof ResourceInterface) |
|
| 253 | - { |
|
| 254 | - $this->addResource((string)$object); |
|
| 255 | - } |
|
| 256 | - else if ($object instanceof PermissionInterface) |
|
| 257 | - { |
|
| 258 | - $this->addPermission((string)$object); |
|
| 259 | - } |
|
| 260 | - else { |
|
| 261 | - throw new \Exception( |
|
| 262 | - sprintf( |
|
| 263 | - "%s must implement one of RoleInterface, '. |
|
| 189 | + $this->initSession(); |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * Add a new role object to the registry |
|
| 194 | + * |
|
| 195 | + * @param string[] $role |
|
| 196 | + * @return void |
|
| 197 | + */ |
|
| 198 | + public function addRole(string ...$role) |
|
| 199 | + { |
|
| 200 | + foreach ($role as $_role) |
|
| 201 | + { |
|
| 202 | + $this->roleRegistry->save($_role); |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * Add a new resource object to the registry |
|
| 208 | + * |
|
| 209 | + * @param string[] $resource |
|
| 210 | + * @return void |
|
| 211 | + */ |
|
| 212 | + public function addResource(string ...$resource) |
|
| 213 | + { |
|
| 214 | + foreach ($resource as $_resource) |
|
| 215 | + { |
|
| 216 | + $this->resourceRegistry->save($_resource); |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * Add a new permission object to the registry |
|
| 222 | + * |
|
| 223 | + * @param string[] $permission |
|
| 224 | + * @return void |
|
| 225 | + */ |
|
| 226 | + public function addPermission(string ...$permission) |
|
| 227 | + { |
|
| 228 | + foreach ($permission as $_permission) |
|
| 229 | + { |
|
| 230 | + $this->permissionRegistry->save($_permission); |
|
| 231 | + } |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + /** |
|
| 235 | + * Adds objects lazily. |
|
| 236 | + * |
|
| 237 | + * Automatically determine the type of an object and call the appropriate |
|
| 238 | + * add method on it. |
|
| 239 | + * |
|
| 240 | + * @param ObjectInterface[] $objects |
|
| 241 | + * @throws \Exception |
|
| 242 | + * @return void |
|
| 243 | + */ |
|
| 244 | + public function add(ObjectInterface ...$objects) |
|
| 245 | + { |
|
| 246 | + foreach ($objects as $object) |
|
| 247 | + { |
|
| 248 | + if ($object instanceof RoleInterface) |
|
| 249 | + { |
|
| 250 | + $this->addRole((string)$object); |
|
| 251 | + } |
|
| 252 | + else if ($object instanceof ResourceInterface) |
|
| 253 | + { |
|
| 254 | + $this->addResource((string)$object); |
|
| 255 | + } |
|
| 256 | + else if ($object instanceof PermissionInterface) |
|
| 257 | + { |
|
| 258 | + $this->addPermission((string)$object); |
|
| 259 | + } |
|
| 260 | + else { |
|
| 261 | + throw new \Exception( |
|
| 262 | + sprintf( |
|
| 263 | + "%s must implement one of RoleInterface, '. |
|
| 264 | 264 | 'ResourceInterface and PermissionInterface", |
| 265 | - $object |
|
| 266 | - ) |
|
| 267 | - ); |
|
| 268 | - } |
|
| 269 | - } |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - /** |
|
| 273 | - * Change the status option of an assigned permission to true |
|
| 274 | - * |
|
| 275 | - * @param string $role; |
|
| 276 | - * @param string $permission |
|
| 277 | - * @param string $resource |
|
| 278 | - * @param boolean $status Optional |
|
| 279 | - * @throws \Exception |
|
| 280 | - * @return void |
|
| 281 | - */ |
|
| 282 | - public function allow(string $role, string $permission, string $resource, bool $status=null) |
|
| 283 | - { |
|
| 265 | + $object |
|
| 266 | + ) |
|
| 267 | + ); |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + /** |
|
| 273 | + * Change the status option of an assigned permission to true |
|
| 274 | + * |
|
| 275 | + * @param string $role; |
|
| 276 | + * @param string $permission |
|
| 277 | + * @param string $resource |
|
| 278 | + * @param boolean $status Optional |
|
| 279 | + * @throws \Exception |
|
| 280 | + * @return void |
|
| 281 | + */ |
|
| 282 | + public function allow(string $role, string $permission, string $resource, bool $status=null) |
|
| 283 | + { |
|
| 284 | 284 | $status = $status ?? true; |
| 285 | - if (!$this->roleRegistry->exists($role)) { |
|
| 285 | + if (!$this->roleRegistry->exists($role)) { |
|
| 286 | 286 | throw new \Exception( |
| 287 | 287 | sprintf( |
| 288 | 288 | "The role: %s doesnt exist", |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare(strict_types=1); |
|
| 1 | +<?php declare(strict_types = 1); |
|
| 2 | 2 | |
| 3 | 3 | /** |
| 4 | 4 | * This file is part of the Samshal\Acl library |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | * @throws \Exception |
| 280 | 280 | * @return void |
| 281 | 281 | */ |
| 282 | - public function allow(string $role, string $permission, string $resource, bool $status=null) |
|
| 282 | + public function allow(string $role, string $permission, string $resource, bool $status = null) |
|
| 283 | 283 | { |
| 284 | 284 | $status = $status ?? true; |
| 285 | 285 | if (!$this->roleRegistry->exists($role)) { |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | /** |
| 23 | 23 | * Adds a new role object to the registry |
| 24 | 24 | * |
| 25 | - * @param string $role |
|
| 25 | + * @param string[] $role |
|
| 26 | 26 | * @return void |
| 27 | 27 | */ |
| 28 | 28 | public function addRole(string ...$role); |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | /** |
| 31 | 31 | * Adds a new resource object to the registry |
| 32 | 32 | * |
| 33 | - * @param string $resource |
|
| 33 | + * @param string[] $resource |
|
| 34 | 34 | * @return void |
| 35 | 35 | */ |
| 36 | 36 | public function addResource(string ...$resource); |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | /** |
| 39 | 39 | * Adds a new permission object to the registry |
| 40 | 40 | * |
| 41 | - * @param string $permission |
|
| 41 | + * @param string[] $permission |
|
| 42 | 42 | * @return void |
| 43 | 43 | */ |
| 44 | 44 | public function addPermission(string ...$permission); |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | * Automatically determine the type of an object and call the appropriate |
| 50 | 50 | * add method on it. |
| 51 | 51 | * |
| 52 | - * @param ObjectInterface $object |
|
| 52 | + * @param ObjectInterface[] $object |
|
| 53 | 53 | * @throws \Exception |
| 54 | 54 | * @return void |
| 55 | 55 | */ |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare (strict_types=1); |
|
| 1 | +<?php declare (strict_types = 1); |
|
| 2 | 2 | |
| 3 | 3 | /** |
| 4 | 4 | * This file is part of the Samshal\Acl library |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | * @throws \Exception |
| 66 | 66 | * @return void |
| 67 | 67 | */ |
| 68 | - public function allow(string $role, string $permission, string $resource, bool $status=null); |
|
| 68 | + public function allow(string $role, string $permission, string $resource, bool $status = null); |
|
| 69 | 69 | |
| 70 | 70 | /** |
| 71 | 71 | * Change the status option of an assigned permission to false |