src/Role/RoleService.php
public function matchIdentityRoles(array $roles): bool
    {
        $identityRoles = $this->getIdentityRoles();
        // Too easy...
        if (empty($identityRoles)) {
            return false;
        }
        $roleNames = [];
        foreach ($roles as $role) {
            $roleNames[] = $role instanceof RoleInterface ? $role->getName() : (string)$role;
        }

        $identityRoleNames = [];
        foreach ($this->flattenRoles($identityRoles) as $role) {
            $identityRoleNames[] = $role->getName();
        }

        return count(array_intersect($roleNames, $identityRoleNames)) > 0;
    }
public function matchIdentityRoles(array $roles): bool
    {
        $identityRoles = $this->getIdentityRoles();
        // Too easy...
        if (empty($identityRoles)) {
            return false;
        }
        $roleNames = [];
        foreach ($roles as $role) {
            $roleNames[] = $role instanceof RoleInterface ? $role->getName() : (string)$role;
        }

        $identityRoleNames = [];
        foreach ($this->flattenRoles($identityRoles) as $role) {
            $identityRoleNames[] = $role->getName();
        }

        return count(array_intersect($roleNames, $identityRoleNames)) > 0;
    }
public function matchIdentityRoles ( array $ roles ) : bool { $ identityRoles = $ this -> getIdentityRoles ( ) ; // Too easy... if ( empty ( $ identityRoles ) ) { return false ; } $ roleNames = [ ] ; foreach ( $ roles as $ role ) { $ roleNames [ ] = $ role instanceof RoleInterface ? $ role -> getName ( ) : ( string ) $ role ; } $ identityRoleNames = [ ] ; foreach ( $ this -> flattenRoles ( $ identityRoles ) as $ role ) { $ identityRoleNames [ ] = $ role -> getName ( ) ; } return count ( array_intersect ( $ roleNames , $ identityRoleNames ) ) > 0 ; }
Check if the given roles match one of the identity roles

This method is smart enough to automatically recursively extracts roles for hierarchical roles

@param  string[]|RoleInterface[] $roles
@return bool
Check if the given roles match one of the identity roles