Exemplo n.º 1
0
 /**
  * Reformat role in a clean way. This filter assumes that the roles passed are known to {@see
  * RoleHierarchyHelper} and formatted following the ROLE_%s mask.
  *
  * @example
  *  roleFilter(['ROLE_USER'])         // "user"
  *  roleFilter(['ROLE_ADMIN'])        // "admin"
  *  roleFilter(['ROLE_SUPER_ADMIN'])  // "root"
  *
  * @param array $roles Array of valid Symfony roles.
  *
  * @return string Formatted top role if role known, empty string otherwise.
  */
 public function userTopRoleFilter(array $roles)
 {
     $topRole = RoleHierarchyHelper::getTopLevelRole($roles);
     if (null === $topRole) {
         return '';
     }
     if ('ROLE_SUPER_ADMIN' === $topRole) {
         return 'root';
     }
     return strtolower(substr($topRole, 5));
 }
Exemplo n.º 2
0
 /**
  * @testdox Test RoleHierarchyHelper::getTopLevelRole().
  *
  * @covers       ::getTopLevelRole
  * @dataProvider rolesProvider
  *
  * @param array       $roles    List of roles.
  * @param string|null $expected Expected value returned by the method.
  */
 public function testGetTopLevelRole(array $roles, $expected)
 {
     $this->assertEquals($expected, RoleHierarchyHelper::getTopLevelRole($roles));
 }