Skip to content

Commit bc1a0bd

Browse files
minor #31918 [HttpKernel] remove all deprecated event and replace their use (Simperfit, nicolas-grekas)
This PR was merged into the 5.0-dev branch. Discussion ---------- [HttpKernel] remove all deprecated event and replace their use | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | none <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR |to check<!-- required for new features --> <!-- Replace this notice by a short README for your feature/bugfix. This will help people understand your PR and can be used as a start for the documentation. Additionally (see https://symfony.com/roadmap): - Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too). - Features and deprecations must be submitted against the master branch. --> Extract the whole event & listener part from #31672 (comment) to its own PR to ease the removal of deprecated code from HttpKernel. Commits ------- be5f641 Fix annotations 48073dd [HttpKernel] remove all deprecated event and replace their use
2 parents d81ab9b + be5f641 commit bc1a0bd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+334
-581
lines changed

UPGRADE-5.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ HttpKernel
266266
* Removed `PostResponseEvent`, use `TerminateEvent` instead
267267
* Removed `TranslatorListener` in favor of `LocaleAwareListener`
268268
* The `DebugHandlersListener` class has been made `final`
269+
* Removed `SaveSessionListener` in favor of `AbstractSessionListener`
269270

270271
Intl
271272
----

src/Symfony/Bridge/Monolog/Handler/ChromePhpHandler.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313

1414
use Monolog\Handler\ChromePHPHandler as BaseChromePhpHandler;
1515
use Symfony\Component\HttpFoundation\Response;
16-
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
16+
use Symfony\Component\HttpKernel\Event\ResponseEvent;
1717

1818
/**
1919
* ChromePhpHandler.
2020
*
2121
* @author Christophe Coevoet <stof@notk.org>
2222
*
23-
* @final since Symfony 4.3
23+
* @final
2424
*/
2525
class ChromePhpHandler extends BaseChromePhpHandler
2626
{
@@ -34,7 +34,7 @@ class ChromePhpHandler extends BaseChromePhpHandler
3434
/**
3535
* Adds the headers to the response once it's created.
3636
*/
37-
public function onKernelResponse(FilterResponseEvent $event)
37+
public function onKernelResponse(ResponseEvent $event)
3838
{
3939
if (!$event->isMasterRequest()) {
4040
return;

src/Symfony/Bridge/Monolog/Handler/FirePHPHandler.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313

1414
use Monolog\Handler\FirePHPHandler as BaseFirePHPHandler;
1515
use Symfony\Component\HttpFoundation\Response;
16-
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
16+
use Symfony\Component\HttpKernel\Event\ResponseEvent;
1717

1818
/**
1919
* FirePHPHandler.
2020
*
2121
* @author Jordi Boggiano <j.boggiano@seld.be>
2222
*
23-
* @final since Symfony 4.3
23+
* @final
2424
*/
2525
class FirePHPHandler extends BaseFirePHPHandler
2626
{
@@ -34,7 +34,7 @@ class FirePHPHandler extends BaseFirePHPHandler
3434
/**
3535
* Adds the headers to the response once it's created.
3636
*/
37-
public function onKernelResponse(FilterResponseEvent $event)
37+
public function onKernelResponse(ResponseEvent $event)
3838
{
3939
if (!$event->isMasterRequest()) {
4040
return;

src/Symfony/Bridge/Monolog/Handler/SwiftMailerHandler.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313

1414
use Monolog\Handler\SwiftMailerHandler as BaseSwiftMailerHandler;
1515
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
16-
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
16+
use Symfony\Component\HttpKernel\Event\TerminateEvent;
1717

1818
/**
1919
* Extended SwiftMailerHandler that flushes mail queue if necessary.
2020
*
2121
* @author Philipp Kräutli <pkraeutli@astina.ch>
2222
*
23-
* @final since Symfony 4.3
23+
* @final
2424
*/
2525
class SwiftMailerHandler extends BaseSwiftMailerHandler
2626
{
@@ -36,7 +36,7 @@ public function setTransport(\Swift_Transport $transport)
3636
/**
3737
* After the kernel has been terminated we will always flush messages.
3838
*/
39-
public function onKernelTerminate(PostResponseEvent $event)
39+
public function onKernelTerminate(TerminateEvent $event)
4040
{
4141
$this->instantFlush = true;
4242
}

src/Symfony/Bridge/Monolog/Processor/RouteProcessor.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1515
use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
16-
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
16+
use Symfony\Component\HttpKernel\Event\RequestEvent;
1717
use Symfony\Component\HttpKernel\KernelEvents;
1818
use Symfony\Contracts\Service\ResetInterface;
1919

@@ -22,7 +22,7 @@
2222
*
2323
* @author Piotr Stankowski <git@trakos.pl>
2424
*
25-
* @final since Symfony 4.4
25+
* @final
2626
*/
2727
class RouteProcessor implements EventSubscriberInterface, ResetInterface
2828
{
@@ -49,7 +49,7 @@ public function reset()
4949
$this->routeData = [];
5050
}
5151

52-
public function addRouteData(GetResponseEvent $event)
52+
public function addRouteData(RequestEvent $event)
5353
{
5454
if ($event->isMasterRequest()) {
5555
$this->reset();

src/Symfony/Bridge/Monolog/Processor/WebProcessor.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313

1414
use Monolog\Processor\WebProcessor as BaseWebProcessor;
1515
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
16-
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
16+
use Symfony\Component\HttpKernel\Event\ResponseEvent;
1717
use Symfony\Component\HttpKernel\KernelEvents;
1818

1919
/**
2020
* WebProcessor override to read from the HttpFoundation's Request.
2121
*
2222
* @author Jordi Boggiano <j.boggiano@seld.be>
2323
*
24-
* @final since Symfony 4.3
24+
* @final
2525
*/
2626
class WebProcessor extends BaseWebProcessor implements EventSubscriberInterface
2727
{
@@ -31,7 +31,7 @@ public function __construct(array $extraFields = null)
3131
parent::__construct([], $extraFields);
3232
}
3333

34-
public function onKernelRequest(GetResponseEvent $event)
34+
public function onKernelRequest(ResponseEvent $event)
3535
{
3636
if ($event->isMasterRequest()) {
3737
$this->serverData = $event->getRequest()->server->all();

src/Symfony/Bridge/Monolog/Tests/Processor/RouteProcessorTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Symfony\Component\HttpFoundation\ParameterBag;
1717
use Symfony\Component\HttpFoundation\Request;
1818
use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
19-
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
19+
use Symfony\Component\HttpKernel\Event\RequestEvent;
2020

2121
class RouteProcessorTest extends TestCase
2222
{
@@ -122,9 +122,9 @@ public function testProcessorDoesNothingWhenNoRequest()
122122
$this->assertEquals(['extra' => []], $record);
123123
}
124124

125-
private function mockGetResponseEvent(Request $request): GetResponseEvent
125+
private function mockGetResponseEvent(Request $request): RequestEvent
126126
{
127-
$event = $this->getMockBuilder(GetResponseEvent::class)->disableOriginalConstructor()->getMock();
127+
$event = $this->getMockBuilder(RequestEvent::class)->disableOriginalConstructor()->getMock();
128128
$event->method('getRequest')->willReturn($request);
129129

130130
return $event;

src/Symfony/Bridge/Monolog/Tests/Processor/WebProcessorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use PHPUnit\Framework\TestCase;
1616
use Symfony\Bridge\Monolog\Processor\WebProcessor;
1717
use Symfony\Component\HttpFoundation\Request;
18-
use Symfony\Component\HttpKernel\Event\RequestEvent;
18+
use Symfony\Component\HttpKernel\Event\ResponseEvent;
1919

2020
class WebProcessorTest extends TestCase
2121
{
@@ -88,7 +88,7 @@ private function createRequestEvent($additionalServerParameters = []): array
8888
$request->server->replace($server);
8989
$request->headers->replace($server);
9090

91-
$event = $this->getMockBuilder(RequestEvent::class)
91+
$event = $this->getMockBuilder(ResponseEvent::class)
9292
->disableOriginalConstructor()
9393
->getMock();
9494
$event->expects($this->any())

src/Symfony/Bundle/FrameworkBundle/Tests/Kernel/ConcreteMicroKernel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
2020
use Symfony\Component\Filesystem\Filesystem;
2121
use Symfony\Component\HttpFoundation\Response;
22-
use Symfony\Component\HttpKernel\Event\RequestEvent;
22+
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
2323
use Symfony\Component\HttpKernel\Kernel;
2424
use Symfony\Component\HttpKernel\KernelEvents;
2525
use Symfony\Component\Routing\RouteCollectionBuilder;
@@ -30,7 +30,7 @@ class ConcreteMicroKernel extends Kernel implements EventSubscriberInterface
3030

3131
private $cacheDir;
3232

33-
public function onKernelException(RequestEvent $event)
33+
public function onKernelException(ExceptionEvent $event)
3434
{
3535
if ($event->getException() instanceof Danger) {
3636
$event->setResponse(Response::create('It\'s dangerous to go alone. Take this ⚔'));

src/Symfony/Bundle/SecurityBundle/EventListener/FirewallListener.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
namespace Symfony\Bundle\SecurityBundle\EventListener;
1313

1414
use Symfony\Bundle\SecurityBundle\Security\FirewallMap;
15-
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
1615
use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
17-
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
16+
use Symfony\Component\HttpKernel\Event\RequestEvent;
1817
use Symfony\Component\HttpKernel\KernelEvents;
1918
use Symfony\Component\Security\Http\Firewall;
2019
use Symfony\Component\Security\Http\FirewallMapInterface;
2120
use Symfony\Component\Security\Http\Logout\LogoutUrlGenerator;
21+
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
2222

2323
/**
2424
* @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
@@ -30,18 +30,13 @@ class FirewallListener extends Firewall
3030

3131
public function __construct(FirewallMapInterface $map, EventDispatcherInterface $dispatcher, LogoutUrlGenerator $logoutUrlGenerator)
3232
{
33-
// the type-hint will be updated to the "EventDispatcherInterface" from symfony/contracts in 5.0
34-
3533
$this->map = $map;
3634
$this->logoutUrlGenerator = $logoutUrlGenerator;
3735

3836
parent::__construct($map, $dispatcher);
3937
}
4038

41-
/**
42-
* @internal
43-
*/
44-
public function configureLogoutUrlGenerator(GetResponseEvent $event)
39+
public function onKernelRequest(RequestEvent $event)
4540
{
4641
if (!$event->isMasterRequest()) {
4742
return;
@@ -50,11 +45,10 @@ public function configureLogoutUrlGenerator(GetResponseEvent $event)
5045
if ($this->map instanceof FirewallMap && $config = $this->map->getFirewallConfig($event->getRequest())) {
5146
$this->logoutUrlGenerator->setCurrentFirewall($config->getName(), $config->getContext());
5247
}
48+
49+
parent::onKernelRequest($event);
5350
}
5451

55-
/**
56-
* @internal since Symfony 4.3
57-
*/
5852
public function onKernelFinishRequest(FinishRequestEvent $event)
5953
{
6054
if ($event->isMasterRequest()) {
@@ -71,7 +65,6 @@ public static function getSubscribedEvents()
7165
{
7266
return [
7367
KernelEvents::REQUEST => [
74-
['configureLogoutUrlGenerator', 8],
7568
['onKernelRequest', 8],
7669
],
7770
KernelEvents::FINISH_REQUEST => 'onKernelFinishRequest',

0 commit comments

Comments
 (0)