Source of file AbstractRole.php
Size: 2,473 Bytes - Last Modified: 2014-03-12T23:21:18+01:00
/home/theseer/Downloads/ZendFramework-2.3.0/library/Zend/Permissions/Rbac/AbstractRole.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 | <?php /** * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2014 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; } } |