This repository has been archived by the owner on Jan 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/5628' into develop
- Loading branch information
108 parents
fd14bf6
+
4425956
+
598e6a5
+
6e40a22
+
90bd82f
+
61e86cc
+
2755e28
+
666e28e
+
7c5abb8
+
d753388
+
e33d218
+
b0d3cc2
+
05539b9
+
56091aa
+
c47d6e1
+
dcee015
+
6c132b6
+
7065efb
+
e63c913
+
b34a30f
+
f6898d8
+
9d8ce42
+
e8926e5
+
5f59463
+
30b6149
+
843dd21
+
6d04042
+
98ed105
+
ea632d6
+
c2c0c90
+
4d8678c
+
b5fe867
+
dd6dd90
+
fe69d86
+
7e4c1bb
+
c718944
+
032f2c6
+
e587c4a
+
afb2df9
+
4ea8d76
+
9dfff7d
+
c88317e
+
2be5985
+
9490459
+
8e68e61
+
b111673
+
18367f4
+
f312673
+
d7f78c7
+
82f434d
+
9355d07
+
9cc8996
+
202d5af
+
4dff9cb
+
8834dfc
+
81b48da
+
480b4d7
+
df42df9
+
3ee9c5e
+
b7556e5
+
4c81c23
+
9c8309f
+
35ab5f0
+
85e1f91
+
3cb23c1
+
16f6088
+
d32c68c
+
df5b9c3
+
1936d7e
+
c478319
+
9fafd09
+
e102ab1
+
a90bdee
+
2f9fa9f
+
aad5075
+
4127f0d
+
eda7358
+
25538ec
+
ff2c116
+
ee7f5d8
+
60fd2f8
+
33976d4
+
446a94e
+
fbb88bb
+
78a9131
+
d4d4e35
+
444b3aa
+
51abe83
+
af16339
+
d531e0a
+
46c7d78
+
25d96a9
+
71d7e50
+
03600cd
+
f2f56b8
+
d78b598
+
a6922a1
+
40b06f5
+
7d1ac75
+
f0465d5
+
3f7be91
+
0512c9a
+
e7b8a17
+
c93e356
+
512b56d
+
fb112da
+
625742d
+
04a79fa
commit a30a4f1
Showing
5 changed files
with
592 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
namespace Zend\Permissions\Acl\Assertion; | ||
|
||
use Zend\Permissions\Acl\Acl; | ||
use Zend\Permissions\Acl\Role\RoleInterface; | ||
use Zend\Permissions\Acl\Resource\ResourceInterface; | ||
use Zend\Permissions\Acl\Exception\InvalidArgumentException; | ||
use Zend\Permissions\Acl\Exception\RuntimeException; | ||
|
||
class AssertionAggregate implements AssertionInterface | ||
{ | ||
|
||
const MODE_ALL = 'all'; | ||
|
||
const MODE_AT_LEAST_ONE = 'at_least_one'; | ||
|
||
protected $assertions = array(); | ||
|
||
/** | ||
* | ||
* @var $manager AssertionManager | ||
*/ | ||
protected $assertionManager; | ||
|
||
protected $mode = self::MODE_ALL; | ||
|
||
/** | ||
* Stacks an assertion in aggregate | ||
* | ||
* @param AssertionInterface|string $assertion | ||
* if string, must match a AssertionManager declared service (checked later) | ||
* | ||
* @return self | ||
*/ | ||
public function addAssertion($assertion) | ||
{ | ||
$this->assertions[] = $assertion; | ||
|
||
return $this; | ||
} | ||
|
||
public function addAssertions(array $assertions) | ||
{ | ||
foreach ($assertions as $assertion) { | ||
$this->addAssertion($assertion); | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Empties assertions stack | ||
* | ||
* @return self | ||
*/ | ||
public function clearAssertions() | ||
{ | ||
$this->assertions = array(); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* | ||
* @param AssertionManager $manager | ||
* | ||
* @return self | ||
*/ | ||
public function setAssertionManager(AssertionManager $manager) | ||
{ | ||
$this->assertionManager = $manager; | ||
|
||
return $this; | ||
} | ||
|
||
public function getAssertionManager() | ||
{ | ||
return $this->assertionManager; | ||
} | ||
|
||
/** | ||
* Set assertion chain behavior | ||
* | ||
* AssertionAggregate should assert to true when: | ||
* | ||
* - all assertions are true with MODE_ALL | ||
* - at least one assertion is true with MODE_AT_LEAST_ONE | ||
* | ||
* @param string $mode | ||
* indicates how assertion chain result should interpreted (either 'all' or 'at_least_one') | ||
* @throws Exception | ||
* | ||
* @return self | ||
*/ | ||
public function setMode($mode) | ||
{ | ||
if ($mode != self::MODE_ALL && $mode != self::MODE_AT_LEAST_ONE) { | ||
throw new InvalidArgumentException('invalid assertion aggregate mode'); | ||
} | ||
|
||
$this->mode = $mode; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Return current mode | ||
* | ||
* @return string | ||
*/ | ||
public function getMode() | ||
{ | ||
return $this->mode; | ||
} | ||
|
||
/** | ||
* @see \Zend\Permissions\Acl\Assertion\AssertionInterface::assert() | ||
* | ||
* @throws RuntimeException | ||
* @return bool | ||
*/ | ||
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'); | ||
} | ||
|
||
foreach ($this->assertions as $assertion) { | ||
|
||
// jit assertion mloading | ||
if (! $assertion instanceof AssertionInterface) { | ||
if (class_exists($assertion)) { | ||
$assertion = new $assertion(); | ||
} else { | ||
if ($manager = $this->getAssertionManager()) { | ||
try { | ||
$assertion = $manager->get($assertion); | ||
} catch (\Exception $e) { | ||
throw new Exception\InvalidAssertionException('assertion "' . $assertion . '" is not defined in assertion manager'); | ||
} | ||
} else { | ||
throw new RuntimeException('no assertion manager is set - cannot look up for assertions'); | ||
} | ||
} | ||
} | ||
|
||
$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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
namespace Zend\Permissions\Acl\Assertion; | ||
|
||
use Zend\ServiceManager\AbstractPluginManager; | ||
use Zend\Permissions\Acl\Exception\InvalidArgumentException; | ||
|
||
class AssertionManager extends AbstractPluginManager | ||
{ | ||
|
||
protected $sharedByDefault = true; | ||
|
||
/** | ||
* Validate the plugin | ||
* | ||
* Checks that the element is an instance of AssertionInterface | ||
* | ||
* @param mixed $plugin | ||
* | ||
* @throws InvalidArgumentException | ||
* @return bool | ||
*/ | ||
public function validatePlugin($plugin) | ||
{ | ||
if (! $plugin instanceof AssertionInterface) { | ||
throw new InvalidArgumentException(sprintf('Plugin of type %s is invalid; must implement | ||
Zend\Permissions\Acl\Assertion\AssertionInterface', | ||
(is_object($plugin) ? get_class($plugin) : gettype($plugin)))); | ||
} | ||
|
||
return true; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
namespace Zend\Permissions\Acl\Assertion\Exception; | ||
|
||
use Zend\Permissions\Acl\Exception\ExceptionInterface; | ||
|
||
class InvalidAssertionException extends \InvalidArgumentException implements ExceptionInterface | ||
{ | ||
} |
Oops, something went wrong.