-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The role instance is in charge of checking the permission type. #11
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,6 @@ | |
|
||
namespace Rbac\Role; | ||
|
||
use InvalidArgumentException; | ||
use Rbac\Permission\PermissionInterface; | ||
|
||
/** | ||
|
@@ -24,7 +23,7 @@ class Role implements RoleInterface | |
protected $name; | ||
|
||
/** | ||
* @var string[] | ||
* @var string[]|PermissionInterface[] | ||
*/ | ||
protected $permissions = []; | ||
|
||
|
@@ -50,28 +49,20 @@ public function getName() | |
* Add a permission | ||
* | ||
* @param PermissionInterface|string $permission | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no doc to inherit There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can remove 1 space :D There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, please remove the space after @param. |
||
* @throws InvalidArgumentException | ||
*/ | ||
public function addPermission($permission) | ||
{ | ||
if (!is_string($permission)) { | ||
throw new InvalidArgumentException("Permission should be a string"); | ||
} | ||
$this->permissions[(string) $permission] = $permission; | ||
} | ||
|
||
/** | ||
* Checks if a permission exists for this role | ||
* | ||
* @param string $permission | ||
* @throws InvalidArgumentException | ||
* @param PermissionInterface|string $permission | ||
* @return bool | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doc not inherited because of the more strict params |
||
*/ | ||
public function hasPermission($permission) | ||
{ | ||
if (!is_string($permission)) { | ||
throw new InvalidArgumentException("Permission should be a string"); | ||
} | ||
return isset($this->permissions[(string) $permission]); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ class RecursiveRoleIterator extends ArrayIterator implements RecursiveIterator | |
/** | ||
* Override constructor to accept {@link Traversable} as well | ||
* | ||
* @param RoleInterface[]|Traversable | ||
* @param RoleInterface[]|Traversable $roles | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Name of param was lacking |
||
*/ | ||
public function __construct($roles) | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allow only strings array