-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
311 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,79 @@ | ||
<?php | ||
namespace AclMan\Assertion; | ||
|
||
use Zend\Permissions\Acl\Acl; | ||
use Zend\Permissions\Acl\Assertion\AssertionAggregate as BaseAssertionAggregate; | ||
use Zend\Permissions\Acl\Assertion\AssertionInterface; | ||
use Zend\Permissions\Acl\Exception\RuntimeException; | ||
use Zend\Permissions\Acl\Resource\ResourceInterface; | ||
use Zend\Permissions\Acl\Role\RoleInterface; | ||
|
||
/** | ||
* Created by PhpStorm. | ||
* User: visa | ||
* Date: 26/01/17 | ||
* Time: 12.22 | ||
* Class AssertionAggregate | ||
*/ | ||
class AssertionAggregate extends BaseAssertionAggregate | ||
{ | ||
public function assert(Acl $acl, RoleInterface $role = null, ResourceInterface $resource = null, $privilege = null) | ||
{ | ||
// check if assertions are set | ||
if (!$this->assertions) { | ||
throw new RuntimeException('No assertion have been aggregated to this AssertionAggregate'); | ||
} | ||
|
||
namespace AclMan\Assertion; | ||
foreach ($this->assertions as $key => $assertions) { | ||
switch (true) { | ||
case is_array($assertions): | ||
if (!$this->getAssertionManager()) { | ||
throw new RuntimeException('No assertion manager is set - cannot look up for assertions'); | ||
} | ||
|
||
$name = $assertions; | ||
$option = []; | ||
|
||
class AssertionAggregate | ||
{ | ||
if (!isset($assertions['name'])) { | ||
throw new RuntimeException('Name not set in the assertion'); | ||
} | ||
|
||
$name = $assertions['name']; | ||
unset($assertions['name']); | ||
$option = $assertions; | ||
|
||
$assertion = $this->getAssertionManager()->get($name, $option); | ||
break; | ||
case is_string($assertions) && class_exists($assertions): | ||
$assertion = new $assertions(); | ||
if (!($assertion instanceof AssertionInterface)) { | ||
throw new RuntimeException(sprintf('Instace of %s is not an instance of Zend\Permissions\Acl\Assertion\AssertionInterface', get_class($assertion))); | ||
} | ||
break; | ||
case is_string($assertions): | ||
if (!$this->getAssertionManager()) { | ||
throw new RuntimeException('No assertion manager is set - cannot look up for assertions'); | ||
} | ||
if ($this->getAssertionManager()->has($assertions)) { | ||
$assertion = $this->getAssertionManager()->get($assertions); | ||
} | ||
break; | ||
default: | ||
throw new RuntimeException('Invalid params in aggregate Assertion'); | ||
} | ||
$result = (bool)$assertion->assert($acl, $role, $resource, $privilege); | ||
if ($this->getMode() == self::MODE_ALL && !$result) { | ||
// on false is enough | ||
return false; | ||
} | ||
|
||
if ($this->getMode() == self::MODE_AT_LEAST_ONE && $result) { | ||
// one true is enough | ||
return true; | ||
} | ||
} | ||
|
||
if ($this->getMode() == self::MODE_ALL) { | ||
// none of the assertions returned false | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,22 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: visa | ||
* Date: 27/01/17 | ||
* Time: 17.19 | ||
*/ | ||
|
||
namespace AclMan\Assertion; | ||
|
||
use Zend\Permissions\Acl\Assertion\AssertionManager as BaseAssertionManager; | ||
|
||
class AssertionManager | ||
/** | ||
* Class AssertionManager | ||
*/ | ||
class AssertionManager extends BaseAssertionManager | ||
{ | ||
/** | ||
* zend-servicemanager v3 compatibility | ||
* @var bool | ||
*/ | ||
protected $shareByDefault = false; | ||
|
||
/** | ||
* zend-servicemanager v2 compatibility | ||
* @var bool | ||
*/ | ||
protected $sharedByDefault = false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.