mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-28 18:43:49 +00:00
fix: Strict types interfaces: VoterHelperInterface
, ProvideRoleHierarchyInterface
and ProvideRoleInterface
.
This commit is contained in:
@@ -20,7 +20,7 @@
|
||||
namespace Chill\MainBundle\Security;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
@@ -31,63 +31,57 @@ class RoleProvider
|
||||
* @var ProvideRoleInterface[]
|
||||
*/
|
||||
private $providers = array();
|
||||
|
||||
|
||||
/**
|
||||
* an array where keys are the role, and value is the title
|
||||
* for the given role.
|
||||
*
|
||||
*
|
||||
* Null when not initialized.
|
||||
*
|
||||
* @var array|null
|
||||
*/
|
||||
private $rolesTitlesCache = null;
|
||||
|
||||
|
||||
/**
|
||||
* Add a role provider
|
||||
*
|
||||
*
|
||||
* @internal This function is called by the dependency injector: it inject provider
|
||||
* @param \Chill\MainBundle\Security\ProvideRoleInterface $provider
|
||||
*/
|
||||
public function addProvider(ProvideRoleInterface $provider)
|
||||
public function addProvider(ProvideRoleInterface $provider)
|
||||
{
|
||||
$this->providers[] = $provider;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string[] the roles as string
|
||||
*/
|
||||
public function getRoles()
|
||||
|
||||
public function getRoles(): array
|
||||
{
|
||||
$roles = array();
|
||||
$roles = [];
|
||||
|
||||
foreach ($this->providers as $provider) {
|
||||
if ($provider->getRoles() !== NULL) {
|
||||
$roles = array_merge($roles, $provider->getRoles());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $roles;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string[] the roles as string
|
||||
*/
|
||||
public function getRolesWithoutScopes()
|
||||
|
||||
public function getRolesWithoutScopes(): array
|
||||
{
|
||||
$roles = array();
|
||||
$roles = [];
|
||||
|
||||
foreach ($this->providers as $provider) {
|
||||
if ($provider->getRolesWithoutScope() !== NULL) {
|
||||
$roles = array_merge($roles, $provider->getRolesWithoutScope());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $roles;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* initialize the array for caching role and titles
|
||||
*
|
||||
*
|
||||
*/
|
||||
private function initializeRolesTitlesCache()
|
||||
{
|
||||
@@ -95,7 +89,7 @@ class RoleProvider
|
||||
if ($this->rolesTitlesCache !== null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
foreach ($this->providers as $provider) {
|
||||
if ($provider instanceof ProvideRoleHierarchyInterface) {
|
||||
foreach ($provider->getRolesWithHierarchy() as $title => $roles) {
|
||||
@@ -106,31 +100,31 @@ class RoleProvider
|
||||
} else {
|
||||
if ($provider->getRoles() !== null) {
|
||||
$this->rolesTitlesCache = \array_merge(
|
||||
$this->rolesTitlesCache,
|
||||
$this->rolesTitlesCache,
|
||||
\array_fill_keys($provider->getRoles(), null)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the title for each role.
|
||||
*
|
||||
*
|
||||
* @param string $role
|
||||
* @return string the title of the role
|
||||
*/
|
||||
public function getRoleTitle($role)
|
||||
{
|
||||
$this->initializeRolesTitlesCache();
|
||||
|
||||
|
||||
if (! \array_key_exists($role, $this->rolesTitlesCache)) {
|
||||
// this case might happens when the role is not described in
|
||||
// this case might happens when the role is not described in
|
||||
// `getRolesWithHierarchy`
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
return $this->rolesTitlesCache[$role];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user