Neos\Flow\Security\Policy\PolicyService::getRoles PHP Метод

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

Returns an array of all configured roles
public getRoles ( boolean $includeAbstract = false ) : Role[]
$includeAbstract boolean If TRUE the result includes abstract roles, otherwise those will be skipped
Результат Role[] Array of all configured roles, indexed by role identifier
    public function getRoles($includeAbstract = false)
    {
        $this->initialize();
        if (!$includeAbstract) {
            return array_filter($this->roles, function (Role $role) {
                return $role->isAbstract() !== true;
            });
        }
        return $this->roles;
    }

Usage Example

 /**
  * Lists all public controller actions not covered by the active security policy
  *
  * @return void
  */
 public function showUnprotectedActionsCommand()
 {
     $methodPrivileges = [];
     foreach ($this->policyService->getRoles(true) as $role) {
         $methodPrivileges = array_merge($methodPrivileges, $role->getPrivilegesByType(MethodPrivilegeInterface::class));
     }
     $controllerClassNames = $this->reflectionService->getAllSubClassNamesForClass(AbstractController::class);
     $allActionsAreProtected = true;
     foreach ($controllerClassNames as $controllerClassName) {
         if ($this->reflectionService->isClassAbstract($controllerClassName)) {
             continue;
         }
         $methodNames = get_class_methods($controllerClassName);
         $foundUnprotectedAction = false;
         foreach ($methodNames as $methodName) {
             if (preg_match('/.*Action$/', $methodName) === 0 || $this->reflectionService->isMethodPublic($controllerClassName, $methodName) === false) {
                 continue;
             }
             /** @var MethodPrivilegeInterface $methodPrivilege */
             foreach ($methodPrivileges as $methodPrivilege) {
                 if ($methodPrivilege->matchesMethod($controllerClassName, $methodName)) {
                     continue 2;
                 }
             }
             if ($foundUnprotectedAction === false) {
                 $this->outputLine(PHP_EOL . '<b>' . $controllerClassName . '</b>');
                 $foundUnprotectedAction = true;
                 $allActionsAreProtected = false;
             }
             $this->outputLine('  ' . $methodName);
         }
     }
     if ($allActionsAreProtected === true) {
         $this->outputLine('All public controller actions are covered by your security policy. Good job!');
     }
 }
All Usage Examples Of Neos\Flow\Security\Policy\PolicyService::getRoles