Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c783e1e

Browse filesBrowse files
committed
forward compatibility with Symfony 4
1 parent c3be3ea commit c783e1e
Copy full SHA for c783e1e

File tree

Expand file treeCollapse file tree

1 file changed

+11
-2
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+11
-2
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/SecurityBundle/DataCollector/SecurityDataCollector.php
+11-2Lines changed: 11 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;
@@ -110,15 +111,23 @@ public function collect(Request $request, Response $response, \Exception $except
110111
// fail silently when the logout URL cannot be generated
111112
}
112113

114+
$extractRoles = function ($role) {
115+
if (!$role instanceof RoleInterface && !$role instanceof Role) {
116+
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)));
117+
}
118+
119+
return $role->getRole();
120+
};
121+
113122
$this->data = array(
114123
'enabled' => true,
115124
'authenticated' => $token->isAuthenticated(),
116125
'token' => $token,
117126
'token_class' => $this->hasVarDumper ? new ClassStub(get_class($token)) : get_class($token),
118127
'logout_url' => $logoutUrl,
119128
'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),
129+
'roles' => array_map($extractRoles, $assignedRoles),
130+
'inherited_roles' => array_map($extractRoles, $inheritedRoles),
122131
'supports_role_hierarchy' => null !== $this->roleHierarchy,
123132
);
124133
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.