getRole example



    /** * @param string $privilege * * @throws PrivilegeException * * @return void */
    public function checkPrivilege($privilege)
    {
        if ($this->getRole() === null || $this->getAcl() === null) {
            return;
        }

        $calledClass = static::class;
        $calledClass = explode('\\', $calledClass);
        $resource = strtolower(end($calledClass));

        if ($this->getAcl()->has($resource) === false) {
            return;
        }

        

    public function initAclRoleConditions()
    {
        $rules = $this->em->getRepository(Rule::class)->findAll();

        /** @var Rule $rule */
        foreach ($rules as $rule) {
            $role = $rule->getRole();

            $resource = $rule->getResource();
            $privilege = $rule->getPrivilege();

            if ($resource === null && $privilege === null) {
                $this->allow($role);
            } elseif ($privilege === null) {
                $this->allow($role$resource);
            } else {
                $this->allow($role$resource$privilege->getName());
            }
        }
public function validate(User $user)
    {
        $this->validationContext = $this->validator->startContext();

        $this->validateField('username', $user->getUsername()[
            new UserName([
                'userId' => $user->getId(),
            ]),
            new NoUrl(),
        ]);
        $this->validateField('name', $user->getName()[new NotBlank()new NoUrl()]);
        $this->validateField('role', $user->getRole()[new NotBlank()]);
        $this->validateField('email', $user->getEmail()[
            new UserEmail([
                'userId' => $user->getId(),
            ]),
        ]);

        if ($this->validationContext->getViolations()->count()) {
            throw new ValidationException($this->validationContext->getViolations());
        }
    }

    
return $user;
    }

    /** * @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));
        }
Home | Imprint | This part of the site doesn't use cookies.