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

Skip to content

Commit 913a9c4

Browse files
committed
Deprecate LogoutListener being returned as 3rd element by FirewallMapInterface::getListeners
1 parent ff70bd1 commit 913a9c4

File tree

7 files changed

+20
-7
lines changed

7 files changed

+20
-7
lines changed

src/Symfony/Bundle/SecurityBundle/Security/FirewallMap.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ public function __construct(ContainerInterface $container, iterable $map)
3535

3636
public function getListeners(Request $request)
3737
{
38+
if (2 > \func_num_args() || func_get_arg(1)) {
39+
trigger_deprecation('symfony/security-bundle', '5.4', 'The third element in the return value of "%s()" is deprecated', __METHOD__);
40+
}
41+
3842
$context = $this->getFirewallContext($request);
3943

4044
if (null === $context) {

src/Symfony/Bundle/SecurityBundle/Tests/Security/FirewallMapTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function testGetListenersWithEmptyMap()
3535

3636
$firewallMap = new FirewallMap($container, $map);
3737

38-
$this->assertEquals([[], null, null], $firewallMap->getListeners($request));
38+
$this->assertEquals([[], null, null], $firewallMap->getListeners($request, false));
3939
$this->assertNull($firewallMap->getFirewallConfig($request));
4040
$this->assertFalse($request->attributes->has(self::ATTRIBUTE_FIREWALL_CONTEXT));
4141
}
@@ -51,7 +51,7 @@ public function testGetListenersWithInvalidParameter()
5151

5252
$firewallMap = new FirewallMap($container, $map);
5353

54-
$this->assertEquals([[], null, null], $firewallMap->getListeners($request));
54+
$this->assertEquals([[], null, null], $firewallMap->getListeners($request, false));
5555
$this->assertNull($firewallMap->getFirewallConfig($request));
5656
$this->assertFalse($request->attributes->has(self::ATTRIBUTE_FIREWALL_CONTEXT));
5757
}
@@ -85,7 +85,7 @@ public function testGetListeners()
8585

8686
$firewallMap = new FirewallMap($container, ['security.firewall.map.context.foo' => $matcher]);
8787

88-
$this->assertEquals([[$listener], $exceptionListener, $logoutListener], $firewallMap->getListeners($request));
88+
$this->assertEquals([[$listener], $exceptionListener, $logoutListener], $firewallMap->getListeners($request, false));
8989
$this->assertEquals($firewallConfig, $firewallMap->getFirewallConfig($request));
9090
$this->assertEquals('security.firewall.map.context.foo', $request->attributes->get(self::ATTRIBUTE_FIREWALL_CONTEXT));
9191
}

src/Symfony/Component/Security/Http/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ CHANGELOG
1616
* Deprecate `CookieClearingLogoutHandler`, `SessionLogoutHandler` and `CsrfTokenClearingLogoutHandler`.
1717
Use `CookieClearingLogoutListener`, `SessionLogoutListener` and `CsrfTokenClearingLogoutListener` instead
1818
* Deprecate `PassportInterface`, `UserPassportInterface` and `PassportTrait`, use `Passport` instead
19+
* Deprecate the third element of the outer array returned by `FirewallMapInterface::getListener` which contains the `LogoutListener`.
1920

2021
5.3
2122
---

src/Symfony/Component/Security/Http/Firewall.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function onKernelRequest(RequestEvent $event)
4848
}
4949

5050
// register listeners for this firewall
51-
$listeners = $this->map->getListeners($event->getRequest());
51+
$listeners = $this->map->getListeners($event->getRequest(), false);
5252

5353
$authenticationListeners = $listeners[0];
5454
$exceptionListener = $listeners[1];

src/Symfony/Component/Security/Http/FirewallMap.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ public function add(RequestMatcherInterface $requestMatcher = null, array $liste
3636
*/
3737
public function getListeners(Request $request)
3838
{
39+
if (2 > \func_num_args() || func_get_arg(1)) {
40+
trigger_deprecation('symfony/security', '5.4', 'The third element in the return value of "%s()" is deprecated', __METHOD__);
41+
}
42+
3943
foreach ($this->map as $elements) {
4044
if (null === $elements[0] || $elements[0]->matches($request)) {
4145
return [$elements[1], $elements[2], $elements[3]];

src/Symfony/Component/Security/Http/FirewallMapInterface.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ interface FirewallMapInterface
3333
* If there is no logout listener, the third element of the outer array
3434
* must be null.
3535
*
36+
* The third element of the outer array is deprecated since Symfony 5.4. It
37+
* will be removed in Symfony 6.0 and instead the LogoutListener will be
38+
* included in the first element.
39+
*
3640
* @return array of the format [[AuthenticationListener], ExceptionListener, LogoutListener]
3741
*/
3842
public function getListeners(Request $request);

src/Symfony/Component/Security/Http/Tests/FirewallMapTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function testGetListeners()
5555

5656
$map->add($tooLateMatcher, [function () {}]);
5757

58-
[$listeners, $exception] = $map->getListeners($request);
58+
[$listeners, $exception] = $map->getListeners($request, false);
5959

6060
$this->assertEquals([$theListener], $listeners);
6161
$this->assertEquals($theException, $exception);
@@ -90,7 +90,7 @@ public function testGetListenersWithAnEntryHavingNoRequestMatcher()
9090

9191
$map->add($tooLateMatcher, [function () {}]);
9292

93-
[$listeners, $exception] = $map->getListeners($request);
93+
[$listeners, $exception] = $map->getListeners($request, false);
9494

9595
$this->assertEquals([$theListener], $listeners);
9696
$this->assertEquals($theException, $exception);
@@ -112,7 +112,7 @@ public function testGetListenersWithNoMatchingEntry()
112112

113113
$map->add($notMatchingMatcher, [function () {}]);
114114

115-
[$listeners, $exception] = $map->getListeners($request);
115+
[$listeners, $exception] = $map->getListeners($request, false);
116116

117117
$this->assertEquals([], $listeners);
118118
$this->assertNull($exception);

0 commit comments

Comments
 (0)