Skip to content

[HttpKernel] deprecate the usage of the deprecated events to ease deleting them #31886

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()));
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down