Exemple #1
0
 /**
  * Adds a Resource having an identifier unique to the ACL
  *
  * The $parent parameter may be a reference to, or the string identifier for,
  * the existing Resource from which the newly added Resource will inherit.
  *
  * @param  Resource\ResourceInterface|string $resource
  * @param  Resource\ResourceInterface|string $parent
  * @throws Exception\InvalidArgumentException
  * @return Acl Provides a fluent interface
  */
 public function addResource($resource, $parent = null)
 {
     if (is_string($resource)) {
         $resource = new Resource\GenericResource($resource);
     } elseif (!$resource instanceof Resource\ResourceInterface) {
         throw new Exception\InvalidArgumentException('addResource() expects $resource to be of type Zend\\Permissions\\Acl\\Resource\\ResourceInterface');
     }
     $resourceId = $resource->getResourceId();
     if ($this->hasResource($resourceId)) {
         throw new Exception\InvalidArgumentException("Resource id '{$resourceId}' already exists in the ACL");
     }
     $resourceParent = null;
     if (null !== $parent) {
         try {
             if ($parent instanceof Resource\ResourceInterface) {
                 $resourceParentId = $parent->getResourceId();
             } else {
                 $resourceParentId = $parent;
             }
             $resourceParent = $this->getResource($resourceParentId);
         } catch (\Exception $e) {
             throw new Exception\InvalidArgumentException(sprintf('Parent Resource id "%s" does not exist', $resourceParentId), 0, $e);
         }
         $this->resources[$resourceParentId]['children'][$resourceId] = $resource;
     }
     $this->resources[$resourceId] = array('instance' => $resource, 'parent' => $resourceParent, 'children' => array());
     return $this;
 }
Exemple #2
0
 /**
  * Adds a Resource having an identifier unique to the ACL
  *
  * The $parent parameter may be a reference to, or the string identifier for,
  * the existing Resource from which the newly added Resource will inherit.
  *
  * @param  Zend\Acl\Resource|string $resource
  * @param  Zend\Acl\Resource|string $parent
  * @throws Zend\Acl\Exception
  * @return Zend\Acl\Acl Provides a fluent interface
  */
 public function addResource($resource, $parent = null)
 {
     if (is_string($resource)) {
         $resource = new Resource\GenericResource($resource);
     }
     if (!$resource instanceof Resource) {
         throw new Exception('addResource() expects $resource to be of type Zend_Acl_Resource_Interface');
     }
     $resourceId = $resource->getResourceId();
     if ($this->hasResource($resourceId)) {
         throw new Exception("Resource id '{$resourceId}' already exists in the ACL");
     }
     $resourceParent = null;
     if (null !== $parent) {
         try {
             if ($parent instanceof Resource) {
                 $resourceParentId = $parent->getResourceId();
             } else {
                 $resourceParentId = $parent;
             }
             $resourceParent = $this->getResource($resourceParentId);
         } catch (Exception $e) {
             throw new Exception("Parent Resource id '{$resourceParentId}' does not exist", 0, $e);
         }
         $this->_resources[$resourceParentId]['children'][$resourceId] = $resource;
     }
     $this->_resources[$resourceId] = array('instance' => $resource, 'parent' => $resourceParent, 'children' => array());
     return $this;
 }