Skip to content

Commit 5fd228b

Browse files
committed
deprecate the Role and SwitchUserRole classes
1 parent b263468 commit 5fd228b

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

Processor/TokenProcessor.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,16 @@ public function __invoke(array $records)
3131
{
3232
$records['extra']['token'] = null;
3333
if (null !== $token = $this->tokenStorage->getToken()) {
34+
if (method_exists($token, 'getRoleNames')) {
35+
$roles = $token->getRoleNames();
36+
} else {
37+
$roles = array_map(function ($role) { return $role->getRole(); }, $token->getRoles(false));
38+
}
39+
3440
$records['extra']['token'] = [
3541
'username' => $token->getUsername(),
3642
'authenticated' => $token->isAuthenticated(),
37-
'roles' => array_map(function ($role) { return $role->getRole(); }, $token->getRoles()),
43+
'roles' => $roles,
3844
];
3945
}
4046

Tests/Processor/TokenProcessorTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ public function testProcessor()
3636
$this->assertArrayHasKey('token', $record['extra']);
3737
$this->assertEquals($token->getUsername(), $record['extra']['token']['username']);
3838
$this->assertEquals($token->isAuthenticated(), $record['extra']['token']['authenticated']);
39-
$roles = array_map(function ($role) { return $role->getRole(); }, $token->getRoles());
40-
$this->assertEquals($roles, $record['extra']['token']['roles']);
39+
$this->assertEquals(['ROLE_USER'], $record['extra']['token']['roles']);
4140
}
4241
}

0 commit comments

Comments
 (0)