Skip to content
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

Merged
merged 4 commits into from
Feb 6, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Accept mixed permissions
  • Loading branch information
jmleroux committed Jan 30, 2014
commit 8d5302439b500379815239416ef8a210047274ef
3 changes: 1 addition & 2 deletions src/Rbac/Rbac.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace Rbac;

use Rbac\Permission\PermissionInterface;
use Rbac\Role\RoleInterface;
use Rbac\Traversal\Strategy\TraversalStrategyInterface;
use Traversable;
Expand All @@ -36,7 +35,7 @@ public function __construct(TraversalStrategyInterface $strategy)
* Determines if access is granted by checking the roles for permission.
*
* @param RoleInterface|RoleInterface[]|Traversable $roles
* @param PermissionInterface $permission
* @param mixed $permission
* @return bool
*/
public function isGranted($roles, $permission)
Expand Down
13 changes: 2 additions & 11 deletions src/Rbac/Role/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace Rbac\Role;

use InvalidArgumentException;
use Rbac\Permission\PermissionInterface;

/**
Expand All @@ -24,7 +23,7 @@ class Role implements RoleInterface
protected $name;

/**
* @var string[]
* @var string[]|PermissionInterface[]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allow only strings array

*/
protected $permissions = [];

Expand All @@ -50,28 +49,20 @@ public function getName()
* Add a permission
*
* @param PermissionInterface|string $permission
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no doc to inherit

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove 1 space :D

Copy link
Member

Choose a reason for hiding this comment

The 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
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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]);
}
}
2 changes: 1 addition & 1 deletion src/Rbac/Role/RoleInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function getName();
/**
* Checks if a permission exists for this role (it does not check child roles)
*
* @param $permission
* @param mixed $permission
* @return bool
*/
public function hasPermission($permission);
Expand Down
2 changes: 1 addition & 1 deletion src/Rbac/Traversal/RecursiveRoleIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name of param was lacking

*/
public function __construct($roles)
{
Expand Down