From 5e1c5ce10166721e5164253b01323884bf97eed5 Mon Sep 17 00:00:00 2001 From: Glenn Eggleton <geggleto@gmail.com> Date: Mon, 11 Jan 2016 10:18:01 -0500 Subject: [PATCH] Feature: Added isAllowedWithRoles to compliment checking more than one role at a time --- src/AclRepository.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/AclRepository.php b/src/AclRepository.php index 9714106..f83c314 100644 --- a/src/AclRepository.php +++ b/src/AclRepository.php @@ -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 @@ -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);