Skip to content

Commit

Permalink
Merge pull request #8 from Becklyn/update
Browse files Browse the repository at this point in the history
  • Loading branch information
Jannik committed Apr 28, 2020
2 parents 40c0915 + d71ee8c commit 2cdb443
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 48 deletions.
4 changes: 4 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public function getConfigTreeBuilder ()
->scalarNode("description")->end()
->booleanNode("hidden")->defaultFalse()->end()
->arrayNode("included_roles")
->validate()
->ifTrue(function (array $roles) { return !empty($roles); })
->thenInvalid("Don't define your included roles in the `becklyn_static_roles` config, but in symfony's role hierarchy instead")
->end()
->prototype('scalar')->end()
->end()
->arrayNode("tags")
Expand Down
28 changes: 1 addition & 27 deletions src/Role/RoleCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Becklyn\StaticRolesBundle\Role;

use Symfony\Component\Security\Core\Role\RoleHierarchy;
use Symfony\Component\Security\Core\Role\RoleHierarchyInterface;

/**
Expand All @@ -13,9 +12,6 @@ final class RoleCollection implements RoleHierarchyInterface
/** @var RoleHierarchyInterface */
private $coreHierarchy;

/** @var RoleHierarchyInterface */
private $nestedHierarchy;

/** @var StaticRole[] */
private $roles;

Expand All @@ -25,27 +21,10 @@ final class RoleCollection implements RoleHierarchyInterface
public function __construct (RoleHierarchyInterface $coreHierarchy, array $config = [])
{
$this->coreHierarchy = $coreHierarchy;
$this->nestedHierarchy = $this->buildNestedHierarchy($config);
$this->roles = $this->prepareRoleCollection($config);
}


/**
*
*/
private function buildNestedHierarchy (array $config) : RoleHierarchyInterface
{
$map = [];

foreach ($config as $role => $data)
{
$map[$role] = $data["included_roles"] ?? [];
}

return new RoleHierarchy($map);
}



/**
* Prepares the role collection by transforming the config array to an object structure
Expand Down Expand Up @@ -100,12 +79,7 @@ public function getReachableRoleNames (array $roles) : array
{
$roles = $this->coreHierarchy->getReachableRoleNames($roles);

foreach ($this->nestedHierarchy->getReachableRoleNames($roles) as $additional)
{
$roles[] = $additional;
}

$result = \array_unique($roles);
$result = $roles;

foreach ($roles as $role)
{
Expand Down
21 changes: 0 additions & 21 deletions src/Role/StaticRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,6 @@ final class StaticRole
private $hidden;


/**
* A list of all included role names
*
* @var string[]
*/
private $includedRoles = [];


/**
* A list of tags
*
Expand All @@ -69,7 +61,6 @@ public function __construct (
?string $title,
?string $description,
bool $hidden,
array $includedRoles,
array $tags,
array $actions
)
Expand All @@ -78,7 +69,6 @@ public function __construct (
$this->title = $title;
$this->description = $description;
$this->hidden = $hidden;
$this->includedRoles = $includedRoles;
$this->tags = $tags;
$this->actions = $actions;
}
Expand All @@ -99,7 +89,6 @@ public static function createFromConfiguration ($role, array $configuration)
$configuration["title"] ?? null,
$configuration["description"] ?? null,
$configuration["hidden"] ?? false,
$configuration["included_roles"] ?? [],
$configuration["tags"] ?? [],
$configuration["actions"] ?? []
);
Expand Down Expand Up @@ -134,16 +123,6 @@ public function getTags () : array



/**
* @return string[]
*/
public function getIncludedRoles () : array
{
return $this->includedRoles;
}



/**
*/
public function getActions () : array
Expand Down

0 comments on commit 2cdb443

Please sign in to comment.