/** * {@inheritdoc} * Example: * <code> * //Add a resource to the the list allowing access to an action * $acl->addResource(new \Phalcon\Acl\Resource('customers'), 'search'); * $acl->addResource('customers', 'search'); * //Add a resource with an access list * $acl->addResource(new \Phalcon\Acl\Resource('customers'), array('create', 'search')); * $acl->addResource('customers', array('create', 'search')); * </code> * * @param string|\Phalcon\Acl\Resource|string $resource * @param array|string $accessList * @return boolean */ public function addResource($resource, $accessList = null) { if (!is_object($resource)) { $resource = new Resource($resource); } $resources = $this->getCollection('resources'); $currentResource = $resources->findOne(array('name' => $this->filterResourceName($resource->getName()))); if (!$currentResource) { $resources->insert(array('name' => $this->filterResourceName($resource->getName()), 'description' => $resource->getDescription(), 'scope' => $resource->getScope())); } else { $resources->update(array('_id' => $currentResource['_id']), array('name' => $this->filterResourceName($resource->getName()), 'description' => $resource->getDescription(), 'scope' => $resource->getScope())); } if ($accessList) { return $this->addResourceAccess($resource->getName(), $accessList); } return true; }
/** * {@inheritdoc} * Example: * <code> * //Add a resource to the the list allowing access to an action * $acl->addResource(new \Phalcon\Acl\Resource('customers'), 'search'); * $acl->addResource('customers', 'search'); * //Add a resource with an access list * $acl->addResource(new \Phalcon\Acl\Resource('customers'), array('create', 'search')); * $acl->addResource('customers', array('create', 'search')); * </code> * * @param \Phalcon\Acl\Resource $resource * @param array|string $accessList * @return boolean */ public function addResource($resource, $accessList = null) { if (!$resource instanceof Resource) { $resource = new Resource($resource); } try { $resourceModel = $this->getResourceModel($resource->getName()); } catch (ResourceNotExistsException $e) { $resourceModel = new AclResource(); } $resourceModel->save(['name' => $this->filterResourceName($resource->getName()), 'description' => $resource->getDescription(), 'scope' => $resource->getScope()]); if ($accessList) { return $this->addResourceAccess($resource->getName(), $accessList); } return true; }