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 remote-tracking branch 'upstream/master'
- Loading branch information
Quoc Vu
committed
May 9, 2013
58 parents
9a04dec
+
c948ef1
+
bb8d758
+
681350e
+
535bf8a
+
6308000
+
43c0375
+
b6882cc
+
5ab9938
+
aee3039
+
d0c6f97
+
def4669
+
1d9336b
+
186c74b
+
06a51e4
+
3c55c64
+
8673a50
+
c5e096f
+
21a2d03
+
63799fd
+
457cc49
+
15924e3
+
7f82fa6
+
4b06447
+
b2bc2d7
+
581d4ea
+
2208cf2
+
782856d
+
af684a7
+
a30a853
+
c39d541
+
323eff0
+
f5a878b
+
99d2b61
+
0236fd9
+
94d722b
+
9515119
+
3453a81
+
c65c180
+
d9cce25
+
efa008a
+
bc6d3ee
+
b2d0cd0
+
f86fbc9
+
92dce0d
+
4299d35
+
39ca271
+
c515d60
+
7df306c
+
256605f
+
2a58924
+
45a72c8
+
6027334
+
695e48e
+
04ea4de
+
dc96c4e
+
f96c20d
+
9edb640
commit 24ccb84
Showing
13 changed files
with
785 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?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\Rbac; | ||
|
||
use RecursiveIterator; | ||
|
||
abstract class AbstractIterator implements RecursiveIterator | ||
{ | ||
protected $index = 0; | ||
protected $children = array(); | ||
|
||
/** | ||
* (PHP 5 >= 5.0.0)<br/> | ||
* Return the current element | ||
* @link http://php.net/manual/en/iterator.current.php | ||
* @return mixed Can return any type. | ||
*/ | ||
public function current() | ||
{ | ||
return $this->children[$this->index]; | ||
} | ||
|
||
/** | ||
* (PHP 5 >= 5.0.0)<br/> | ||
* Move forward to next element | ||
* @link http://php.net/manual/en/iterator.next.php | ||
* @return void Any returned value is ignored. | ||
*/ | ||
public function next() | ||
{ | ||
$this->index++; | ||
} | ||
|
||
/** | ||
* (PHP 5 >= 5.0.0)<br/> | ||
* Return the key of the current element | ||
* @link http://php.net/manual/en/iterator.key.php | ||
* @return scalar scalar on success, or null on failure. | ||
*/ | ||
public function key() | ||
{ | ||
return $this->index; | ||
} | ||
|
||
/** | ||
* (PHP 5 >= 5.0.0)<br/> | ||
* Checks if current position is valid | ||
* @link http://php.net/manual/en/iterator.valid.php | ||
* @return bool The return value will be casted to boolean and then evaluated. | ||
* Returns true on success or false on failure. | ||
*/ | ||
public function valid() | ||
{ | ||
return isset($this->children[$this->index]); | ||
} | ||
|
||
/** | ||
* (PHP 5 >= 5.0.0)<br/> | ||
* Rewind the Iterator to the first element | ||
* @link http://php.net/manual/en/iterator.rewind.php | ||
* @return void Any returned value is ignored. | ||
*/ | ||
public function rewind() | ||
{ | ||
$this->index = 0; | ||
} | ||
|
||
/** | ||
* (PHP 5 >= 5.1.0)<br/> | ||
* Returns if an iterator can be created fot the current entry. | ||
* @link http://php.net/manual/en/recursiveiterator.haschildren.php | ||
* @return bool true if the current entry can be iterated over, otherwise returns false. | ||
*/ | ||
public function hasChildren() | ||
{ | ||
if ($this->valid() && ($this->current() instanceof RecursiveIterator)) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* (PHP 5 >= 5.1.0)<br/> | ||
* Returns an iterator for the current entry. | ||
* @link http://php.net/manual/en/recursiveiterator.getRoles.php | ||
* @return RecursiveIterator An iterator for the current entry. | ||
*/ | ||
public function getChildren() | ||
{ | ||
return $this->children[$this->index]; | ||
} | ||
} |
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,118 @@ | ||
<?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\Rbac; | ||
|
||
use RecursiveIteratorIterator; | ||
|
||
abstract class AbstractRole extends AbstractIterator implements RoleInterface | ||
{ | ||
/** | ||
* @var null|RoleInterface | ||
*/ | ||
protected $parent; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $name; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $permissions = array(); | ||
|
||
/** | ||
* Get the name of the role. | ||
* | ||
* @return string | ||
*/ | ||
public function getName() | ||
{ | ||
return $this->name; | ||
} | ||
|
||
/** | ||
* Add permission to the role. | ||
* | ||
* @param $name | ||
* @return RoleInterface | ||
*/ | ||
public function addPermission($name) | ||
{ | ||
$this->permissions[$name] = true; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Checks if a permission exists for this role or any child roles. | ||
* | ||
* @param string $name | ||
* @return bool | ||
*/ | ||
public function hasPermission($name) | ||
{ | ||
if (isset($this->permissions[$name])) { | ||
return true; | ||
} | ||
|
||
$it = new RecursiveIteratorIterator($this, RecursiveIteratorIterator::CHILD_FIRST); | ||
foreach ($it as $leaf) { | ||
/** @var RoleInterface $leaf */ | ||
if ($leaf->hasPermission($name)) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* Add a child. | ||
* | ||
* @param RoleInterface|string $child | ||
* @return Role | ||
*/ | ||
public function addChild($child) | ||
{ | ||
if (is_string($child)) { | ||
$child = new Role($child); | ||
} | ||
if (!$child instanceof RoleInterface) { | ||
throw new Exception\InvalidArgumentException( | ||
'Child must be a string or implement Zend\Permissions\Rbac\RoleInterface' | ||
); | ||
} | ||
|
||
$child->setParent($this); | ||
$this->children[] = $child; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @param RoleInterface $parent | ||
* @return RoleInterface | ||
*/ | ||
public function setParent($parent) | ||
{ | ||
$this->parent = $parent; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return null|RoleInterface | ||
*/ | ||
public function getParent() | ||
{ | ||
return $this->parent; | ||
} | ||
} |
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,21 @@ | ||
<?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\Rbac; | ||
|
||
interface AssertionInterface | ||
{ | ||
/** | ||
* Assertion method - must return a boolean. | ||
* | ||
* @param Rbac $rbac | ||
* @return bool | ||
*/ | ||
public function assert(Rbac $rbac); | ||
} |
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,13 @@ | ||
<?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\Rbac\Exception; | ||
|
||
interface ExceptionInterface | ||
{} |
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,14 @@ | ||
<?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\Rbac\Exception; | ||
|
||
class InvalidArgumentException extends \InvalidArgumentException implements | ||
ExceptionInterface | ||
{} |
Oops, something went wrong.