Neos\Flow\Security\Context::hasRole PHP Method

hasRole() public method

Returns TRUE, if at least one of the currently authenticated accounts holds a role with the given identifier, also recursively.
public hasRole ( string $roleIdentifier ) : boolean
$roleIdentifier string The string representation of the role to search for
return boolean TRUE, if a role with the given string representation was found
    public function hasRole($roleIdentifier)
    {
        if ($roleIdentifier === 'Neos.Flow:Everybody') {
            return true;
        }
        if ($roleIdentifier === 'Neos.Flow:Anonymous') {
            return !$this->authenticationManager->isAuthenticated();
        }
        if ($roleIdentifier === 'Neos.Flow:AuthenticatedUser') {
            return $this->authenticationManager->isAuthenticated();
        }
        $roles = $this->getRoles();
        return isset($roles[$roleIdentifier]);
    }

Usage Example

 /**
  * Returns TRUE, if at least one of the currently authenticated accounts holds
  * a role with the given identifier, also recursively.
  *
  * @param string $roleIdentifier The string representation of the role to search for
  * @return boolean TRUE, if a role with the given string representation was found
  */
 public function hasRole($roleIdentifier)
 {
     if ($roleIdentifier === 'Neos.Flow:Everybody') {
         return true;
     }
     if ($this->securityContext->canBeInitialized()) {
         return $this->securityContext->hasRole($roleIdentifier);
     }
     return false;
 }
All Usage Examples Of Neos\Flow\Security\Context::hasRole