Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit af7d48d

Browse files
committed
forward compatibility with Symfony 4
1 parent c3be3ea commit af7d48d

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/Symfony/Bundle/SecurityBundle/DataCollector/SecurityDataCollector.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\SecurityBundle\DataCollector;
1313

1414
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
15+
use Symfony\Component\Security\Core\Role\Role;
1516
use Symfony\Component\Security\Core\Role\RoleHierarchyInterface;
1617
use Symfony\Component\HttpFoundation\Request;
1718
use Symfony\Component\HttpFoundation\Response;
@@ -117,8 +118,26 @@ public function collect(Request $request, Response $response, \Exception $except
117118
'token_class' => $this->hasVarDumper ? new ClassStub(get_class($token)) : get_class($token),
118119
'logout_url' => $logoutUrl,
119120
'user' => $token->getUsername(),
120-
'roles' => array_map(function (RoleInterface $role) { return $role->getRole(); }, $assignedRoles),
121-
'inherited_roles' => array_map(function (RoleInterface $role) { return $role->getRole(); }, $inheritedRoles),
121+
'roles' => array_map(
122+
function ($role) {
123+
if (!$role instanceof RoleInterface && !$role instanceof Role) {
124+
throw new \InvalidArgumentException(sprintf('Roles must be instances of %s or %s (%s given).', RoleInterface::class, Role::class, is_object($role) ? get_class($role) : gettype($role)));
125+
}
126+
127+
return $role->getRole();
128+
},
129+
$assignedRoles
130+
),
131+
'inherited_roles' => array_map(
132+
function ($role) {
133+
if (!$role instanceof RoleInterface && !$role instanceof Role) {
134+
throw new \InvalidArgumentException(sprintf('Roles must be instances of %s or %s (%s given).', RoleInterface::class, Role::class, is_object($role) ? get_class($role) : gettype($role)));
135+
}
136+
137+
return $role->getRole();
138+
},
139+
$inheritedRoles
140+
),
122141
'supports_role_hierarchy' => null !== $this->roleHierarchy,
123142
);
124143
}

0 commit comments

Comments
 (0)