@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | * @param string $permission |
| 147 | 147 | * @param string[] $args |
| 148 | 148 | * @throws \Exception |
| 149 | - * @return void |
|
| 149 | + * @return boolean|null |
|
| 150 | 150 | */ |
| 151 | 151 | public function __call(string $permission, array $args) |
| 152 | 152 | { |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | /** |
| 195 | 195 | * Add a new role object to the registry |
| 196 | 196 | * |
| 197 | - * @param string $role |
|
| 197 | + * @param string[] $role |
|
| 198 | 198 | * @return void |
| 199 | 199 | */ |
| 200 | 200 | public function addRole(string ...$role) |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | /** |
| 209 | 209 | * Add a new resource object to the registry |
| 210 | 210 | * |
| 211 | - * @param string $resource |
|
| 211 | + * @param string[] $resource |
|
| 212 | 212 | * @return void |
| 213 | 213 | */ |
| 214 | 214 | public function addResource(string ...$resource) |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | * Automatically determine the type of an object and call the appropriate |
| 240 | 240 | * add method on it. |
| 241 | 241 | * |
| 242 | - * @param ObjectInterface $object |
|
| 242 | + * @param ObjectInterface $objects |
|
| 243 | 243 | * @throws \Exception |
| 244 | 244 | * @return void |
| 245 | 245 | */ |
@@ -9,20 +9,20 @@ discard block |
||
| 9 | 9 | namespace Samshal\Acl; |
| 10 | 10 | |
| 11 | 11 | use Samshal\Acl\Role\{ |
| 12 | - DefaultRole as Role, |
|
| 13 | - RoleInterface |
|
| 12 | + DefaultRole as Role, |
|
| 13 | + RoleInterface |
|
| 14 | 14 | }; |
| 15 | 15 | use Samshal\Acl\Resource\{ |
| 16 | - DefaultResource as Resource, |
|
| 17 | - ResourceInterface |
|
| 16 | + DefaultResource as Resource, |
|
| 17 | + ResourceInterface |
|
| 18 | 18 | }; |
| 19 | 19 | use Samshal\Acl\Permission\{ |
| 20 | - DefaultPermission as Permission, |
|
| 21 | - PermissionInterface |
|
| 20 | + DefaultPermission as Permission, |
|
| 21 | + PermissionInterface |
|
| 22 | 22 | }; |
| 23 | 23 | use Samshal\Acl\Registry\{ |
| 24 | - GlobalRegistry, |
|
| 25 | - Registry |
|
| 24 | + GlobalRegistry, |
|
| 25 | + Registry |
|
| 26 | 26 | }; |
| 27 | 27 | |
| 28 | 28 | |
@@ -35,98 +35,98 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | class Acl implements AclInterface |
| 37 | 37 | { |
| 38 | - /** |
|
| 39 | - * @var RegistryInterface $roleRegistry |
|
| 40 | - */ |
|
| 41 | - public $roleRegistry; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @var RegistryInterface $resourceRegistry |
|
| 45 | - */ |
|
| 46 | - protected $resourceRegistry; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @var RegistryInterface $permissionRegistry |
|
| 50 | - */ |
|
| 51 | - protected $permissionRegistry; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @var RegistryInterface $globalRegistry |
|
| 55 | - */ |
|
| 56 | - public $globalRegistry; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @var string[] $sesion |
|
| 60 | - */ |
|
| 61 | - protected $session = []; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * @var string SYN_ALLOW |
|
| 65 | - */ |
|
| 66 | - const SYN_ALLOW = "can"; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @var string SYN_DENY |
|
| 70 | - */ |
|
| 71 | - const SYN_DENY = "cannot"; |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * Performs bootstrapping |
|
| 75 | - */ |
|
| 76 | - public function __construct() |
|
| 77 | - { |
|
| 78 | - self::initRegistries(); |
|
| 79 | - self::initSession(); |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Initalizes the registries |
|
| 84 | - * |
|
| 85 | - * @return void |
|
| 86 | - */ |
|
| 87 | - protected function initRegistries() |
|
| 88 | - { |
|
| 89 | - $this->roleRegistry = new Registry(); |
|
| 90 | - $this->resourceRegistry = new Registry(); |
|
| 91 | - $this->permissionRegistry = new Registry(); |
|
| 92 | - $this->globalRegistry = new GlobalRegistry(); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Initializes the global session array and sets them to the default value |
|
| 97 | - * |
|
| 98 | - * @return void |
|
| 99 | - */ |
|
| 100 | - protected function initSession() |
|
| 101 | - { |
|
| 102 | - $this->session["query"] = true; |
|
| 103 | - unset($this->session["role"], $this->session["status"]); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Listen for and intercept properties that're not set |
|
| 108 | - * |
|
| 109 | - * @param string $role; |
|
| 110 | - * @throws \Exception |
|
| 111 | - * @return AclInterface |
|
| 112 | - */ |
|
| 113 | - public function __get(string $role) : AclInterface |
|
| 114 | - { |
|
| 115 | - if ($role === self::SYN_ALLOW || $role === self::SYN_DENY) |
|
| 116 | - { |
|
| 117 | - $this->session["status"] = ($role === self::SYN_ALLOW) |
|
| 38 | + /** |
|
| 39 | + * @var RegistryInterface $roleRegistry |
|
| 40 | + */ |
|
| 41 | + public $roleRegistry; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @var RegistryInterface $resourceRegistry |
|
| 45 | + */ |
|
| 46 | + protected $resourceRegistry; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @var RegistryInterface $permissionRegistry |
|
| 50 | + */ |
|
| 51 | + protected $permissionRegistry; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @var RegistryInterface $globalRegistry |
|
| 55 | + */ |
|
| 56 | + public $globalRegistry; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @var string[] $sesion |
|
| 60 | + */ |
|
| 61 | + protected $session = []; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * @var string SYN_ALLOW |
|
| 65 | + */ |
|
| 66 | + const SYN_ALLOW = "can"; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @var string SYN_DENY |
|
| 70 | + */ |
|
| 71 | + const SYN_DENY = "cannot"; |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * Performs bootstrapping |
|
| 75 | + */ |
|
| 76 | + public function __construct() |
|
| 77 | + { |
|
| 78 | + self::initRegistries(); |
|
| 79 | + self::initSession(); |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Initalizes the registries |
|
| 84 | + * |
|
| 85 | + * @return void |
|
| 86 | + */ |
|
| 87 | + protected function initRegistries() |
|
| 88 | + { |
|
| 89 | + $this->roleRegistry = new Registry(); |
|
| 90 | + $this->resourceRegistry = new Registry(); |
|
| 91 | + $this->permissionRegistry = new Registry(); |
|
| 92 | + $this->globalRegistry = new GlobalRegistry(); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Initializes the global session array and sets them to the default value |
|
| 97 | + * |
|
| 98 | + * @return void |
|
| 99 | + */ |
|
| 100 | + protected function initSession() |
|
| 101 | + { |
|
| 102 | + $this->session["query"] = true; |
|
| 103 | + unset($this->session["role"], $this->session["status"]); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Listen for and intercept properties that're not set |
|
| 108 | + * |
|
| 109 | + * @param string $role; |
|
| 110 | + * @throws \Exception |
|
| 111 | + * @return AclInterface |
|
| 112 | + */ |
|
| 113 | + public function __get(string $role) : AclInterface |
|
| 114 | + { |
|
| 115 | + if ($role === self::SYN_ALLOW || $role === self::SYN_DENY) |
|
| 116 | + { |
|
| 117 | + $this->session["status"] = ($role === self::SYN_ALLOW) |
|
| 118 | 118 | ? true : false # <- obsolete, conditions do escalate to a boolean |
| 119 | 119 | ; |
| 120 | 120 | |
| 121 | - if (!empty($this->session["role"])) |
|
| 122 | - { |
|
| 123 | - $this->session["query"] = false; |
|
| 124 | - } |
|
| 121 | + if (!empty($this->session["role"])) |
|
| 122 | + { |
|
| 123 | + $this->session["query"] = false; |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | - return $this; |
|
| 127 | - } |
|
| 126 | + return $this; |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - if (!$this->roleRegistry->exists($role)) { |
|
| 129 | + if (!$this->roleRegistry->exists($role)) { |
|
| 130 | 130 | throw new \Exception( |
| 131 | 131 | sprintf( |
| 132 | 132 | "The role: %s doesnt exist", |
@@ -135,22 +135,22 @@ discard block |
||
| 135 | 135 | ); |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | - $this->session["role"] = $role; |
|
| 139 | - |
|
| 140 | - return $this; |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * Listen for and intercept undefined methods |
|
| 145 | - * |
|
| 146 | - * @param string $permission |
|
| 147 | - * @param string[] $args |
|
| 148 | - * @throws \Exception |
|
| 149 | - * @return void |
|
| 150 | - */ |
|
| 151 | - public function __call(string $permission, array $args) |
|
| 152 | - { |
|
| 153 | - if (!$this->permissionRegistry->exists($permission)) { |
|
| 138 | + $this->session["role"] = $role; |
|
| 139 | + |
|
| 140 | + return $this; |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * Listen for and intercept undefined methods |
|
| 145 | + * |
|
| 146 | + * @param string $permission |
|
| 147 | + * @param string[] $args |
|
| 148 | + * @throws \Exception |
|
| 149 | + * @return void |
|
| 150 | + */ |
|
| 151 | + public function __call(string $permission, array $args) |
|
| 152 | + { |
|
| 153 | + if (!$this->permissionRegistry->exists($permission)) { |
|
| 154 | 154 | throw new \Exception( |
| 155 | 155 | sprintf( |
| 156 | 156 | "The permission: %s doesnt exist", |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | ); |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | - if (!$this->resourceRegistry->exists($args[0])) { |
|
| 162 | + if (!$this->resourceRegistry->exists($args[0])) { |
|
| 163 | 163 | throw new \Exception( |
| 164 | 164 | sprintf( |
| 165 | 165 | "The resource: %s doesnt exist", |
@@ -168,122 +168,122 @@ discard block |
||
| 168 | 168 | ); |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | - if ($this->session["query"]) |
|
| 172 | - { |
|
| 173 | - $result = $this->getPermissionStatus( |
|
| 171 | + if ($this->session["query"]) |
|
| 172 | + { |
|
| 173 | + $result = $this->getPermissionStatus( |
|
| 174 | 174 | $this->session["role"], |
| 175 | 175 | $permission, |
| 176 | 176 | $args[0] |
| 177 | 177 | ); |
| 178 | 178 | |
| 179 | - $this->initSession(); |
|
| 179 | + $this->initSession(); |
|
| 180 | 180 | |
| 181 | - return $result; |
|
| 182 | - } |
|
| 181 | + return $result; |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | - $this->allow( |
|
| 184 | + $this->allow( |
|
| 185 | 185 | $this->session["role"], |
| 186 | 186 | $permission, |
| 187 | 187 | $args[0], |
| 188 | 188 | $this->session["status"] |
| 189 | 189 | ); |
| 190 | 190 | |
| 191 | - $this->initSession(); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * Add a new role object to the registry |
|
| 196 | - * |
|
| 197 | - * @param string $role |
|
| 198 | - * @return void |
|
| 199 | - */ |
|
| 200 | - public function addRole(string ...$role) |
|
| 201 | - { |
|
| 202 | - foreach ($role as $_role) |
|
| 203 | - { |
|
| 204 | - $this->roleRegistry->save($_role); |
|
| 205 | - } |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * Add a new resource object to the registry |
|
| 210 | - * |
|
| 211 | - * @param string $resource |
|
| 212 | - * @return void |
|
| 213 | - */ |
|
| 214 | - public function addResource(string ...$resource) |
|
| 215 | - { |
|
| 216 | - foreach ($resource as $_resource) |
|
| 217 | - { |
|
| 218 | - $this->resourceRegistry->save($resource); |
|
| 219 | - } |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - /** |
|
| 223 | - * Add a new permission object to the registry |
|
| 224 | - * |
|
| 225 | - * @param PermissionInterface $permission |
|
| 226 | - * @return void |
|
| 227 | - */ |
|
| 228 | - public function addPermission(string $permission) |
|
| 229 | - { |
|
| 230 | - foreach ($permission as $_permission) |
|
| 231 | - { |
|
| 232 | - $this->permissionRegistry->save($_permission); |
|
| 233 | - } |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - /** |
|
| 237 | - * Adds objects lazily. |
|
| 238 | - * |
|
| 239 | - * Automatically determine the type of an object and call the appropriate |
|
| 240 | - * add method on it. |
|
| 241 | - * |
|
| 242 | - * @param ObjectInterface $object |
|
| 243 | - * @throws \Exception |
|
| 244 | - * @return void |
|
| 245 | - */ |
|
| 246 | - public function add(ObjectInterface ...$objects) |
|
| 247 | - { |
|
| 248 | - foreach ($objects as $object) |
|
| 249 | - { |
|
| 250 | - if ($object instanceof RoleInterface) |
|
| 251 | - { |
|
| 252 | - $this->addRole((string)$object); |
|
| 253 | - } |
|
| 254 | - else if ($object instanceof ResourceInterface) |
|
| 255 | - { |
|
| 256 | - $this->addResource((string)$object); |
|
| 257 | - } |
|
| 258 | - else if ($object instanceof PermissionInterface) |
|
| 259 | - { |
|
| 260 | - $this->addPermission((string)$object); |
|
| 261 | - } |
|
| 262 | - else { |
|
| 263 | - throw new \Exception( |
|
| 264 | - sprintf( |
|
| 265 | - "%s must implement one of RoleInterface, '. |
|
| 191 | + $this->initSession(); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * Add a new role object to the registry |
|
| 196 | + * |
|
| 197 | + * @param string $role |
|
| 198 | + * @return void |
|
| 199 | + */ |
|
| 200 | + public function addRole(string ...$role) |
|
| 201 | + { |
|
| 202 | + foreach ($role as $_role) |
|
| 203 | + { |
|
| 204 | + $this->roleRegistry->save($_role); |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * Add a new resource object to the registry |
|
| 210 | + * |
|
| 211 | + * @param string $resource |
|
| 212 | + * @return void |
|
| 213 | + */ |
|
| 214 | + public function addResource(string ...$resource) |
|
| 215 | + { |
|
| 216 | + foreach ($resource as $_resource) |
|
| 217 | + { |
|
| 218 | + $this->resourceRegistry->save($resource); |
|
| 219 | + } |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + /** |
|
| 223 | + * Add a new permission object to the registry |
|
| 224 | + * |
|
| 225 | + * @param PermissionInterface $permission |
|
| 226 | + * @return void |
|
| 227 | + */ |
|
| 228 | + public function addPermission(string $permission) |
|
| 229 | + { |
|
| 230 | + foreach ($permission as $_permission) |
|
| 231 | + { |
|
| 232 | + $this->permissionRegistry->save($_permission); |
|
| 233 | + } |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + /** |
|
| 237 | + * Adds objects lazily. |
|
| 238 | + * |
|
| 239 | + * Automatically determine the type of an object and call the appropriate |
|
| 240 | + * add method on it. |
|
| 241 | + * |
|
| 242 | + * @param ObjectInterface $object |
|
| 243 | + * @throws \Exception |
|
| 244 | + * @return void |
|
| 245 | + */ |
|
| 246 | + public function add(ObjectInterface ...$objects) |
|
| 247 | + { |
|
| 248 | + foreach ($objects as $object) |
|
| 249 | + { |
|
| 250 | + if ($object instanceof RoleInterface) |
|
| 251 | + { |
|
| 252 | + $this->addRole((string)$object); |
|
| 253 | + } |
|
| 254 | + else if ($object instanceof ResourceInterface) |
|
| 255 | + { |
|
| 256 | + $this->addResource((string)$object); |
|
| 257 | + } |
|
| 258 | + else if ($object instanceof PermissionInterface) |
|
| 259 | + { |
|
| 260 | + $this->addPermission((string)$object); |
|
| 261 | + } |
|
| 262 | + else { |
|
| 263 | + throw new \Exception( |
|
| 264 | + sprintf( |
|
| 265 | + "%s must implement one of RoleInterface, '. |
|
| 266 | 266 | 'ResourceInterface and PermissionInterface", |
| 267 | - $object |
|
| 268 | - ) |
|
| 269 | - ); |
|
| 270 | - } |
|
| 271 | - } |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - /** |
|
| 275 | - * Change the status option of an assigned permission to true |
|
| 276 | - * |
|
| 277 | - * @param string $role; |
|
| 278 | - * @param string $permission |
|
| 279 | - * @param string $resource |
|
| 280 | - * @param boolean $status Optional |
|
| 281 | - * @throws \Exception |
|
| 282 | - * @return void |
|
| 283 | - */ |
|
| 284 | - public function allow(string $role, string $permission, string $resource, bool $status=true) |
|
| 285 | - { |
|
| 286 | - if (!$this->roleRegistry->exists($role)) { |
|
| 267 | + $object |
|
| 268 | + ) |
|
| 269 | + ); |
|
| 270 | + } |
|
| 271 | + } |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + /** |
|
| 275 | + * Change the status option of an assigned permission to true |
|
| 276 | + * |
|
| 277 | + * @param string $role; |
|
| 278 | + * @param string $permission |
|
| 279 | + * @param string $resource |
|
| 280 | + * @param boolean $status Optional |
|
| 281 | + * @throws \Exception |
|
| 282 | + * @return void |
|
| 283 | + */ |
|
| 284 | + public function allow(string $role, string $permission, string $resource, bool $status=true) |
|
| 285 | + { |
|
| 286 | + if (!$this->roleRegistry->exists($role)) { |
|
| 287 | 287 | throw new \Exception( |
| 288 | 288 | sprintf( |
| 289 | 289 | "The role: %s doesnt exist", |
@@ -292,7 +292,7 @@ discard block |
||
| 292 | 292 | ); |
| 293 | 293 | } |
| 294 | 294 | |
| 295 | - if (!$this->permissionRegistry->exists($permission)) { |
|
| 295 | + if (!$this->permissionRegistry->exists($permission)) { |
|
| 296 | 296 | throw new \Exception( |
| 297 | 297 | sprintf( |
| 298 | 298 | "The permission: %s doesnt exist", |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | ); |
| 302 | 302 | } |
| 303 | 303 | |
| 304 | - if (!$this->resourceRegistry->exists($resource)) { |
|
| 304 | + if (!$this->resourceRegistry->exists($resource)) { |
|
| 305 | 305 | throw new \Exception( |
| 306 | 306 | sprintf( |
| 307 | 307 | "The resource: %s doesnt exist", |
@@ -310,33 +310,33 @@ discard block |
||
| 310 | 310 | ); |
| 311 | 311 | } |
| 312 | 312 | |
| 313 | - $this->globalRegistry->save($role, $resource, $permission, $status); |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - /** |
|
| 317 | - * Change the status option of an assigned permission to false |
|
| 318 | - * |
|
| 319 | - * @param string $role; |
|
| 320 | - * @param string $permission |
|
| 321 | - * @param string $resource |
|
| 322 | - * @return void |
|
| 323 | - */ |
|
| 324 | - public function deny(string $role, string $permission, string $resource) |
|
| 325 | - { |
|
| 326 | - $this->allow($role, $permission, $resource, false); |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - /** |
|
| 330 | - * Retrieve the status of a permission assigned to a role |
|
| 331 | - * |
|
| 332 | - * @param string $role; |
|
| 333 | - * @param string $permission |
|
| 334 | - * @param string $resource |
|
| 335 | - * @return boolean |
|
| 336 | - */ |
|
| 337 | - public function getPermissionStatus(string $role, string $permission, string $resource) : bool |
|
| 338 | - { |
|
| 339 | - if (!$this->roleRegistry->exists($role)) { |
|
| 313 | + $this->globalRegistry->save($role, $resource, $permission, $status); |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + /** |
|
| 317 | + * Change the status option of an assigned permission to false |
|
| 318 | + * |
|
| 319 | + * @param string $role; |
|
| 320 | + * @param string $permission |
|
| 321 | + * @param string $resource |
|
| 322 | + * @return void |
|
| 323 | + */ |
|
| 324 | + public function deny(string $role, string $permission, string $resource) |
|
| 325 | + { |
|
| 326 | + $this->allow($role, $permission, $resource, false); |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + /** |
|
| 330 | + * Retrieve the status of a permission assigned to a role |
|
| 331 | + * |
|
| 332 | + * @param string $role; |
|
| 333 | + * @param string $permission |
|
| 334 | + * @param string $resource |
|
| 335 | + * @return boolean |
|
| 336 | + */ |
|
| 337 | + public function getPermissionStatus(string $role, string $permission, string $resource) : bool |
|
| 338 | + { |
|
| 339 | + if (!$this->roleRegistry->exists($role)) { |
|
| 340 | 340 | throw new \Exception( |
| 341 | 341 | sprintf( |
| 342 | 342 | "The role: %s doesnt exist", |
@@ -345,7 +345,7 @@ discard block |
||
| 345 | 345 | ); |
| 346 | 346 | } |
| 347 | 347 | |
| 348 | - if (!$this->permissionRegistry->exists($permission)) { |
|
| 348 | + if (!$this->permissionRegistry->exists($permission)) { |
|
| 349 | 349 | throw new \Exception( |
| 350 | 350 | sprintf( |
| 351 | 351 | "The permission: %s doesnt exist", |
@@ -354,7 +354,7 @@ discard block |
||
| 354 | 354 | ); |
| 355 | 355 | } |
| 356 | 356 | |
| 357 | - if (!$this->resourceRegistry->exists($resource)) { |
|
| 357 | + if (!$this->resourceRegistry->exists($resource)) { |
|
| 358 | 358 | throw new \Exception( |
| 359 | 359 | sprintf( |
| 360 | 360 | "The resource: %s doesnt exist", |
@@ -364,8 +364,8 @@ discard block |
||
| 364 | 364 | } |
| 365 | 365 | |
| 366 | 366 | |
| 367 | - $role = $this->globalRegistry->get($role); |
|
| 367 | + $role = $this->globalRegistry->get($role); |
|
| 368 | 368 | |
| 369 | - return $role[$resource][$permission]["status"]; |
|
| 370 | - } |
|
| 369 | + return $role[$resource][$permission]["status"]; |
|
| 370 | + } |
|
| 371 | 371 | } |
@@ -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 |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | * @throws \Exception |
| 282 | 282 | * @return void |
| 283 | 283 | */ |
| 284 | - public function allow(string $role, string $permission, string $resource, bool $status=true) |
|
| 284 | + public function allow(string $role, string $permission, string $resource, bool $status = true) |
|
| 285 | 285 | { |
| 286 | 286 | if (!$this->roleRegistry->exists($role)) { |
| 287 | 287 | throw new \Exception( |
@@ -250,16 +250,13 @@ |
||
| 250 | 250 | if ($object instanceof RoleInterface) |
| 251 | 251 | { |
| 252 | 252 | $this->addRole((string)$object); |
| 253 | - } |
|
| 254 | - else if ($object instanceof ResourceInterface) |
|
| 253 | + } else if ($object instanceof ResourceInterface) |
|
| 255 | 254 | { |
| 256 | 255 | $this->addResource((string)$object); |
| 257 | - } |
|
| 258 | - else if ($object instanceof PermissionInterface) |
|
| 256 | + } else if ($object instanceof PermissionInterface) |
|
| 259 | 257 | { |
| 260 | 258 | $this->addPermission((string)$object); |
| 261 | - } |
|
| 262 | - else { |
|
| 259 | + } else { |
|
| 263 | 260 | throw new \Exception( |
| 264 | 261 | sprintf( |
| 265 | 262 | "%s must implement one of RoleInterface, '. |
@@ -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=true); |
|
| 68 | + public function allow(string $role, string $permission, string $resource, bool $status = true); |
|
| 69 | 69 | |
| 70 | 70 | /** |
| 71 | 71 | * Change the status option of an assigned permission to false |
@@ -1,4 +1,4 @@ |
||
| 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 |
@@ -1,4 +1,4 @@ |
||
| 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 |
@@ -1,4 +1,4 @@ |
||
| 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 |
@@ -1,4 +1,4 @@ |
||
| 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 |
@@ -1,4 +1,4 @@ |
||
| 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 |
@@ -1,4 +1,4 @@ |
||
| 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 |
@@ -1,4 +1,4 @@ |
||
| 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 |