From fde6c62f0bb762491a4609829e9b2aff745c2725 Mon Sep 17 00:00:00 2001 From: Amrouche Hamza Date: Wed, 5 Jun 2019 20:10:04 +0200 Subject: [PATCH] [HttpKernel] deprecate the usage of the deprecated events to ease the deletion of them --- .../EventListener/FirewallListener.php | 8 ++++++- .../EventListener/WebDebugToolbarListener.php | 8 ++++++- .../EventListener/ExceptionListener.php | 14 +++++++++-- .../EventListener/ResponseListener.php | 8 ++++++- .../EventListener/ExceptionListenerTest.php | 24 +++++++++++++++++++ .../Http/Firewall/ContextListener.php | 8 ++++++- 6 files changed, 64 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Bundle/SecurityBundle/EventListener/FirewallListener.php b/src/Symfony/Bundle/SecurityBundle/EventListener/FirewallListener.php index 3dca451d9ab17..706ea57593477 100644 --- a/src/Symfony/Bundle/SecurityBundle/EventListener/FirewallListener.php +++ b/src/Symfony/Bundle/SecurityBundle/EventListener/FirewallListener.php @@ -15,6 +15,8 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpKernel\Event\FinishRequestEvent; use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\KernelEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\Security\Http\Firewall; use Symfony\Component\Security\Http\FirewallMapInterface; @@ -41,8 +43,12 @@ public function __construct(FirewallMapInterface $map, EventDispatcherInterface /** * @internal */ - public function configureLogoutUrlGenerator(GetResponseEvent $event) + public function configureLogoutUrlGenerator(KernelEvent $event) { + if (GetResponseEvent::class === \get_class($event)) { + @trigger_error(sprintf('The %s event has been deprecated since Symfony 4.3 and will be replaced by %s event in Symfony 5.0.', GetResponseEvent::class, RequestEvent::class), E_USER_DEPRECATED); + } + if (!$event->isMasterRequest()) { return; } diff --git a/src/Symfony/Bundle/WebProfilerBundle/EventListener/WebDebugToolbarListener.php b/src/Symfony/Bundle/WebProfilerBundle/EventListener/WebDebugToolbarListener.php index 1541c7113b138..5d0cb53d3d544 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/EventListener/WebDebugToolbarListener.php +++ b/src/Symfony/Bundle/WebProfilerBundle/EventListener/WebDebugToolbarListener.php @@ -17,6 +17,8 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag; use Symfony\Component\HttpKernel\Event\FilterResponseEvent; +use Symfony\Component\HttpKernel\Event\KernelEvent; +use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Twig\Environment; @@ -60,8 +62,12 @@ public function isEnabled() return self::DISABLED !== $this->mode; } - public function onKernelResponse(FilterResponseEvent $event) + public function onKernelResponse(KernelEvent $event) { + if (FilterResponseEvent::class === \get_class($event)) { + @trigger_error(sprintf('The %s event has been deprecated since Symfony 4.3 and will be replaced by %s event in Symfony 5.0.', FilterResponseEvent::class, ResponseEvent::class), E_USER_DEPRECATED); + } + $response = $event->getResponse(); $request = $event->getRequest(); diff --git a/src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php b/src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php index f8044537a8147..4fd457e70dfd3 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php @@ -17,7 +17,9 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Event\ExceptionEvent; use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; +use Symfony\Component\HttpKernel\Event\KernelEvent; use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\KernelEvents; @@ -41,8 +43,12 @@ public function __construct($controller, LoggerInterface $logger = null, $debug $this->debug = $debug; } - public function logKernelException(GetResponseForExceptionEvent $event) + public function logKernelException(KernelEvent $event) { + if (GetResponseForExceptionEvent::class === \get_class($event)) { + @trigger_error(sprintf('The %s event has been deprecated since Symfony 4.3 and will be replaced by %s event in Symfony 5.0.', GetResponseForExceptionEvent::class, ExceptionEvent::class), E_USER_DEPRECATED); + } + $e = FlattenException::create($event->getException()); $this->logException($event->getException(), sprintf('Uncaught PHP Exception %s: "%s" at %s line %s', $e->getClass(), $e->getMessage(), $e->getFile(), $e->getLine())); @@ -52,8 +58,12 @@ public function logKernelException(GetResponseForExceptionEvent $event) * @param string $eventName * @param EventDispatcherInterface $eventDispatcher */ - public function onKernelException(GetResponseForExceptionEvent $event) + public function onKernelException(KernelEvent $event) { + if (GetResponseForExceptionEvent::class === \get_class($event)) { + @trigger_error(sprintf('The %s event has been deprecated since Symfony 4.3 and will be replaced by %s event in Symfony 5.0.', GetResponseForExceptionEvent::class, ExceptionEvent::class), E_USER_DEPRECATED); + } + if (null === $this->controller) { return; } diff --git a/src/Symfony/Component/HttpKernel/EventListener/ResponseListener.php b/src/Symfony/Component/HttpKernel/EventListener/ResponseListener.php index 01973e222a097..9a7180bc4c006 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/ResponseListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/ResponseListener.php @@ -13,6 +13,8 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpKernel\Event\FilterResponseEvent; +use Symfony\Component\HttpKernel\Event\KernelEvent; +use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\HttpKernel\KernelEvents; /** @@ -34,8 +36,12 @@ public function __construct(string $charset) /** * Filters the Response. */ - public function onKernelResponse(FilterResponseEvent $event) + public function onKernelResponse(KernelEvent $event) { + if (FilterResponseEvent::class === \get_class($event)) { + @trigger_error(sprintf('The %s event has been deprecated since Symfony 4.3 and will be replaced by %s event in Symfony 5.0.', FilterResponseEvent::class, ResponseEvent::class), E_USER_DEPRECATED); + } + if (!$event->isMasterRequest()) { return; } diff --git a/src/Symfony/Component/HttpKernel/Tests/EventListener/ExceptionListenerTest.php b/src/Symfony/Component/HttpKernel/Tests/EventListener/ExceptionListenerTest.php index 2048fdd01cc10..ed5e72d3aee3c 100644 --- a/src/Symfony/Component/HttpKernel/Tests/EventListener/ExceptionListenerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/EventListener/ExceptionListenerTest.php @@ -16,6 +16,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Event\ExceptionEvent; +use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\HttpKernel\EventListener\ExceptionListener; use Symfony\Component\HttpKernel\HttpKernelInterface; @@ -130,6 +131,29 @@ public function testSubRequestFormat() $this->assertEquals('xml', $response->getContent()); } + /** + * @group legacy + * @expectedDeprecation The Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent event has been deprecated since Symfony 4.3 and will be replaced by Symfony\Component\HttpKernel\Event\ExceptionEvent event in Symfony 5.0. + */ + public function testPassingShouldTriggerDeprecated() + { + $listener = new ExceptionListener('foo', $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock()); + + $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(); + $kernel->expects($this->once())->method('handle')->willReturnCallback(function (Request $request) { + return new Response($request->getRequestFormat()); + }); + + $request = Request::create('/'); + $request->setRequestFormat('xml'); + + $event = new GetResponseForExceptionEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, new \Exception('foo')); + $listener->onKernelException($event); + + $response = $event->getResponse(); + $this->assertEquals('xml', $response->getContent()); + } + public function testCSPHeaderIsRemoved() { $dispatcher = new EventDispatcher(); diff --git a/src/Symfony/Component/Security/Http/Firewall/ContextListener.php b/src/Symfony/Component/Security/Http/Firewall/ContextListener.php index 16cdc8f9e23f8..29accd9ed2d11 100644 --- a/src/Symfony/Component/Security/Http/Firewall/ContextListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/ContextListener.php @@ -14,7 +14,9 @@ use Psr\Log\LoggerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpKernel\Event\FilterResponseEvent; +use Symfony\Component\HttpKernel\Event\KernelEvent; use Symfony\Component\HttpKernel\Event\RequestEvent; +use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolver; use Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface; @@ -123,8 +125,12 @@ public function __invoke(RequestEvent $event) /** * Writes the security token into the session. */ - public function onKernelResponse(FilterResponseEvent $event) + public function onKernelResponse(KernelEvent $event) { + if (FilterResponseEvent::class === \get_class($event)) { + @trigger_error(sprintf('The %s class has been deprecated since Symfony 4.3 and will be replaced by %s in Symfony 5.0.', FilterResponseEvent::class, ResponseEvent::class), E_USER_DEPRECATED); + } + if (!$event->isMasterRequest()) { return; } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy