Skip to content

Commit

Permalink
Feature: Added isAllowedWithRoles to compliment checking more than on…
Browse files Browse the repository at this point in the history
…e role at a time
  • Loading branch information
geggleto committed Jan 11, 2016
1 parent 18aa234 commit 5e1c5ce
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/AclRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,15 @@ public function isAllowed($role_id = '', $resource_id = '') {
return $this->acl->isAllowed($role_id, $resource_id);
}

public function isAllowedWithRoles($roles = [], $resource_id = '') {
foreach ($roles as $role) {
if ($this->isAllowed($role, $resource_id)) {
return true;
}
}
return false;
}

/**
* @param \Psr\Http\Message\ServerRequestInterface $requestInterface
* @param \Psr\Http\Message\ResponseInterface $responseInterface
Expand All @@ -181,11 +190,7 @@ public function __invoke(ServerRequestInterface $requestInterface, ResponseInter
$route = '/' . ltrim($requestInterface->getUri()->getPath(), '/');

try {
foreach ($this->role as $role) {
if ($this->isAllowed($role, $route)) {
$allowed = true;
}
}
$allowed = $this->isAllowedWithRoles($this->role, $route);
} catch (InvalidArgumentException $iae) {
$fn = $this->handler;
$allowed = $fn($requestInterface, $this);
Expand Down

0 comments on commit 5e1c5ce

Please sign in to comment.