/**
  * Ensures that cyclic role hierarchies don't choke up the system
  */
 public function testCyclicRoleHierarchy()
 {
     $configuration = ["a" => ["included_roles" => ["b"]], "b" => ["included_roles" => ["a"]]];
     $roleCollection = new RoleCollection($configuration);
     $includedRoles = $roleCollection->getAllIncludedRoles(["a"]);
     $this->assertArrayHasKey("a", $includedRoles);
     $this->assertArrayHasKey("b", $includedRoles);
 }
 /**
  * Configures the options for this type.
  *
  * @param OptionsResolver $resolver The resolver for the options.
  */
 public function configureOptions(OptionsResolver $resolver)
 {
     $allRoles = $this->roleCollection->getAllAvailableRoles();
     $allRoleKeys = array_keys($allRoles);
     $resolver->setDefaults(["roles_with_tags" => [], "choices" => function (Options $options) use($allRoleKeys, $allRoles) {
         // if no tags are selected, just return all roles
         if (empty($options["roles_with_tags"])) {
             return array_combine($allRoleKeys, $allRoleKeys);
         }
         // if tags are selected, only use the choices with the given tags
         $choices = [];
         foreach ($allRoles as $roleKey => $role) {
             if (!empty(array_intersect($options["roles_with_tags"], $role->getTags()))) {
                 $choices[$roleKey] = $roleKey;
             }
         }
         return $choices;
     }, "choices_as_values" => true, "choice_label" => function ($choiceValue, $choiceKey, $index) use($allRoles) {
         return $allRoles[$choiceKey]->getTitle();
     }, "choice_attr" => function ($choiceValue, $choiceKey, $index) use($allRoles) {
         return ["data-role-description" => $allRoles[$choiceKey]->getDescription()];
     }]);
     $resolver->setAllowedTypes("roles_with_tags", ["array"]);
 }
 /**
  * {@inheritdoc}
  */
 protected function extractRoles(TokenInterface $token)
 {
     return $this->roleCollection->getAllIncludedRoles($token->getRoles());
 }
 /**
  * Returns the static role name
  *
  * @param string $roleKey
  *
  * @return null|string
  */
 public function staticRoleTitle($roleKey)
 {
     $role = $this->roleCollection->getRoleByKey($roleKey);
     return null !== $role ? $role->getTitle() : null;
 }