ZfcRbac\Service\RoleService::matchIdentityRoles PHP Метод

matchIdentityRoles() публичный Метод

This method is smart enough to automatically recursively extracts roles for hierarchical roles
public matchIdentityRoles ( array $roles ) : boolean
$roles array
Результат boolean
    public function matchIdentityRoles(array $roles)
    {
        $identityRoles = $this->getIdentityRoles();
        // Too easy...
        if (empty($identityRoles)) {
            return false;
        }
        $roleNames = [];
        foreach ($roles as $role) {
            $roleNames[] = $role instanceof RoleInterface ? $role->getName() : (string) $role;
        }
        $identityRoles = $this->flattenRoles($identityRoles);
        return count(array_intersect($roleNames, $identityRoles)) > 0;
    }

Usage Example

Пример #1
0
 /**
  * @dataProvider roleProvider
  */
 public function testMatchIdentityRoles(array $rolesConfig, array $identityRoles, array $rolesToCheck, $doesMatch)
 {
     $identity = $this->getMock('ZfcRbac\\Identity\\IdentityInterface');
     $identity->expects($this->once())->method('getRoles')->will($this->returnValue($identityRoles));
     $identityProvider = $this->getMock('ZfcRbac\\Identity\\IdentityProviderInterface');
     $identityProvider->expects($this->any())->method('getIdentity')->will($this->returnValue($identity));
     $roleService = new RoleService($identityProvider, new InMemoryRoleProvider($rolesConfig), new RecursiveRoleIteratorStrategy());
     $this->assertEquals($doesMatch, $roleService->matchIdentityRoles($rolesToCheck));
 }
All Usage Examples Of ZfcRbac\Service\RoleService::matchIdentityRoles