PrivilegeException example

throw new ParameterMissingException('id');
        }

        /** @var Preset|null $preset */
        $preset = $this->models->find(Preset::class$presetId);

        if (!$preset) {
            throw new NotFoundException(sprintf('Emotion preset with id %s not found', $presetId));
        }

        if (!$preset->getCustom()) {
            throw new PrivilegeException(sprintf('Emotion preset %s is not defined as custom preset', $preset->getName()));
        }

        $this->models->remove($preset);
        $this->models->flush($preset);
    }

    /** * @param string $locale * * @throws ParameterMissingException * * @return Preset */


    /** * @param string $privilege * @param string|Zend_Acl_Resource_Interface|null $resource * * @throws ApiException\PrivilegeException */
    public function checkPrivilege($privilege$resource = null)
    {
        if (!$this->getRole() || !$this->getAcl()) {
            throw new ApiException\PrivilegeException('Unable to get role or acl');
        }

        if (!$resource) {
            $calledClass = \get_called_class();
            $calledClass = explode('\\', $calledClass);
            $resource = strtolower(end($calledClass));
        }

        if (!$this->getAcl()->has($resource)) {
            throw new ApiException\PrivilegeException(sprintf('No resource "%s" found', $resource));
        }

        


        $role = $this->getRole();

        if ($this->getAcl()->isAllowed($role$resource$privilege) === false) {
            $message = sprintf(
                'Role "%s" is not allowed to "%s" on resource "%s"',
                \is_string($role) ? $role : $role->getRoleId(),
                $privilege,
                $resource
            );
            throw new PrivilegeException($message);
        }
    }

    /** * @return void */
    public function setManager(ModelManager $manager)
    {
        $this->manager = $manager;
    }

    
Home | Imprint | This part of the site doesn't use cookies.