public function isGrantedForRoles(array $roles, $privilegeType, $subject, &$reason = '')
    {
        $availablePrivileges = array_reduce($roles, $this->getPrivilegeByTypeReducer($privilegeType), []);
        $effectivePrivileges = array_filter($availablePrivileges, $this->getPrivilegeSubjectFilter($subject));
        /** @var PrivilegePermissionResult $result */
        $result = array_reduce($effectivePrivileges, [$this, 'applyPrivilegeToResult'], new PrivilegePermissionResult());

        $effectivePrivilegeIdentifiersWithPermission = $result->getEffectivePrivilegeIdentifiersWithPermission();
        if ($effectivePrivilegeIdentifiersWithPermission === []) {
            $reason = sprintf('No privilege of type "%s" matched.', $privilegeType);
            return true;
        }

        $reason = sprintf('Evaluated following %d privilege target(s):' . chr(10) . '%s' . chr(10) . '(%d granted, %d denied, %d abstained)',
            count($effectivePrivilegeIdentifiersWithPermission),
            implode(chr(10), $effectivePrivilegeIdentifiersWithPermission),
            $result->getGrants(),
            $result->getDenies(),
            $result->getAbstains()
        );

        if ($result->getDenies() > 0) {
            return false;
        }
        if ($result->getGrants() > 0) {
            return true;
        }

        return false;
    }
public function isGrantedForRoles(array $roles, $privilegeType, $subject, &$reason = '')
    {
        $availablePrivileges = array_reduce($roles, $this->getPrivilegeByTypeReducer($privilegeType), []);
        $effectivePrivileges = array_filter($availablePrivileges, $this->getPrivilegeSubjectFilter($subject));
        /** @var PrivilegePermissionResult $result */
        $result = array_reduce($effectivePrivileges, [$this, 'applyPrivilegeToResult'], new PrivilegePermissionResult());

        $effectivePrivilegeIdentifiersWithPermission = $result->getEffectivePrivilegeIdentifiersWithPermission();
        if ($effectivePrivilegeIdentifiersWithPermission === []) {
            $reason = sprintf('No privilege of type "%s" matched.', $privilegeType);
            return true;
        }

        $reason = sprintf('Evaluated following %d privilege target(s):' . chr(10) . '%s' . chr(10) . '(%d granted, %d denied, %d abstained)',
            count($effectivePrivilegeIdentifiersWithPermission),
            implode(chr(10), $effectivePrivilegeIdentifiersWithPermission),
            $result->getGrants(),
            $result->getDenies(),
            $result->getAbstains()
        );

        if ($result->getDenies() > 0) {
            return false;
        }
        if ($result->getGrants() > 0) {
            return true;
        }

        return false;
    }
public function isGrantedForRoles ( array $ roles , $ privilegeType , $ subject , & $ reason = '' ) { $ availablePrivileges = array_reduce ( $ roles , $ this -> getPrivilegeByTypeReducer ( $ privilegeType ) , [ ] ) ; $ effectivePrivileges = array_filter ( $ availablePrivileges , $ this -> getPrivilegeSubjectFilter ( $ subject ) ) ; /** @var PrivilegePermissionResult $result */ $ result = array_reduce ( $ effectivePrivileges , [ $ this , 'applyPrivilegeToResult' ] , new PrivilegePermissionResult ( ) ) ; $ effectivePrivilegeIdentifiersWithPermission = $ result -> getEffectivePrivilegeIdentifiersWithPermission ( ) ; if ( $ effectivePrivilegeIdentifiersWithPermission === [ ] ) { $ reason = sprintf ( 'No privilege of type "%s" matched.' , $ privilegeType ) ; return true ; } $ reason = sprintf ( 'Evaluated following %d privilege target(s):' . chr ( 10 ) . '%s' . chr ( 10 ) . '(%d granted, %d denied, %d abstained)' , count ( $ effectivePrivilegeIdentifiersWithPermission ) , implode ( chr ( 10 ) , $ effectivePrivilegeIdentifiersWithPermission ) , $ result -> getGrants ( ) , $ result -> getDenies ( ) , $ result -> getAbstains ( ) ) ; if ( $ result -> getDenies ( ) > 0 ) { return false ; } if ( $ result -> getGrants ( ) > 0 ) { return true ; } return false ; }
Returns true, if the given privilege type would be granted for the given roles and subject

@param array<Role> $roles The roles that should be evaluated
@param string $privilegeType The type of privilege that should be evaluated
@param mixed $subject The subject to check privileges for
@param string $reason This variable will be filled by a message giving information about the reasons for the result of this method
@return boolean
Returns true if the given privilege type would be granted for the given roles and subject