ZfcRbac\Service\RoleService::getIdentityRoles PHP Method

getIdentityRoles() public method

Get the identity roles from the current identity, applying some more logic
public getIdentityRoles ( ) : Rbac\Role\RoleInterface[]
return Rbac\Role\RoleInterface[]
    public function getIdentityRoles()
    {
        if (!($identity = $this->getIdentity())) {
            return $this->convertRoles([$this->guestRole]);
        }
        if (!$identity instanceof IdentityInterface) {
            throw new Exception\RuntimeException(sprintf('ZfcRbac expects your identity to implement ZfcRbac\\Identity\\IdentityInterface, "%s" given', is_object($identity) ? get_class($identity) : gettype($identity)));
        }
        return $this->convertRoles($identity->getRoles());
    }

Usage Example

Esempio n. 1
0
 public function testThrowExceptionIfIdentityIsWrongType()
 {
     $this->setExpectedException('ZfcRbac\\Exception\\RuntimeException', 'ZfcRbac expects your identity to implement ZfcRbac\\Identity\\IdentityInterface, "stdClass" given');
     $identityProvider = $this->getMock('ZfcRbac\\Identity\\IdentityProviderInterface');
     $identityProvider->expects($this->any())->method('getIdentity')->will($this->returnValue(new \stdClass()));
     $roleService = new RoleService($identityProvider, $this->getMock('ZfcRbac\\Role\\RoleProviderInterface'), $this->getMock('Rbac\\Traversal\\Strategy\\TraversalStrategyInterface'));
     $roleService->getIdentityRoles();
 }
All Usage Examples Of ZfcRbac\Service\RoleService::getIdentityRoles