From 75369dabb8af73b0d0ad7f206d85c08cf39117f8 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 18 Oct 2018 22:44:28 +0200 Subject: [PATCH] [EventDispatcher] swap arguments of dispatch() to allow registering events by FQCN --- UPGRADE-4.3.md | 16 +- UPGRADE-5.0.md | 10 ++ .../MergeDoctrineCollectionListenerTest.php | 4 +- .../Monolog/Handler/ChromePhpHandler.php | 2 + .../Bridge/Monolog/Handler/FirePHPHandler.php | 2 + .../Monolog/Handler/SwiftMailerHandler.php | 2 + .../Bridge/Monolog/Processor/WebProcessor.php | 2 + .../Tests/Handler/ConsoleHandlerTest.php | 4 +- .../Tests/Processor/WebProcessorTest.php | 3 +- src/Symfony/Bridge/Monolog/composer.json | 4 +- .../Resources/config/services.xml | 32 ++++ .../ResolveControllerNameSubscriberTest.php | 6 +- .../Bundle/FrameworkBundle/composer.json | 1 - .../Debug/TraceableFirewallListener.php | 6 +- .../SecurityBundle/Debug/WrappedListener.php | 23 ++- .../EventListener/FirewallListener.php | 25 ++- .../SecurityDataCollectorTest.php | 15 +- .../Debug/TraceableFirewallListenerTest.php | 15 +- .../Tests/Security/FirewallContextTest.php | 8 +- .../Tests/Security/FirewallMapTest.php | 3 +- .../Bundle/SecurityBundle/composer.json | 6 +- .../EventListener/WebDebugToolbarListener.php | 2 + .../WebDebugToolbarListenerTest.php | 28 ++-- .../Bundle/WebProfilerBundle/composer.json | 3 +- src/Symfony/Component/Console/Application.php | 13 +- src/Symfony/Component/Console/composer.json | 3 +- .../Component/EventDispatcher/CHANGELOG.md | 5 + .../Debug/TraceableEventDispatcher.php | 24 ++- .../RegisterListenersPass.php | 22 ++- .../EventDispatcher/EventDispatcher.php | 19 ++- .../EventDispatcherInterface.php | 10 +- .../ImmutableEventDispatcher.php | 17 ++- .../LegacyEventDispatcherProxy.php | 142 ++++++++++++++++++ .../Debug/TraceableEventDispatcherTest.php | 36 ++--- .../Tests/EventDispatcherTest.php | 24 +-- .../Tests/ImmutableEventDispatcherTest.php | 4 +- .../Tests/LegacyEventDispatcherTest.php | 36 +++++ src/Symfony/Component/Form/CHANGELOG.md | 5 + .../Component/Form/Event/PostSetDataEvent.php | 23 +++ .../Component/Form/Event/PostSubmitEvent.php | 24 +++ .../Component/Form/Event/PreSetDataEvent.php | 25 +++ .../Component/Form/Event/PreSubmitEvent.php | 25 +++ .../Component/Form/Event/SubmitEvent.php | 24 +++ src/Symfony/Component/Form/Form.php | 30 ++-- src/Symfony/Component/Form/FormEvents.php | 10 +- src/Symfony/Component/Form/composer.json | 2 +- src/Symfony/Component/HttpKernel/CHANGELOG.md | 7 + .../DataCollector/RequestDataCollector.php | 6 + .../DataCollector/RouterDataCollector.php | 4 +- .../Event/ControllerArgumentsEvent.php | 28 ++++ .../HttpKernel/Event/ControllerEvent.php | 27 ++++ .../HttpKernel/Event/ExceptionEvent.php | 29 ++++ .../Event/FilterControllerArgumentsEvent.php | 13 +- .../Event/FilterControllerEvent.php | 10 +- .../HttpKernel/Event/FilterResponseEvent.php | 8 +- .../HttpKernel/Event/GetResponseEvent.php | 8 +- .../GetResponseForControllerResultEvent.php | 10 +- .../Event/GetResponseForExceptionEvent.php | 14 +- .../HttpKernel/Event/PostResponseEvent.php | 7 +- .../HttpKernel/Event/RequestEvent.php | 25 +++ .../HttpKernel/Event/ResponseEvent.php | 25 +++ .../HttpKernel/Event/TerminateEvent.php | 24 +++ .../Component/HttpKernel/Event/ViewEvent.php | 25 +++ .../EventListener/AbstractSessionListener.php | 2 + .../AbstractTestSessionListener.php | 2 + .../AddRequestFormatsListener.php | 2 + .../DisallowRobotsIndexingListener.php | 4 +- .../EventListener/ExceptionListener.php | 7 +- .../EventListener/FragmentListener.php | 2 + .../EventListener/LocaleListener.php | 2 + .../EventListener/ProfilerListener.php | 2 + .../EventListener/ResponseListener.php | 2 + .../EventListener/RouterListener.php | 2 + .../StreamedResponseListener.php | 2 + .../EventListener/SurrogateListener.php | 2 + .../EventListener/TranslatorListener.php | 2 + .../EventListener/ValidateRequestListener.php | 2 + .../Fragment/InlineFragmentRenderer.php | 9 +- .../Component/HttpKernel/HttpKernel.php | 45 +++--- .../Component/HttpKernel/KernelEvents.php | 14 +- .../RequestDataCollectorTest.php | 8 +- .../Debug/TraceableEventDispatcherTest.php | 7 +- .../Event/ControllerArgumentsEventTest.php | 17 +++ ...onEventTest.php => ExceptionEventTest.php} | 6 +- .../FilterControllerArgumentsEventTest.php | 17 --- .../AddRequestFormatsListenerTest.php | 7 +- .../DebugHandlersListenerTest.php | 2 +- .../DisallowRobotsIndexingListenerTest.php | 4 +- .../EventListener/ExceptionListenerTest.php | 20 +-- .../EventListener/FragmentListenerTest.php | 20 +-- .../EventListener/LocaleListenerTest.php | 6 +- .../EventListener/ProfilerListenerTest.php | 14 +- .../EventListener/ResponseListenerTest.php | 18 +-- .../EventListener/RouterListenerTest.php | 30 ++-- .../EventListener/SaveSessionListenerTest.php | 6 +- .../EventListener/SessionListenerTest.php | 26 ++-- .../EventListener/SurrogateListenerTest.php | 14 +- .../EventListener/TestSessionListenerTest.php | 20 +-- .../EventListener/TranslatorListenerTest.php | 6 +- .../ValidateRequestListenerTest.php | 6 +- .../Fragment/InlineFragmentRendererTest.php | 11 +- .../HttpKernel/Tests/HttpKernelTest.php | 8 +- .../Component/HttpKernel/composer.json | 2 +- src/Symfony/Component/Security/CHANGELOG.md | 6 + .../AuthenticationProviderManager.php | 9 +- .../Security/Core/AuthenticationEvents.php | 2 +- .../Core/Event/AuthenticationSuccessEvent.php | 16 ++ .../AuthenticationProviderManagerTest.php | 6 +- .../Component/Security/Core/composer.json | 3 +- .../Firewall/GuardAuthenticationListener.php | 11 +- .../Guard/GuardAuthenticatorHandler.php | 5 +- .../GuardAuthenticationListenerTest.php | 14 +- .../Tests/GuardAuthenticatorHandlerTest.php | 2 +- .../Component/Security/Guard/composer.json | 2 +- .../Component/Security/Http/Firewall.php | 28 +++- .../AbstractAuthenticationListener.php | 13 +- .../AbstractPreAuthenticatedListener.php | 13 +- .../Security/Http/Firewall/AccessListener.php | 8 +- .../AnonymousAuthenticationListener.php | 8 +- .../Firewall/BasicAuthenticationListener.php | 8 +- .../Http/Firewall/ChannelListener.php | 8 +- .../Http/Firewall/ContextListener.php | 8 +- .../Http/Firewall/ExceptionListener.php | 2 + .../Http/Firewall/LegacyListenerTrait.php | 60 ++++++++ .../Http/Firewall/ListenerInterface.php | 2 + .../Security/Http/Firewall/LogoutListener.php | 8 +- .../Http/Firewall/RememberMeListener.php | 13 +- .../SimplePreAuthenticationListener.php | 11 +- .../Http/Firewall/SwitchUserListener.php | 15 +- ...namePasswordJsonAuthenticationListener.php | 13 +- .../Http/RememberMe/ResponseListener.php | 2 + .../AbstractPreAuthenticatedListenerTest.php | 21 +-- .../Tests/Firewall/AccessListenerTest.php | 17 ++- .../AnonymousAuthenticationListenerTest.php | 7 +- .../BasicAuthenticationListenerTest.php | 21 +-- .../Tests/Firewall/ChannelListenerTest.php | 17 ++- .../Tests/Firewall/ContextListenerTest.php | 47 +++--- .../Tests/Firewall/ExceptionListenerTest.php | 7 +- .../Tests/Firewall/LogoutListenerTest.php | 13 +- .../Tests/Firewall/RememberMeListenerTest.php | 30 ++-- .../SimplePreAuthenticationListenerTest.php | 9 +- .../Tests/Firewall/SwitchUserListenerTest.php | 45 +++--- ...PasswordFormAuthenticationListenerTest.php | 22 +-- ...PasswordJsonAuthenticationListenerTest.php | 62 ++++---- .../Security/Http/Tests/FirewallMapTest.php | 14 +- .../Security/Http/Tests/FirewallTest.php | 30 ++-- .../Tests/RememberMe/ResponseListenerTest.php | 3 +- .../Component/Security/Http/composer.json | 5 +- src/Symfony/Component/Security/composer.json | 3 +- .../EventListener/AddLinkHeaderListener.php | 4 +- .../AddLinkHeaderListenerTest.php | 4 +- src/Symfony/Component/WebLink/composer.json | 6 +- src/Symfony/Component/Workflow/CHANGELOG.md | 7 + .../Workflow/Event/AnnounceEvent.php | 16 ++ .../Workflow/Event/CompletedEvent.php | 16 ++ .../Component/Workflow/Event/EnterEvent.php | 16 ++ .../Component/Workflow/Event/EnteredEvent.php | 16 ++ .../Component/Workflow/Event/LeaveEvent.php | 16 ++ .../Workflow/Event/TransitionEvent.php | 16 ++ .../Component/Workflow/Tests/WorkflowTest.php | 2 +- src/Symfony/Component/Workflow/Workflow.php | 63 ++++---- .../Component/Workflow/WorkflowEvents.php | 58 +++++++ src/Symfony/Component/Workflow/composer.json | 5 +- 163 files changed, 1649 insertions(+), 658 deletions(-) create mode 100644 src/Symfony/Component/EventDispatcher/LegacyEventDispatcherProxy.php create mode 100644 src/Symfony/Component/EventDispatcher/Tests/LegacyEventDispatcherTest.php create mode 100644 src/Symfony/Component/Form/Event/PostSetDataEvent.php create mode 100644 src/Symfony/Component/Form/Event/PostSubmitEvent.php create mode 100644 src/Symfony/Component/Form/Event/PreSetDataEvent.php create mode 100644 src/Symfony/Component/Form/Event/PreSubmitEvent.php create mode 100644 src/Symfony/Component/Form/Event/SubmitEvent.php create mode 100644 src/Symfony/Component/HttpKernel/Event/ControllerArgumentsEvent.php create mode 100644 src/Symfony/Component/HttpKernel/Event/ControllerEvent.php create mode 100644 src/Symfony/Component/HttpKernel/Event/ExceptionEvent.php create mode 100644 src/Symfony/Component/HttpKernel/Event/RequestEvent.php create mode 100644 src/Symfony/Component/HttpKernel/Event/ResponseEvent.php create mode 100644 src/Symfony/Component/HttpKernel/Event/TerminateEvent.php create mode 100644 src/Symfony/Component/HttpKernel/Event/ViewEvent.php create mode 100644 src/Symfony/Component/HttpKernel/Tests/Event/ControllerArgumentsEventTest.php rename src/Symfony/Component/HttpKernel/Tests/Event/{GetResponseForExceptionEventTest.php => ExceptionEventTest.php} (71%) delete mode 100644 src/Symfony/Component/HttpKernel/Tests/Event/FilterControllerArgumentsEventTest.php create mode 100644 src/Symfony/Component/Security/Core/Event/AuthenticationSuccessEvent.php create mode 100644 src/Symfony/Component/Security/Http/Firewall/LegacyListenerTrait.php create mode 100644 src/Symfony/Component/Workflow/Event/AnnounceEvent.php create mode 100644 src/Symfony/Component/Workflow/Event/CompletedEvent.php create mode 100644 src/Symfony/Component/Workflow/Event/EnterEvent.php create mode 100644 src/Symfony/Component/Workflow/Event/EnteredEvent.php create mode 100644 src/Symfony/Component/Workflow/Event/LeaveEvent.php create mode 100644 src/Symfony/Component/Workflow/Event/TransitionEvent.php create mode 100644 src/Symfony/Component/Workflow/WorkflowEvents.php diff --git a/UPGRADE-4.3.md b/UPGRADE-4.3.md index a6a4d2e307dc..54aaefec2581 100644 --- a/UPGRADE-4.3.md +++ b/UPGRADE-4.3.md @@ -21,6 +21,11 @@ Config * Deprecated using environment variables with `cannotBeEmpty()` if the value is validated with `validate()` +EventDispatcher +--------------- + + * The signature of the `EventDispatcherInterface::dispatch()` method should be updated to `dispatch($event, string $eventName = null)`, not doing so is deprecated + Form ---- @@ -55,7 +60,14 @@ HttpFoundation HttpKernel ---------- - * renamed `Client` to `HttpKernelBrowser` + * Renamed `Client` to `HttpKernelBrowser` + * Renamed `FilterControllerArgumentsEvent` to `ControllerArgumentsEvent` + * Renamed `FilterControllerEvent` to `ControllerEvent` + * Renamed `FilterResponseEvent` to `ResponseEvent` + * Renamed `GetResponseEvent` to `RequestEvent` + * Renamed `GetResponseForControllerResultEvent` to `ViewEvent` + * Renamed `GetResponseForExceptionEvent` to `ExceptionEvent` + * Renamed `PostResponseEvent` to `TerminateEvent` Messenger --------- @@ -80,6 +92,8 @@ Security Use the `getReachableRoleNames()` method instead. * The `getRoles()` method of the `TokenInterface` is deprecated. Tokens must implement the `getRoleNames()` method instead and return roles as strings. + * The `ListenerInterface` is deprecated, turn your listeners into callables instead. + * The `Firewall::handleRequest()` method is deprecated, use `Firewall::callListeners()` instead. * The `AbstractToken::serialize()`, `AbstractToken::unserialize()`, `AuthenticationException::serialize()` and `AuthenticationException::unserialize()` methods are now final, use `getState()` and `setState()` instead. diff --git a/UPGRADE-5.0.md b/UPGRADE-5.0.md index 1805e312e474..a2d8c4e62ad6 100644 --- a/UPGRADE-5.0.md +++ b/UPGRADE-5.0.md @@ -70,6 +70,7 @@ EventDispatcher --------------- * The `TraceableEventDispatcherInterface` has been removed. + * The signature of the `EventDispatcherInterface::dispatch()` method has been updated to `dispatch($event, string $eventName = null)` Filesystem ---------- @@ -206,6 +207,13 @@ HttpKernel * Removed the first and second constructor argument of `ConfigDataCollector` * Removed `ConfigDataCollector::getApplicationName()` * Removed `ConfigDataCollector::getApplicationVersion()` + * Removed `FilterControllerArgumentsEvent`, use `ControllerArgumentsEvent` instead + * Removed `FilterControllerEvent`, use `ControllerEvent` instead + * Removed `FilterResponseEvent`, use `ResponseEvent` instead + * Removed `GetResponseEvent`, use `RequestEvent` instead + * Removed `GetResponseForControllerResultEvent`, use `ViewEvent` instead + * Removed `GetResponseForExceptionEvent`, use `ExceptionEvent` instead + * Removed `PostResponseEvent`, use `TerminateEvent` instead Monolog ------- @@ -257,6 +265,8 @@ Security * `SimpleAuthenticatorInterface`, `SimpleFormAuthenticatorInterface`, `SimplePreAuthenticatorInterface`, `SimpleAuthenticationProvider`, `SimpleAuthenticationHandler`, `SimpleFormAuthenticationListener` and `SimplePreAuthenticationListener` have been removed. Use Guard instead. + * The `ListenerInterface` has been removed, turn your listeners into callables instead. + * The `Firewall::handleRequest()` method has been removed, use `Firewall::callListeners()` instead. * `\Serializable` interface has been removed from `AbstractToken` and `AuthenticationException`, thus `serialize()` and `unserialize()` aren't available. Use `getState()` and `setState()` instead. diff --git a/src/Symfony/Bridge/Doctrine/Tests/Form/EventListener/MergeDoctrineCollectionListenerTest.php b/src/Symfony/Bridge/Doctrine/Tests/Form/EventListener/MergeDoctrineCollectionListenerTest.php index e9994b5c9d24..757cdc3934c9 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Form/EventListener/MergeDoctrineCollectionListenerTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Form/EventListener/MergeDoctrineCollectionListenerTest.php @@ -63,7 +63,7 @@ public function testOnSubmitDoNothing() $submittedData = ['test']; $event = new FormEvent($this->getForm(), $submittedData); - $this->dispatcher->dispatch(FormEvents::SUBMIT, $event); + $this->dispatcher->dispatch($event, FormEvents::SUBMIT); $this->assertTrue($this->collection->contains('test')); $this->assertSame(1, $this->collection->count()); @@ -74,7 +74,7 @@ public function testOnSubmitNullClearCollection() $submittedData = []; $event = new FormEvent($this->getForm(), $submittedData); - $this->dispatcher->dispatch(FormEvents::SUBMIT, $event); + $this->dispatcher->dispatch($event, FormEvents::SUBMIT); $this->assertTrue($this->collection->isEmpty()); } diff --git a/src/Symfony/Bridge/Monolog/Handler/ChromePhpHandler.php b/src/Symfony/Bridge/Monolog/Handler/ChromePhpHandler.php index c27b0803e200..4f98d58b1ffb 100644 --- a/src/Symfony/Bridge/Monolog/Handler/ChromePhpHandler.php +++ b/src/Symfony/Bridge/Monolog/Handler/ChromePhpHandler.php @@ -19,6 +19,8 @@ * ChromePhpHandler. * * @author Christophe Coevoet + * + * @final since Symfony 4.3 */ class ChromePhpHandler extends BaseChromePhpHandler { diff --git a/src/Symfony/Bridge/Monolog/Handler/FirePHPHandler.php b/src/Symfony/Bridge/Monolog/Handler/FirePHPHandler.php index 9c3ec5f98144..b235fc101ea7 100644 --- a/src/Symfony/Bridge/Monolog/Handler/FirePHPHandler.php +++ b/src/Symfony/Bridge/Monolog/Handler/FirePHPHandler.php @@ -19,6 +19,8 @@ * FirePHPHandler. * * @author Jordi Boggiano + * + * @final since Symfony 4.3 */ class FirePHPHandler extends BaseFirePHPHandler { diff --git a/src/Symfony/Bridge/Monolog/Handler/SwiftMailerHandler.php b/src/Symfony/Bridge/Monolog/Handler/SwiftMailerHandler.php index c912614a2abb..93f2f72e6457 100644 --- a/src/Symfony/Bridge/Monolog/Handler/SwiftMailerHandler.php +++ b/src/Symfony/Bridge/Monolog/Handler/SwiftMailerHandler.php @@ -19,6 +19,8 @@ * Extended SwiftMailerHandler that flushes mail queue if necessary. * * @author Philipp Kräutli + * + * @final since Symfony 4.3 */ class SwiftMailerHandler extends BaseSwiftMailerHandler { diff --git a/src/Symfony/Bridge/Monolog/Processor/WebProcessor.php b/src/Symfony/Bridge/Monolog/Processor/WebProcessor.php index 8bf8cec3dfeb..71bf71a81632 100644 --- a/src/Symfony/Bridge/Monolog/Processor/WebProcessor.php +++ b/src/Symfony/Bridge/Monolog/Processor/WebProcessor.php @@ -20,6 +20,8 @@ * WebProcessor override to read from the HttpFoundation's Request. * * @author Jordi Boggiano + * + * @final since Symfony 4.3 */ class WebProcessor extends BaseWebProcessor implements EventSubscriberInterface { diff --git a/src/Symfony/Bridge/Monolog/Tests/Handler/ConsoleHandlerTest.php b/src/Symfony/Bridge/Monolog/Tests/Handler/ConsoleHandlerTest.php index 00106c54e162..192238c83934 100644 --- a/src/Symfony/Bridge/Monolog/Tests/Handler/ConsoleHandlerTest.php +++ b/src/Symfony/Bridge/Monolog/Tests/Handler/ConsoleHandlerTest.php @@ -196,12 +196,12 @@ public function testLogsFromListeners() }); $event = new ConsoleCommandEvent(new Command('foo'), $this->getMockBuilder('Symfony\Component\Console\Input\InputInterface')->getMock(), $output); - $dispatcher->dispatch(ConsoleEvents::COMMAND, $event); + $dispatcher->dispatch($event, ConsoleEvents::COMMAND); $this->assertContains('Before command message.', $out = $output->fetch()); $this->assertContains('After command message.', $out); $event = new ConsoleTerminateEvent(new Command('foo'), $this->getMockBuilder('Symfony\Component\Console\Input\InputInterface')->getMock(), $output, 0); - $dispatcher->dispatch(ConsoleEvents::TERMINATE, $event); + $dispatcher->dispatch($event, ConsoleEvents::TERMINATE); $this->assertContains('Before terminate message.', $out = $output->fetch()); $this->assertContains('After terminate message.', $out); } diff --git a/src/Symfony/Bridge/Monolog/Tests/Processor/WebProcessorTest.php b/src/Symfony/Bridge/Monolog/Tests/Processor/WebProcessorTest.php index 6b61b5c986fc..0f682e842cad 100644 --- a/src/Symfony/Bridge/Monolog/Tests/Processor/WebProcessorTest.php +++ b/src/Symfony/Bridge/Monolog/Tests/Processor/WebProcessorTest.php @@ -15,6 +15,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Bridge\Monolog\Processor\WebProcessor; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpKernel\Event\RequestEvent; class WebProcessorTest extends TestCase { @@ -87,7 +88,7 @@ private function createRequestEvent($additionalServerParameters = []): array $request->server->replace($server); $request->headers->replace($server); - $event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent') + $event = $this->getMockBuilder(RequestEvent::class) ->disableOriginalConstructor() ->getMock(); $event->expects($this->any()) diff --git a/src/Symfony/Bridge/Monolog/composer.json b/src/Symfony/Bridge/Monolog/composer.json index 2cb3654013d3..81e7b15cd0e1 100644 --- a/src/Symfony/Bridge/Monolog/composer.json +++ b/src/Symfony/Bridge/Monolog/composer.json @@ -19,11 +19,10 @@ "php": "^7.1.3", "monolog/monolog": "~1.19", "symfony/contracts": "^1.0", - "symfony/http-kernel": "~3.4|~4.0" + "symfony/http-kernel": "^4.3" }, "require-dev": { "symfony/console": "~3.4|~4.0", - "symfony/event-dispatcher": "~3.4|~4.0", "symfony/security-core": "~3.4|~4.0", "symfony/var-dumper": "~3.4|~4.0" }, @@ -34,7 +33,6 @@ "suggest": { "symfony/http-kernel": "For using the debugging handlers together with the response life cycle of the HTTP kernel.", "symfony/console": "For the possibility to show log messages in console commands depending on verbosity settings.", - "symfony/event-dispatcher": "Needed when using log messages in console commands.", "symfony/var-dumper": "For using the debugging handlers like the console handler or the log server handler." }, "autoload": { diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml index deaffa5946a2..3f6a854c4bf0 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml @@ -4,6 +4,38 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd"> + + + + console.command + console.error + console.terminate + form.pre_submit + form.submit + form.post_submit + form.pre_set_data + form.post_set_data + kernel.controller_arguments + kernel.controller + kernel.response + kernel.finish_request + kernel.request + kernel.view + kernel.exception + kernel.terminate + security.authentication.success + security.authentication.failure + security.interactive_login + security.switch_user + workflow.guard + workflow.leave + workflow.transition + workflow.enter + workflow.entered + workflow.completed + workflow.announce + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/EventListener/ResolveControllerNameSubscriberTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/EventListener/ResolveControllerNameSubscriberTest.php index 92211dc34132..084e63ca95ea 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/EventListener/ResolveControllerNameSubscriberTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/EventListener/ResolveControllerNameSubscriberTest.php @@ -15,7 +15,7 @@ use Symfony\Bundle\FrameworkBundle\EventListener\ResolveControllerNameSubscriber; use Symfony\Bundle\FrameworkBundle\Tests\TestCase; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; class ResolveControllerNameSubscriberTest extends TestCase @@ -33,7 +33,7 @@ public function testReplacesControllerAttribute() $request->attributes->set('_controller', 'AppBundle:Starting:format'); $subscriber = new ResolveControllerNameSubscriber($parser); - $subscriber->onKernelRequest(new GetResponseEvent($httpKernel, $request, HttpKernelInterface::MASTER_REQUEST)); + $subscriber->onKernelRequest(new RequestEvent($httpKernel, $request, HttpKernelInterface::MASTER_REQUEST)); $this->assertEquals('App\\Final\\Format::methodName', $request->attributes->get('_controller')); } @@ -51,7 +51,7 @@ public function testSkipsOtherControllerFormats($controller) $request->attributes->set('_controller', $controller); $subscriber = new ResolveControllerNameSubscriber($parser); - $subscriber->onKernelRequest(new GetResponseEvent($httpKernel, $request, HttpKernelInterface::MASTER_REQUEST)); + $subscriber->onKernelRequest(new RequestEvent($httpKernel, $request, HttpKernelInterface::MASTER_REQUEST)); $this->assertEquals($controller, $request->attributes->get('_controller')); } diff --git a/src/Symfony/Bundle/FrameworkBundle/composer.json b/src/Symfony/Bundle/FrameworkBundle/composer.json index cdf40d12a21f..95f87fee74ce 100644 --- a/src/Symfony/Bundle/FrameworkBundle/composer.json +++ b/src/Symfony/Bundle/FrameworkBundle/composer.json @@ -22,7 +22,6 @@ "symfony/config": "~4.2", "symfony/contracts": "^1.0.2", "symfony/dependency-injection": "^4.3", - "symfony/event-dispatcher": "^4.1", "symfony/http-foundation": "^4.3", "symfony/http-kernel": "^4.3", "symfony/polyfill-mbstring": "~1.0", diff --git a/src/Symfony/Bundle/SecurityBundle/Debug/TraceableFirewallListener.php b/src/Symfony/Bundle/SecurityBundle/Debug/TraceableFirewallListener.php index 7c45a60c1a90..62be170ddc1d 100644 --- a/src/Symfony/Bundle/SecurityBundle/Debug/TraceableFirewallListener.php +++ b/src/Symfony/Bundle/SecurityBundle/Debug/TraceableFirewallListener.php @@ -12,7 +12,7 @@ namespace Symfony\Bundle\SecurityBundle\Debug; use Symfony\Bundle\SecurityBundle\EventListener\FirewallListener; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; /** * Firewall collecting called listeners. @@ -28,11 +28,11 @@ public function getWrappedListeners() return $this->wrappedListeners; } - protected function handleRequest(GetResponseEvent $event, $listeners) + protected function callListeners(RequestEvent $event, iterable $listeners) { foreach ($listeners as $listener) { $wrappedListener = new WrappedListener($listener); - $wrappedListener->handle($event); + $wrappedListener($event); $this->wrappedListeners[] = $wrappedListener->getInfo(); if ($event->hasResponse()) { diff --git a/src/Symfony/Bundle/SecurityBundle/Debug/WrappedListener.php b/src/Symfony/Bundle/SecurityBundle/Debug/WrappedListener.php index 135ac29fc72f..2a36e10102c2 100644 --- a/src/Symfony/Bundle/SecurityBundle/Debug/WrappedListener.php +++ b/src/Symfony/Bundle/SecurityBundle/Debug/WrappedListener.php @@ -11,7 +11,8 @@ namespace Symfony\Bundle\SecurityBundle\Debug; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; +use Symfony\Component\Security\Http\Firewall\LegacyListenerTrait; use Symfony\Component\Security\Http\Firewall\ListenerInterface; use Symfony\Component\VarDumper\Caster\ClassStub; @@ -19,16 +20,23 @@ * Wraps a security listener for calls record. * * @author Robin Chalas + * + * @internal since Symfony 4.3 */ final class WrappedListener implements ListenerInterface { + use LegacyListenerTrait; + private $response; private $listener; private $time; private $stub; private static $hasVarDumper; - public function __construct(ListenerInterface $listener) + /** + * @param callable $listener + */ + public function __construct($listener) { $this->listener = $listener; @@ -40,10 +48,15 @@ public function __construct(ListenerInterface $listener) /** * {@inheritdoc} */ - public function handle(GetResponseEvent $event) + public function __invoke(RequestEvent $event) { $startTime = microtime(true); - $this->listener->handle($event); + if (\is_callable($this->listener)) { + ($this->listener)($event); + } else { + @trigger_error(sprintf('Calling the "%s::handle()" method from the firewall is deprecated since Symfony 4.3, implement "__invoke()" instead.', \get_class($this)), E_USER_DEPRECATED); + $this->listener->handle($event); + } $this->time = microtime(true) - $startTime; $this->response = $event->getResponse(); } @@ -56,7 +69,7 @@ public function __call($method, $arguments) return $this->listener->{$method}(...$arguments); } - public function getWrappedListener(): ListenerInterface + public function getWrappedListener() { return $this->listener; } diff --git a/src/Symfony/Bundle/SecurityBundle/EventListener/FirewallListener.php b/src/Symfony/Bundle/SecurityBundle/EventListener/FirewallListener.php index a27c422fb8d2..1a3712c7507c 100644 --- a/src/Symfony/Bundle/SecurityBundle/EventListener/FirewallListener.php +++ b/src/Symfony/Bundle/SecurityBundle/EventListener/FirewallListener.php @@ -15,6 +15,7 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpKernel\Event\FinishRequestEvent; use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\Security\Http\Firewall; use Symfony\Component\Security\Http\FirewallMapInterface; use Symfony\Component\Security\Http\Logout\LogoutUrlGenerator; @@ -35,7 +36,10 @@ public function __construct(FirewallMapInterface $map, EventDispatcherInterface parent::__construct($map, $dispatcher); } - public function onKernelRequest(GetResponseEvent $event) + /** + * @internal + */ + public function configureLogoutUrlGenerator(GetResponseEvent $event) { if (!$event->isMasterRequest()) { return; @@ -44,10 +48,11 @@ public function onKernelRequest(GetResponseEvent $event) if ($this->map instanceof FirewallMap && $config = $this->map->getFirewallConfig($event->getRequest())) { $this->logoutUrlGenerator->setCurrentFirewall($config->getName(), $config->getContext()); } - - parent::onKernelRequest($event); } + /** + * @internal since Symfony 4.3 + */ public function onKernelFinishRequest(FinishRequestEvent $event) { if ($event->isMasterRequest()) { @@ -56,4 +61,18 @@ public function onKernelFinishRequest(FinishRequestEvent $event) parent::onKernelFinishRequest($event); } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return [ + KernelEvents::REQUEST => [ + ['configureLogoutUrlGenerator', 8], + ['onKernelRequest', 8], + ], + KernelEvents::FINISH_REQUEST => 'onKernelFinishRequest', + ]; + } } diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/DataCollector/SecurityDataCollectorTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/DataCollector/SecurityDataCollectorTest.php index ac264d2937ec..209248cc85bd 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/DataCollector/SecurityDataCollectorTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/DataCollector/SecurityDataCollectorTest.php @@ -20,7 +20,7 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; use Symfony\Component\Security\Core\Authentication\Token\SwitchUserToken; @@ -32,7 +32,6 @@ use Symfony\Component\Security\Core\Role\Role; use Symfony\Component\Security\Core\Role\RoleHierarchy; use Symfony\Component\Security\Core\Role\SwitchUserRole; -use Symfony\Component\Security\Http\Firewall\ListenerInterface; use Symfony\Component\Security\Http\FirewallMapInterface; use Symfony\Component\Security\Http\Logout\LogoutUrlGenerator; @@ -221,13 +220,11 @@ public function testGetFirewallReturnsNull() public function testGetListeners() { $request = new Request(); - $event = new GetResponseEvent($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $request, HttpKernelInterface::MASTER_REQUEST); + $event = new RequestEvent($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $request, HttpKernelInterface::MASTER_REQUEST); $event->setResponse($response = new Response()); - $listener = $this->getMockBuilder(ListenerInterface::class)->getMock(); - $listener - ->expects($this->once()) - ->method('handle') - ->with($event); + $listener = function ($e) use ($event, &$listenerCalled) { + $listenerCalled += $e === $event; + }; $firewallMap = $this ->getMockBuilder(FirewallMap::class) ->disableOriginalConstructor() @@ -251,7 +248,7 @@ public function testGetListeners() $this->assertNotEmpty($collected = $collector->getListeners()[0]); $collector->lateCollect(); - $this->addToAssertionCount(1); + $this->assertSame(1, $listenerCalled); } public function providerCollectDecisionLog(): \Generator diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Debug/TraceableFirewallListenerTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/Debug/TraceableFirewallListenerTest.php index bf5b8c509952..c301ead2fae1 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Debug/TraceableFirewallListenerTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Debug/TraceableFirewallListenerTest.php @@ -17,9 +17,8 @@ use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; -use Symfony\Component\Security\Http\Firewall\ListenerInterface; use Symfony\Component\Security\Http\Logout\LogoutUrlGenerator; use Symfony\Component\VarDumper\Caster\ClassStub; @@ -31,13 +30,11 @@ class TraceableFirewallListenerTest extends TestCase public function testOnKernelRequestRecordsListeners() { $request = new Request(); - $event = new GetResponseEvent($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $request, HttpKernelInterface::MASTER_REQUEST); + $event = new RequestEvent($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $request, HttpKernelInterface::MASTER_REQUEST); $event->setResponse($response = new Response()); - $listener = $this->getMockBuilder(ListenerInterface::class)->getMock(); - $listener - ->expects($this->once()) - ->method('handle') - ->with($event); + $listener = function ($e) use ($event, &$listenerCalled) { + $listenerCalled += $e === $event; + }; $firewallMap = $this ->getMockBuilder(FirewallMap::class) ->disableOriginalConstructor() @@ -54,6 +51,7 @@ public function testOnKernelRequestRecordsListeners() ->willReturn([[$listener], null, null]); $firewall = new TraceableFirewallListener($firewallMap, new EventDispatcher(), new LogoutUrlGenerator()); + $firewall->configureLogoutUrlGenerator($event); $firewall->onKernelRequest($event); $listeners = $firewall->getWrappedListeners(); @@ -61,5 +59,6 @@ public function testOnKernelRequestRecordsListeners() $this->assertSame($response, $listeners[0]['response']); $this->assertInstanceOf(ClassStub::class, $listeners[0]['stub']); $this->assertSame(\get_class($listener), (string) $listeners[0]['stub']); + $this->assertSame(1, $listenerCalled); } } diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Security/FirewallContextTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/Security/FirewallContextTest.php index b65b8af4e967..15f876441609 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Security/FirewallContextTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Security/FirewallContextTest.php @@ -15,7 +15,6 @@ use Symfony\Bundle\SecurityBundle\Security\FirewallConfig; use Symfony\Bundle\SecurityBundle\Security\FirewallContext; use Symfony\Component\Security\Http\Firewall\ExceptionListener; -use Symfony\Component\Security\Http\Firewall\ListenerInterface; use Symfony\Component\Security\Http\Firewall\LogoutListener; class FirewallContextTest extends TestCase @@ -25,12 +24,7 @@ public function testGetters() $config = new FirewallConfig('main', 'user_checker', 'request_matcher'); $exceptionListener = $this->getExceptionListenerMock(); $logoutListener = $this->getLogoutListenerMock(); - $listeners = [ - $this - ->getMockBuilder(ListenerInterface::class) - ->disableOriginalConstructor() - ->getMock(), - ]; + $listeners = [function () {}]; $context = new FirewallContext($listeners, $exceptionListener, $logoutListener, $config); diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Security/FirewallMapTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/Security/FirewallMapTest.php index bfcac0f81b29..fa590a54e908 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Security/FirewallMapTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Security/FirewallMapTest.php @@ -19,7 +19,6 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestMatcherInterface; use Symfony\Component\Security\Http\Firewall\ExceptionListener; -use Symfony\Component\Security\Http\Firewall\ListenerInterface; use Symfony\Component\Security\Http\Firewall\LogoutListener; class FirewallMapTest extends TestCase @@ -66,7 +65,7 @@ public function testGetListeners() $firewallConfig = new FirewallConfig('main', 'user_checker'); $firewallContext->expects($this->once())->method('getConfig')->willReturn($firewallConfig); - $listener = $this->getMockBuilder(ListenerInterface::class)->getMock(); + $listener = function () {}; $firewallContext->expects($this->once())->method('getListeners')->willReturn([$listener]); $exceptionListener = $this->getMockBuilder(ExceptionListener::class)->disableOriginalConstructor()->getMock(); diff --git a/src/Symfony/Bundle/SecurityBundle/composer.json b/src/Symfony/Bundle/SecurityBundle/composer.json index 074e8593178d..2bb411b7d052 100644 --- a/src/Symfony/Bundle/SecurityBundle/composer.json +++ b/src/Symfony/Bundle/SecurityBundle/composer.json @@ -20,11 +20,11 @@ "ext-xml": "*", "symfony/config": "^4.2", "symfony/dependency-injection": "^4.2", - "symfony/http-kernel": "^4.1", + "symfony/http-kernel": "^4.3", "symfony/security-core": "~4.3", "symfony/security-csrf": "~4.2", "symfony/security-guard": "~4.2", - "symfony/security-http": "~4.2" + "symfony/security-http": "^4.3" }, "require-dev": { "symfony/asset": "~3.4|~4.0", @@ -32,7 +32,6 @@ "symfony/console": "~3.4|~4.0", "symfony/css-selector": "~3.4|~4.0", "symfony/dom-crawler": "~3.4|~4.0", - "symfony/event-dispatcher": "~3.4|~4.0", "symfony/form": "~3.4|~4.0", "symfony/framework-bundle": "~4.2", "symfony/http-foundation": "~3.4|~4.0", @@ -51,7 +50,6 @@ "symfony/browser-kit": "<4.2", "symfony/twig-bundle": "<4.2", "symfony/var-dumper": "<3.4", - "symfony/event-dispatcher": "<3.4", "symfony/framework-bundle": "<4.2", "symfony/console": "<3.4" }, diff --git a/src/Symfony/Bundle/WebProfilerBundle/EventListener/WebDebugToolbarListener.php b/src/Symfony/Bundle/WebProfilerBundle/EventListener/WebDebugToolbarListener.php index 4dd4438ed906..c2c7f28fde58 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/EventListener/WebDebugToolbarListener.php +++ b/src/Symfony/Bundle/WebProfilerBundle/EventListener/WebDebugToolbarListener.php @@ -30,6 +30,8 @@ * This means that the WDT is never included in sub-requests or ESI requests. * * @author Fabien Potencier + * + * @final since Symfony 4.3 */ class WebDebugToolbarListener implements EventSubscriberInterface { diff --git a/src/Symfony/Bundle/WebProfilerBundle/Tests/EventListener/WebDebugToolbarListenerTest.php b/src/Symfony/Bundle/WebProfilerBundle/Tests/EventListener/WebDebugToolbarListenerTest.php index 1d6bd12daee5..e40044b26431 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Tests/EventListener/WebDebugToolbarListenerTest.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Tests/EventListener/WebDebugToolbarListenerTest.php @@ -16,7 +16,7 @@ use Symfony\Component\HttpFoundation\HeaderBag; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; +use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; @@ -62,7 +62,7 @@ public function testRedirectionIsIntercepted($statusCode, $hasSession) { $response = new Response('Some content', $statusCode); $response->headers->set('X-Debug-Token', 'xxxxxxxx'); - $event = new FilterResponseEvent($this->getKernelMock(), $this->getRequestMock(false, 'html', $hasSession), HttpKernelInterface::MASTER_REQUEST, $response); + $event = new ResponseEvent($this->getKernelMock(), $this->getRequestMock(false, 'html', $hasSession), HttpKernelInterface::MASTER_REQUEST, $response); $listener = new WebDebugToolbarListener($this->getTwigMock('Redirection'), true); $listener->onKernelResponse($event); @@ -76,7 +76,7 @@ public function testToolbarIsInjected() $response = new Response(''); $response->headers->set('X-Debug-Token', 'xxxxxxxx'); - $event = new FilterResponseEvent($this->getKernelMock(), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response); + $event = new ResponseEvent($this->getKernelMock(), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response); $listener = new WebDebugToolbarListener($this->getTwigMock()); $listener->onKernelResponse($event); @@ -92,7 +92,7 @@ public function testToolbarIsNotInjectedOnNonHtmlContentType() $response = new Response(''); $response->headers->set('X-Debug-Token', 'xxxxxxxx'); $response->headers->set('Content-Type', 'text/xml'); - $event = new FilterResponseEvent($this->getKernelMock(), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response); + $event = new ResponseEvent($this->getKernelMock(), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response); $listener = new WebDebugToolbarListener($this->getTwigMock()); $listener->onKernelResponse($event); @@ -108,7 +108,7 @@ public function testToolbarIsNotInjectedOnContentDispositionAttachment() $response = new Response(''); $response->headers->set('X-Debug-Token', 'xxxxxxxx'); $response->headers->set('Content-Disposition', 'attachment; filename=test.html'); - $event = new FilterResponseEvent($this->getKernelMock(), $this->getRequestMock(false, 'html'), HttpKernelInterface::MASTER_REQUEST, $response); + $event = new ResponseEvent($this->getKernelMock(), $this->getRequestMock(false, 'html'), HttpKernelInterface::MASTER_REQUEST, $response); $listener = new WebDebugToolbarListener($this->getTwigMock()); $listener->onKernelResponse($event); @@ -124,7 +124,7 @@ public function testToolbarIsNotInjectedOnRedirection($statusCode, $hasSession) { $response = new Response('', $statusCode); $response->headers->set('X-Debug-Token', 'xxxxxxxx'); - $event = new FilterResponseEvent($this->getKernelMock(), $this->getRequestMock(false, 'html', $hasSession), HttpKernelInterface::MASTER_REQUEST, $response); + $event = new ResponseEvent($this->getKernelMock(), $this->getRequestMock(false, 'html', $hasSession), HttpKernelInterface::MASTER_REQUEST, $response); $listener = new WebDebugToolbarListener($this->getTwigMock()); $listener->onKernelResponse($event); @@ -149,7 +149,7 @@ public function testToolbarIsNotInjectedWhenThereIsNoNoXDebugTokenResponseHeader { $response = new Response(''); - $event = new FilterResponseEvent($this->getKernelMock(), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response); + $event = new ResponseEvent($this->getKernelMock(), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response); $listener = new WebDebugToolbarListener($this->getTwigMock()); $listener->onKernelResponse($event); @@ -165,7 +165,7 @@ public function testToolbarIsNotInjectedWhenOnSubRequest() $response = new Response(''); $response->headers->set('X-Debug-Token', 'xxxxxxxx'); - $event = new FilterResponseEvent($this->getKernelMock(), $this->getRequestMock(), HttpKernelInterface::SUB_REQUEST, $response); + $event = new ResponseEvent($this->getKernelMock(), $this->getRequestMock(), HttpKernelInterface::SUB_REQUEST, $response); $listener = new WebDebugToolbarListener($this->getTwigMock()); $listener->onKernelResponse($event); @@ -181,7 +181,7 @@ public function testToolbarIsNotInjectedOnIncompleteHtmlResponses() $response = new Response('
Some content
'); $response->headers->set('X-Debug-Token', 'xxxxxxxx'); - $event = new FilterResponseEvent($this->getKernelMock(), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response); + $event = new ResponseEvent($this->getKernelMock(), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response); $listener = new WebDebugToolbarListener($this->getTwigMock()); $listener->onKernelResponse($event); @@ -197,7 +197,7 @@ public function testToolbarIsNotInjectedOnXmlHttpRequests() $response = new Response(''); $response->headers->set('X-Debug-Token', 'xxxxxxxx'); - $event = new FilterResponseEvent($this->getKernelMock(), $this->getRequestMock(true), HttpKernelInterface::MASTER_REQUEST, $response); + $event = new ResponseEvent($this->getKernelMock(), $this->getRequestMock(true), HttpKernelInterface::MASTER_REQUEST, $response); $listener = new WebDebugToolbarListener($this->getTwigMock()); $listener->onKernelResponse($event); @@ -213,7 +213,7 @@ public function testToolbarIsNotInjectedOnNonHtmlRequests() $response = new Response(''); $response->headers->set('X-Debug-Token', 'xxxxxxxx'); - $event = new FilterResponseEvent($this->getKernelMock(), $this->getRequestMock(false, 'json'), HttpKernelInterface::MASTER_REQUEST, $response); + $event = new ResponseEvent($this->getKernelMock(), $this->getRequestMock(false, 'json'), HttpKernelInterface::MASTER_REQUEST, $response); $listener = new WebDebugToolbarListener($this->getTwigMock()); $listener->onKernelResponse($event); @@ -234,7 +234,7 @@ public function testXDebugUrlHeader() ->will($this->returnValue('http://mydomain.com/_profiler/xxxxxxxx')) ; - $event = new FilterResponseEvent($this->getKernelMock(), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response); + $event = new ResponseEvent($this->getKernelMock(), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response); $listener = new WebDebugToolbarListener($this->getTwigMock(), false, WebDebugToolbarListener::ENABLED, $urlGenerator); $listener->onKernelResponse($event); @@ -255,7 +255,7 @@ public function testThrowingUrlGenerator() ->willThrowException(new \Exception('foo')) ; - $event = new FilterResponseEvent($this->getKernelMock(), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response); + $event = new ResponseEvent($this->getKernelMock(), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response); $listener = new WebDebugToolbarListener($this->getTwigMock(), false, WebDebugToolbarListener::ENABLED, $urlGenerator); $listener->onKernelResponse($event); @@ -276,7 +276,7 @@ public function testThrowingErrorCleanup() ->willThrowException(new \Exception("This\nmultiline\r\ntabbed text should\tcome out\r on\n \ta single plain\r\nline")) ; - $event = new FilterResponseEvent($this->getKernelMock(), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response); + $event = new ResponseEvent($this->getKernelMock(), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response); $listener = new WebDebugToolbarListener($this->getTwigMock(), false, WebDebugToolbarListener::ENABLED, $urlGenerator); $listener->onKernelResponse($event); diff --git a/src/Symfony/Bundle/WebProfilerBundle/composer.json b/src/Symfony/Bundle/WebProfilerBundle/composer.json index af07f8cf8cd4..e0998c0175bf 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/composer.json +++ b/src/Symfony/Bundle/WebProfilerBundle/composer.json @@ -18,7 +18,7 @@ "require": { "php": "^7.1.3", "symfony/config": "^4.2", - "symfony/http-kernel": "~4.2", + "symfony/http-kernel": "^4.3", "symfony/routing": "~3.4|~4.0", "symfony/twig-bundle": "~4.2", "symfony/var-dumper": "~3.4|~4.0", @@ -31,7 +31,6 @@ }, "conflict": { "symfony/dependency-injection": "<3.4", - "symfony/event-dispatcher": "<3.4", "symfony/messenger": "<4.2", "symfony/var-dumper": "<3.4" }, diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index 17df91f99448..fcb334a8a175 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -44,6 +44,7 @@ use Symfony\Component\Debug\ErrorHandler; use Symfony\Component\Debug\Exception\FatalThrowableError; use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy; /** * An Application is the container for a collection of commands. @@ -92,7 +93,7 @@ public function __construct(string $name = 'UNKNOWN', string $version = 'UNKNOWN public function setDispatcher(EventDispatcherInterface $dispatcher) { - $this->dispatcher = $dispatcher; + $this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher); } public function setCommandLoader(CommandLoaderInterface $commandLoader) @@ -235,7 +236,7 @@ public function doRun(InputInterface $input, OutputInterface $output) if (!($e instanceof CommandNotFoundException && !$e instanceof NamespaceNotFoundException) || 1 !== \count($alternatives = $e->getAlternatives()) || !$input->isInteractive()) { if (null !== $this->dispatcher) { $event = new ConsoleErrorEvent($input, $output, $e); - $this->dispatcher->dispatch(ConsoleEvents::ERROR, $event); + $this->dispatcher->dispatch($event, ConsoleEvents::ERROR); if (0 === $event->getExitCode()) { return 0; @@ -254,7 +255,7 @@ public function doRun(InputInterface $input, OutputInterface $output) if (!$style->confirm(sprintf('Do you want to run "%s" instead? ', $alternative), false)) { if (null !== $this->dispatcher) { $event = new ConsoleErrorEvent($input, $output, $e); - $this->dispatcher->dispatch(ConsoleEvents::ERROR, $event); + $this->dispatcher->dispatch($event, ConsoleEvents::ERROR); return $event->getExitCode(); } @@ -920,7 +921,7 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI $e = null; try { - $this->dispatcher->dispatch(ConsoleEvents::COMMAND, $event); + $this->dispatcher->dispatch($event, ConsoleEvents::COMMAND); if ($event->commandShouldRun()) { $exitCode = $command->run($input, $output); @@ -929,7 +930,7 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI } } catch (\Throwable $e) { $event = new ConsoleErrorEvent($input, $output, $e, $command); - $this->dispatcher->dispatch(ConsoleEvents::ERROR, $event); + $this->dispatcher->dispatch($event, ConsoleEvents::ERROR); $e = $event->getError(); if (0 === $exitCode = $event->getExitCode()) { @@ -938,7 +939,7 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI } $event = new ConsoleTerminateEvent($command, $input, $output, $exitCode); - $this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event); + $this->dispatcher->dispatch($event, ConsoleEvents::TERMINATE); if (null !== $e) { throw $e; diff --git a/src/Symfony/Component/Console/composer.json b/src/Symfony/Component/Console/composer.json index 70d4a795cd8d..0fae716e9172 100644 --- a/src/Symfony/Component/Console/composer.json +++ b/src/Symfony/Component/Console/composer.json @@ -23,7 +23,7 @@ }, "require-dev": { "symfony/config": "~3.4|~4.0", - "symfony/event-dispatcher": "~3.4|~4.0", + "symfony/event-dispatcher": "^4.3", "symfony/dependency-injection": "~3.4|~4.0", "symfony/lock": "~3.4|~4.0", "symfony/process": "~3.4|~4.0", @@ -40,6 +40,7 @@ }, "conflict": { "symfony/dependency-injection": "<3.4", + "symfony/event-dispatcher": "<4.3", "symfony/process": "<3.3" }, "autoload": { diff --git a/src/Symfony/Component/EventDispatcher/CHANGELOG.md b/src/Symfony/Component/EventDispatcher/CHANGELOG.md index b581d3143351..26a4cbc42790 100644 --- a/src/Symfony/Component/EventDispatcher/CHANGELOG.md +++ b/src/Symfony/Component/EventDispatcher/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +4.3.0 +----- + + * The signature of the `EventDispatcherInterface::dispatch()` method should be updated to `dispatch($event, string $eventName = null)`, not doing so is deprecated + 4.1.0 ----- diff --git a/src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php b/src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php index 513d87c7e818..0a0dde4230d0 100644 --- a/src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php +++ b/src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php @@ -15,6 +15,7 @@ use Symfony\Component\EventDispatcher\Event; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy; use Symfony\Component\Stopwatch\Stopwatch; /** @@ -36,7 +37,7 @@ class TraceableEventDispatcher implements TraceableEventDispatcherInterface public function __construct(EventDispatcherInterface $dispatcher, Stopwatch $stopwatch, LoggerInterface $logger = null) { - $this->dispatcher = $dispatcher; + $this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher); $this->stopwatch = $stopwatch; $this->logger = $logger; $this->wrappedListeners = []; @@ -121,15 +122,28 @@ public function hasListeners($eventName = null) /** * {@inheritdoc} + * + * @param string|null $eventName */ - public function dispatch($eventName, Event $event = null) + public function dispatch($event/*, string $eventName = null*/) { if (null === $this->callStack) { $this->callStack = new \SplObjectStorage(); } - if (null === $event) { - $event = new Event(); + $eventName = 1 < \func_num_args() ? \func_get_arg(1) : null; + + if ($event instanceof Event) { + $eventName = $eventName ?? \get_class($event); + } else { + @trigger_error(sprintf('Calling the "%s::dispatch()" method with the event name as first argument is deprecated since Symfony 4.3, pass it second and provide the event object first instead.', EventDispatcherInterface::class), E_USER_DEPRECATED); + $swap = $event; + $event = $eventName ?? new Event(); + $eventName = $swap; + + if (!$event instanceof Event) { + throw new \TypeError(sprintf('Argument 1 passed to "%s::dispatch()" must be an instance of %s, %s given.', EventDispatcherInterface::class, Event::class, \is_object($event) ? \get_class($event) : \gettype($event))); + } } if (null !== $this->logger && $event->isPropagationStopped()) { @@ -142,7 +156,7 @@ public function dispatch($eventName, Event $event = null) try { $e = $this->stopwatch->start($eventName, 'section'); try { - $this->dispatcher->dispatch($eventName, $event); + $this->dispatcher->dispatch($event, $eventName); } finally { if ($e->isStarted()) { $e->stop(); diff --git a/src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php b/src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php index 674890aa539d..3806990f35fa 100644 --- a/src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php +++ b/src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php @@ -27,15 +27,17 @@ class RegisterListenersPass implements CompilerPassInterface protected $dispatcherService; protected $listenerTag; protected $subscriberTag; + protected $eventAliasesParameter; private $hotPathEvents = []; private $hotPathTagName; - public function __construct(string $dispatcherService = 'event_dispatcher', string $listenerTag = 'kernel.event_listener', string $subscriberTag = 'kernel.event_subscriber') + public function __construct(string $dispatcherService = 'event_dispatcher', string $listenerTag = 'kernel.event_listener', string $subscriberTag = 'kernel.event_subscriber', string $eventAliasesParameter = 'event_dispatcher.event_aliases') { $this->dispatcherService = $dispatcherService; $this->listenerTag = $listenerTag; $this->subscriberTag = $subscriberTag; + $this->eventAliasesParameter = $eventAliasesParameter; } public function setHotPathEvents(array $hotPathEvents, $tagName = 'container.hot_path') @@ -52,6 +54,12 @@ public function process(ContainerBuilder $container) return; } + if ($container->hasParameter($this->eventAliasesParameter)) { + $aliases = $container->getParameter($this->eventAliasesParameter); + $container->getParameterBag()->remove($this->eventAliasesParameter); + } else { + $aliases = []; + } $definition = $container->findDefinition($this->dispatcherService); foreach ($container->findTaggedServiceIds($this->listenerTag, true) as $id => $events) { @@ -61,6 +69,7 @@ public function process(ContainerBuilder $container) if (!isset($event['event'])) { throw new InvalidArgumentException(sprintf('Service "%s" must define the "event" attribute on "%s" tags.', $id, $this->listenerTag)); } + $event['event'] = $aliases[$event['event']] ?? $event['event']; if (!isset($event['method'])) { $event['method'] = 'on'.preg_replace_callback([ @@ -98,6 +107,7 @@ public function process(ContainerBuilder $container) } $class = $r->name; + ExtractingEventDispatcher::$aliases = $aliases; ExtractingEventDispatcher::$subscriber = $class; $extractingDispatcher->addSubscriber($extractingDispatcher); foreach ($extractingDispatcher->listeners as $args) { @@ -109,6 +119,7 @@ public function process(ContainerBuilder $container) } } $extractingDispatcher->listeners = []; + ExtractingEventDispatcher::$aliases = []; } } } @@ -120,6 +131,7 @@ class ExtractingEventDispatcher extends EventDispatcher implements EventSubscrib { public $listeners = []; + public static $aliases = []; public static $subscriber; public function addListener($eventName, $listener, $priority = 0) @@ -129,8 +141,12 @@ public function addListener($eventName, $listener, $priority = 0) public static function getSubscribedEvents() { - $callback = [self::$subscriber, 'getSubscribedEvents']; + $events = []; + + foreach ([self::$subscriber, 'getSubscribedEvents']() as $eventName => $params) { + $events[self::$aliases[$eventName] ?? $eventName] = $params; + } - return $callback(); + return $events; } } diff --git a/src/Symfony/Component/EventDispatcher/EventDispatcher.php b/src/Symfony/Component/EventDispatcher/EventDispatcher.php index 6962c5facfdf..80b3105e6a66 100644 --- a/src/Symfony/Component/EventDispatcher/EventDispatcher.php +++ b/src/Symfony/Component/EventDispatcher/EventDispatcher.php @@ -41,11 +41,24 @@ public function __construct() /** * {@inheritdoc} + * + * @param string|null $eventName */ - public function dispatch($eventName, Event $event = null) + public function dispatch($event/*, string $eventName = null*/) { - if (null === $event) { - $event = new Event(); + $eventName = 1 < \func_num_args() ? \func_get_arg(1) : null; + + if ($event instanceof Event) { + $eventName = $eventName ?? \get_class($event); + } else { + @trigger_error(sprintf('Calling the "%s::dispatch()" method with the event name as first argument is deprecated since Symfony 4.3, pass it second and provide the event object first instead.', EventDispatcherInterface::class), E_USER_DEPRECATED); + $swap = $event; + $event = $eventName ?? new Event(); + $eventName = $swap; + + if (!$event instanceof Event) { + throw new \TypeError(sprintf('Argument 1 passed to "%s::dispatch()" must be an instance of %s, %s given.', EventDispatcherInterface::class, Event::class, \is_object($event) ? \get_class($event) : \gettype($event))); + } } if (null !== $this->optimized && null !== $eventName) { diff --git a/src/Symfony/Component/EventDispatcher/EventDispatcherInterface.php b/src/Symfony/Component/EventDispatcher/EventDispatcherInterface.php index bde753a12fca..672f5044d720 100644 --- a/src/Symfony/Component/EventDispatcher/EventDispatcherInterface.php +++ b/src/Symfony/Component/EventDispatcher/EventDispatcherInterface.php @@ -23,15 +23,13 @@ interface EventDispatcherInterface /** * Dispatches an event to all registered listeners. * - * @param string $eventName The name of the event to dispatch. The name of - * the event is the name of the method that is - * invoked on listeners. - * @param Event|null $event The event to pass to the event handlers/listeners - * If not supplied, an empty Event instance is created + * @param Event $event The event to pass to the event handlers/listeners + * @param string|null $eventName The name of the event to dispatch. If not supplied, + * the class of $event should be used instead. * * @return Event */ - public function dispatch($eventName, Event $event = null); + public function dispatch($event/*, string $eventName = null*/); /** * Adds an event listener that listens on the specified events. diff --git a/src/Symfony/Component/EventDispatcher/ImmutableEventDispatcher.php b/src/Symfony/Component/EventDispatcher/ImmutableEventDispatcher.php index b3cf56c502db..082e2a05d48f 100644 --- a/src/Symfony/Component/EventDispatcher/ImmutableEventDispatcher.php +++ b/src/Symfony/Component/EventDispatcher/ImmutableEventDispatcher.php @@ -22,15 +22,26 @@ class ImmutableEventDispatcher implements EventDispatcherInterface public function __construct(EventDispatcherInterface $dispatcher) { - $this->dispatcher = $dispatcher; + $this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher); } /** * {@inheritdoc} + * + * @param string|null $eventName */ - public function dispatch($eventName, Event $event = null) + public function dispatch($event/*, string $eventName = null*/) { - return $this->dispatcher->dispatch($eventName, $event); + $eventName = 1 < \func_num_args() ? \func_get_arg(1) : null; + + if (\is_scalar($event)) { + // deprecated + $swap = $event; + $event = $eventName ?? new Event(); + $eventName = $swap; + } + + return $this->dispatcher->dispatch($event, $eventName); } /** diff --git a/src/Symfony/Component/EventDispatcher/LegacyEventDispatcherProxy.php b/src/Symfony/Component/EventDispatcher/LegacyEventDispatcherProxy.php new file mode 100644 index 000000000000..8539376206bc --- /dev/null +++ b/src/Symfony/Component/EventDispatcher/LegacyEventDispatcherProxy.php @@ -0,0 +1,142 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\EventDispatcher; + +/** + * An helper class to provide BC/FC with the legacy signature of EventDispatcherInterface::dispatch(). + * + * This class should be deprecated in Symfony 5.1 + * + * @author Nicolas Grekas + */ +final class LegacyEventDispatcherProxy implements EventDispatcherInterface +{ + private $dispatcher; + + public static function decorate(?EventDispatcherInterface $dispatcher): ?EventDispatcherInterface + { + if (null === $dispatcher) { + return null; + } + $r = new \ReflectionMethod($dispatcher, 'dispatch'); + $param2 = $r->getParameters()[1] ?? null; + + if (!$param2 || !$param2->hasType() || $param2->getType()->isBuiltin()) { + return $dispatcher; + } + + @trigger_error(sprintf('The signature of the "%s::dispatch()" method should be updated to "dispatch($event, string $eventName = null)", not doing so is deprecated since Symfony 4.3.', $r->class), E_USER_DEPRECATED); + + $self = new self(); + $self->dispatcher = $dispatcher; + + return $self; + } + + /** + * {@inheritdoc} + * + * @param string|null $eventName + */ + public function dispatch($event/*, string $eventName = null*/) + { + $eventName = 1 < \func_num_args() ? \func_get_arg(1) : null; + + if ($event instanceof Event) { + $eventName = $eventName ?? \get_class($event); + } else { + @trigger_error(sprintf('Calling the "%s::dispatch()" method with the event name as first argument is deprecated since Symfony 4.3, pass it second and provide the event object first instead.', EventDispatcherInterface::class), E_USER_DEPRECATED); + $swap = $event; + $event = $eventName ?? new Event(); + $eventName = $swap; + + if (!$event instanceof Event) { + throw new \TypeError(sprintf('Argument 1 passed to "%s::dispatch()" must be an instance of %s, %s given.', EventDispatcherInterface::class, Event::class, \is_object($event) ? \get_class($event) : \gettype($event))); + } + } + + $listeners = $this->getListeners($eventName); + + foreach ($listeners as $listener) { + if ($event->isPropagationStopped()) { + break; + } + $listener($event, $eventName, $this); + } + + return $event; + } + + /** + * {@inheritdoc} + */ + public function addListener($eventName, $listener, $priority = 0) + { + return $this->dispatcher->addListener($eventName, $listener, $priority); + } + + /** + * {@inheritdoc} + */ + public function addSubscriber(EventSubscriberInterface $subscriber) + { + return $this->dispatcher->addSubscriber($subscriber); + } + + /** + * {@inheritdoc} + */ + public function removeListener($eventName, $listener) + { + return $this->dispatcher->removeListener($eventName, $listener); + } + + /** + * {@inheritdoc} + */ + public function removeSubscriber(EventSubscriberInterface $subscriber) + { + return $this->dispatcher->removeSubscriber($subscriber); + } + + /** + * {@inheritdoc} + */ + public function getListeners($eventName = null) + { + return $this->dispatcher->getListeners($eventName); + } + + /** + * {@inheritdoc} + */ + public function getListenerPriority($eventName, $listener) + { + return $this->dispatcher->getListenerPriority($eventName, $listener); + } + + /** + * {@inheritdoc} + */ + public function hasListeners($eventName = null) + { + return $this->dispatcher->hasListeners($eventName); + } + + /** + * Proxies all method calls to the original event dispatcher. + */ + public function __call($method, $arguments) + { + return $this->dispatcher->{$method}(...$arguments); + } +} diff --git a/src/Symfony/Component/EventDispatcher/Tests/Debug/TraceableEventDispatcherTest.php b/src/Symfony/Component/EventDispatcher/Tests/Debug/TraceableEventDispatcherTest.php index 9a3697a36f3b..8fd0305b0e42 100644 --- a/src/Symfony/Component/EventDispatcher/Tests/Debug/TraceableEventDispatcherTest.php +++ b/src/Symfony/Component/EventDispatcher/Tests/Debug/TraceableEventDispatcherTest.php @@ -69,7 +69,7 @@ public function testGetListenerPriority() // Verify that priority is preserved when listener is removed and re-added // in preProcess() and postProcess(). - $tdispatcher->dispatch('foo', new Event()); + $tdispatcher->dispatch(new Event(), 'foo'); $listeners = $dispatcher->getListeners('foo'); $this->assertSame(123, $tdispatcher->getListenerPriority('foo', $listeners[0])); } @@ -84,7 +84,7 @@ public function testGetListenerPriorityWhileDispatching() }; $tdispatcher->addListener('bar', $listener, 5); - $tdispatcher->dispatch('bar'); + $tdispatcher->dispatch(new Event(), 'bar'); $this->assertSame(5, $priorityWhileDispatching); } @@ -115,7 +115,7 @@ public function testGetCalledListeners() $this->assertEquals([], $tdispatcher->getCalledListeners()); $this->assertEquals([['event' => 'foo', 'pretty' => 'closure', 'priority' => 5]], $listeners); - $tdispatcher->dispatch('foo'); + $tdispatcher->dispatch(new Event(), 'foo'); $listeners = $tdispatcher->getCalledListeners(); $this->assertArrayHasKey('stub', $listeners[0]); @@ -129,7 +129,7 @@ public function testClearCalledListeners() $tdispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch()); $tdispatcher->addListener('foo', function () {}, 5); - $tdispatcher->dispatch('foo'); + $tdispatcher->dispatch(new Event(), 'foo'); $tdispatcher->reset(); $listeners = $tdispatcher->getNotCalledListeners(); @@ -145,7 +145,7 @@ public function testDispatchAfterReset() $tdispatcher->addListener('foo', function () {}, 5); $tdispatcher->reset(); - $tdispatcher->dispatch('foo'); + $tdispatcher->dispatch(new Event(), 'foo'); $listeners = $tdispatcher->getCalledListeners(); $this->assertArrayHasKey('stub', $listeners[0]); @@ -157,10 +157,10 @@ public function testGetCalledListenersNested() $dispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch()); $dispatcher->addListener('foo', function (Event $event, $eventName, $dispatcher) use (&$tdispatcher) { $tdispatcher = $dispatcher; - $dispatcher->dispatch('bar'); + $dispatcher->dispatch(new Event(), 'bar'); }); $dispatcher->addListener('bar', function (Event $event) {}); - $dispatcher->dispatch('foo'); + $dispatcher->dispatch(new Event(), 'foo'); $this->assertSame($dispatcher, $tdispatcher); $this->assertCount(2, $dispatcher->getCalledListeners()); } @@ -175,7 +175,7 @@ public function testItReturnsNoOrphanedEventsWhenCreated() public function testItReturnsOrphanedEventsAfterDispatch() { $tdispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch()); - $tdispatcher->dispatch('foo'); + $tdispatcher->dispatch(new Event(), 'foo'); $events = $tdispatcher->getOrphanedEvents(); $this->assertCount(1, $events); $this->assertEquals(['foo'], $events); @@ -185,7 +185,7 @@ public function testItDoesNotReturnHandledEvents() { $tdispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch()); $tdispatcher->addListener('foo', function () {}); - $tdispatcher->dispatch('foo'); + $tdispatcher->dispatch(new Event(), 'foo'); $events = $tdispatcher->getOrphanedEvents(); $this->assertEmpty($events); } @@ -202,7 +202,7 @@ public function testLogger() $logger->expects($this->at(0))->method('debug')->with('Notified event "{event}" to listener "{listener}".', ['event' => 'foo', 'listener' => 'closure']); $logger->expects($this->at(1))->method('debug')->with('Notified event "{event}" to listener "{listener}".', ['event' => 'foo', 'listener' => 'closure']); - $tdispatcher->dispatch('foo'); + $tdispatcher->dispatch(new Event(), 'foo'); } public function testLoggerWithStoppedEvent() @@ -218,7 +218,7 @@ public function testLoggerWithStoppedEvent() $logger->expects($this->at(1))->method('debug')->with('Listener "{listener}" stopped propagation of the event "{event}".', ['event' => 'foo', 'listener' => 'closure']); $logger->expects($this->at(2))->method('debug')->with('Listener "{listener}" was not called for event "{event}".', ['event' => 'foo', 'listener' => 'closure']); - $tdispatcher->dispatch('foo'); + $tdispatcher->dispatch(new Event(), 'foo'); } public function testDispatchCallListeners() @@ -230,7 +230,7 @@ public function testDispatchCallListeners() $tdispatcher->addListener('foo', function () use (&$called) { $called[] = 'foo1'; }, 10); $tdispatcher->addListener('foo', function () use (&$called) { $called[] = 'foo2'; }, 20); - $tdispatcher->dispatch('foo'); + $tdispatcher->dispatch(new Event(), 'foo'); $this->assertSame(['foo2', 'foo1'], $called); } @@ -243,14 +243,14 @@ public function testDispatchNested() $dispatcher->addListener('foo', $listener1 = function () use ($dispatcher, &$loop) { ++$loop; if (2 == $loop) { - $dispatcher->dispatch('foo'); + $dispatcher->dispatch(new Event(), 'foo'); } }); $dispatcher->addListener('foo', function () use (&$dispatchedEvents) { ++$dispatchedEvents; }); - $dispatcher->dispatch('foo'); + $dispatcher->dispatch(new Event(), 'foo'); $this->assertSame(2, $dispatchedEvents); } @@ -260,14 +260,14 @@ public function testDispatchReusedEventNested() $nestedCall = false; $dispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch()); $dispatcher->addListener('foo', function (Event $e) use ($dispatcher) { - $dispatcher->dispatch('bar', $e); + $dispatcher->dispatch(new Event(), 'bar', $e); }); $dispatcher->addListener('bar', function (Event $e) use (&$nestedCall) { $nestedCall = true; }); $this->assertFalse($nestedCall); - $dispatcher->dispatch('foo'); + $dispatcher->dispatch(new Event(), 'foo'); $this->assertTrue($nestedCall); } @@ -279,7 +279,7 @@ public function testListenerCanRemoveItselfWhenExecuted() }; $eventDispatcher->addListener('foo', $listener1); $eventDispatcher->addListener('foo', function () {}); - $eventDispatcher->dispatch('foo'); + $eventDispatcher->dispatch(new Event(), 'foo'); $this->assertCount(1, $eventDispatcher->getListeners('foo'), 'expected listener1 to be removed'); } @@ -287,7 +287,7 @@ public function testListenerCanRemoveItselfWhenExecuted() public function testClearOrphanedEvents() { $tdispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch()); - $tdispatcher->dispatch('foo'); + $tdispatcher->dispatch(new Event(), 'foo'); $events = $tdispatcher->getOrphanedEvents(); $this->assertCount(1, $events); $tdispatcher->reset(); diff --git a/src/Symfony/Component/EventDispatcher/Tests/EventDispatcherTest.php b/src/Symfony/Component/EventDispatcher/Tests/EventDispatcherTest.php index 98fd027a6a73..cfdc9c137d96 100644 --- a/src/Symfony/Component/EventDispatcher/Tests/EventDispatcherTest.php +++ b/src/Symfony/Component/EventDispatcher/Tests/EventDispatcherTest.php @@ -131,13 +131,13 @@ public function testDispatch() { $this->dispatcher->addListener('pre.foo', [$this->listener, 'preFoo']); $this->dispatcher->addListener('post.foo', [$this->listener, 'postFoo']); - $this->dispatcher->dispatch(self::preFoo); + $this->dispatcher->dispatch(new Event(), self::preFoo); $this->assertTrue($this->listener->preFooInvoked); $this->assertFalse($this->listener->postFooInvoked); - $this->assertInstanceOf('Symfony\Component\EventDispatcher\Event', $this->dispatcher->dispatch('noevent')); - $this->assertInstanceOf('Symfony\Component\EventDispatcher\Event', $this->dispatcher->dispatch(self::preFoo)); + $this->assertInstanceOf('Symfony\Component\EventDispatcher\Event', $this->dispatcher->dispatch(new Event(), 'noevent')); + $this->assertInstanceOf('Symfony\Component\EventDispatcher\Event', $this->dispatcher->dispatch(new Event(), self::preFoo)); $event = new Event(); - $return = $this->dispatcher->dispatch(self::preFoo, $event); + $return = $this->dispatcher->dispatch($event, self::preFoo); $this->assertSame($event, $return); } @@ -149,7 +149,7 @@ public function testDispatchForClosure() }; $this->dispatcher->addListener('pre.foo', $listener); $this->dispatcher->addListener('post.foo', $listener); - $this->dispatcher->dispatch(self::preFoo); + $this->dispatcher->dispatch(new Event(), self::preFoo); $this->assertEquals(1, $invoked); } @@ -162,7 +162,7 @@ public function testStopEventPropagation() // Manually set priority to enforce $this->listener to be called first $this->dispatcher->addListener('post.foo', [$this->listener, 'postFoo'], 10); $this->dispatcher->addListener('post.foo', [$otherListener, 'postFoo']); - $this->dispatcher->dispatch(self::postFoo); + $this->dispatcher->dispatch(new Event(), self::postFoo); $this->assertTrue($this->listener->postFooInvoked); $this->assertFalse($otherListener->postFooInvoked); } @@ -182,7 +182,7 @@ public function testDispatchByPriority() $this->dispatcher->addListener('pre.foo', $listener1, -10); $this->dispatcher->addListener('pre.foo', $listener2); $this->dispatcher->addListener('pre.foo', $listener3, 10); - $this->dispatcher->dispatch(self::preFoo); + $this->dispatcher->dispatch(new Event(), self::preFoo); $this->assertEquals(['3', '2', '1'], $invoked); } @@ -264,7 +264,7 @@ public function testEventReceivesTheDispatcherInstanceAsArgument() $this->dispatcher->addListener('test', [$listener, 'foo']); $this->assertNull($listener->name); $this->assertNull($listener->dispatcher); - $this->dispatcher->dispatch('test'); + $this->dispatcher->dispatch(new Event(), 'test'); $this->assertEquals('test', $listener->name); $this->assertSame($this->dispatcher, $listener->dispatcher); } @@ -327,8 +327,8 @@ public function testDispatchLazyListener() }; $this->dispatcher->addListener('foo', [$factory, 'foo']); $this->assertSame(0, $called); - $this->dispatcher->dispatch('foo', new Event()); - $this->dispatcher->dispatch('foo', new Event()); + $this->dispatcher->dispatch(new Event(), 'foo'); + $this->dispatcher->dispatch(new Event(), 'foo'); $this->assertSame(1, $called); } @@ -385,7 +385,7 @@ public function testMutatingWhilePropagationIsStopped() return $test; }, 'preFoo']); - $this->dispatcher->dispatch('foo'); + $this->dispatcher->dispatch(new Event(), 'foo'); $this->assertTrue($test->postFooInvoked); $this->assertFalse($test->preFooInvoked); @@ -393,7 +393,7 @@ public function testMutatingWhilePropagationIsStopped() $this->assertsame(0, $this->dispatcher->getListenerPriority('foo', [$test, 'preFoo'])); $test->preFoo(new Event()); - $this->dispatcher->dispatch('foo'); + $this->dispatcher->dispatch(new Event(), 'foo'); $this->assertTrue($testLoaded); } diff --git a/src/Symfony/Component/EventDispatcher/Tests/ImmutableEventDispatcherTest.php b/src/Symfony/Component/EventDispatcher/Tests/ImmutableEventDispatcherTest.php index 04f2861e3319..c896facc14c9 100644 --- a/src/Symfony/Component/EventDispatcher/Tests/ImmutableEventDispatcherTest.php +++ b/src/Symfony/Component/EventDispatcher/Tests/ImmutableEventDispatcherTest.php @@ -42,10 +42,10 @@ public function testDispatchDelegates() $this->innerDispatcher->expects($this->once()) ->method('dispatch') - ->with('event', $event) + ->with($event, 'event') ->will($this->returnValue('result')); - $this->assertSame('result', $this->dispatcher->dispatch('event', $event)); + $this->assertSame('result', $this->dispatcher->dispatch($event, 'event')); } public function testGetListenersDelegates() diff --git a/src/Symfony/Component/EventDispatcher/Tests/LegacyEventDispatcherTest.php b/src/Symfony/Component/EventDispatcher/Tests/LegacyEventDispatcherTest.php new file mode 100644 index 000000000000..d17e9f14062f --- /dev/null +++ b/src/Symfony/Component/EventDispatcher/Tests/LegacyEventDispatcherTest.php @@ -0,0 +1,36 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\EventDispatcher\Tests; + +use PHPUnit\Framework\TestCase; +use Symfony\Component\EventDispatcher\Event; +use Symfony\Component\EventDispatcher\EventDispatcher; +use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy; + +/** + * @group legacy + */ +class LegacyEventDispatcherTest extends EventDispatcherTest +{ + protected function createEventDispatcher() + { + return LegacyEventDispatcherProxy::decorate(new TestLegacyEventDispatcher()); + } +} + +class TestLegacyEventDispatcher extends EventDispatcher +{ + public function dispatch($eventName, Event $event = null) + { + return parent::dispatch($event, $eventName); + } +} diff --git a/src/Symfony/Component/Form/CHANGELOG.md b/src/Symfony/Component/Form/CHANGELOG.md index 409153d2be94..0d3d468586f6 100644 --- a/src/Symfony/Component/Form/CHANGELOG.md +++ b/src/Symfony/Component/Form/CHANGELOG.md @@ -42,6 +42,11 @@ CHANGELOG ``` * added the `input_format` option to `DateType`, `DateTimeType`, and `TimeType` to specify the input format when setting the `input` option to `string` + * dispatch `PreSubmitEvent` on `form.pre_submit` + * dispatch `SubmitEvent` on `form.submit` + * dispatch `PostSubmitEvent` on `form.post_submit` + * dispatch `PreSetDataEvent` on `form.pre_set_data` + * dispatch `PostSetDataEvent` on `form.post_set_data` 4.2.0 ----- diff --git a/src/Symfony/Component/Form/Event/PostSetDataEvent.php b/src/Symfony/Component/Form/Event/PostSetDataEvent.php new file mode 100644 index 000000000000..0e5e76c91595 --- /dev/null +++ b/src/Symfony/Component/Form/Event/PostSetDataEvent.php @@ -0,0 +1,23 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Form\Event; + +use Symfony\Component\Form\FormEvent; + +/** + * This event is dispatched at the end of the Form::setData() method. + * + * This event is mostly here for reading data after having pre-populated the form. + */ +class PostSetDataEvent extends FormEvent +{ +} diff --git a/src/Symfony/Component/Form/Event/PostSubmitEvent.php b/src/Symfony/Component/Form/Event/PostSubmitEvent.php new file mode 100644 index 000000000000..996150f331c1 --- /dev/null +++ b/src/Symfony/Component/Form/Event/PostSubmitEvent.php @@ -0,0 +1,24 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Form\Event; + +use Symfony\Component\Form\FormEvent; + +/** + * This event is dispatched after the Form::submit() + * once the model and view data have been denormalized. + * + * It can be used to fetch data after denormalization. + */ +class PostSubmitEvent extends FormEvent +{ +} diff --git a/src/Symfony/Component/Form/Event/PreSetDataEvent.php b/src/Symfony/Component/Form/Event/PreSetDataEvent.php new file mode 100644 index 000000000000..160c3392fd2c --- /dev/null +++ b/src/Symfony/Component/Form/Event/PreSetDataEvent.php @@ -0,0 +1,25 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Form\Event; + +use Symfony\Component\Form\FormEvent; + +/** + * This event is dispatched at the beginning of the Form::setData() method. + * + * It can be used to: + * - Modify the data given during pre-population; + * - Modify a form depending on the pre-populated data (adding or removing fields dynamically). + */ +class PreSetDataEvent extends FormEvent +{ +} diff --git a/src/Symfony/Component/Form/Event/PreSubmitEvent.php b/src/Symfony/Component/Form/Event/PreSubmitEvent.php new file mode 100644 index 000000000000..751317627931 --- /dev/null +++ b/src/Symfony/Component/Form/Event/PreSubmitEvent.php @@ -0,0 +1,25 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Form\Event; + +use Symfony\Component\Form\FormEvent; + +/** + * This event is dispatched at the beginning of the Form::submit() method. + * + * It can be used to: + * - Change data from the request, before submitting the data to the form. + * - Add or remove form fields, before submitting the data to the form. + */ +class PreSubmitEvent extends FormEvent +{ +} diff --git a/src/Symfony/Component/Form/Event/SubmitEvent.php b/src/Symfony/Component/Form/Event/SubmitEvent.php new file mode 100644 index 000000000000..511d800d5329 --- /dev/null +++ b/src/Symfony/Component/Form/Event/SubmitEvent.php @@ -0,0 +1,24 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Form\Event; + +use Symfony\Component\Form\FormEvent; + +/** + * This event is dispatched just before the Form::submit() method + * transforms back the normalized data to the model and view data. + * + * It can be used to change data from the normalized representation of the data. + */ +class SubmitEvent extends FormEvent +{ +} diff --git a/src/Symfony/Component/Form/Form.php b/src/Symfony/Component/Form/Form.php index 17ecfd6f4774..40b7f4d23db6 100644 --- a/src/Symfony/Component/Form/Form.php +++ b/src/Symfony/Component/Form/Form.php @@ -11,6 +11,12 @@ namespace Symfony\Component\Form; +use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy; +use Symfony\Component\Form\Event\PostSetDataEvent; +use Symfony\Component\Form\Event\PostSubmitEvent; +use Symfony\Component\Form\Event\PreSetDataEvent; +use Symfony\Component\Form\Event\PreSubmitEvent; +use Symfony\Component\Form\Event\SubmitEvent; use Symfony\Component\Form\Exception\AlreadySubmittedException; use Symfony\Component\Form\Exception\LogicException; use Symfony\Component\Form\Exception\OutOfBoundsException; @@ -333,12 +339,12 @@ public function setData($modelData) } $this->lockSetData = true; - $dispatcher = $this->config->getEventDispatcher(); + $dispatcher = LegacyEventDispatcherProxy::decorate($this->config->getEventDispatcher()); // Hook to change content of the data if ($dispatcher->hasListeners(FormEvents::PRE_SET_DATA)) { - $event = new FormEvent($this, $modelData); - $dispatcher->dispatch(FormEvents::PRE_SET_DATA, $event); + $event = new PreSetDataEvent($this, $modelData); + $dispatcher->dispatch($event, FormEvents::PRE_SET_DATA); $modelData = $event->getData(); } @@ -380,8 +386,8 @@ public function setData($modelData) } if ($dispatcher->hasListeners(FormEvents::POST_SET_DATA)) { - $event = new FormEvent($this, $modelData); - $dispatcher->dispatch(FormEvents::POST_SET_DATA, $event); + $event = new PostSetDataEvent($this, $modelData); + $dispatcher->dispatch($event, FormEvents::POST_SET_DATA); } return $this; @@ -542,7 +548,7 @@ public function submit($submittedData, $clearMissing = true) $this->transformationFailure = new TransformationFailedException('Submitted data was expected to be text or number, array given.'); } - $dispatcher = $this->config->getEventDispatcher(); + $dispatcher = LegacyEventDispatcherProxy::decorate($this->config->getEventDispatcher()); $modelData = null; $normData = null; @@ -555,8 +561,8 @@ public function submit($submittedData, $clearMissing = true) // Hook to change content of the data submitted by the browser if ($dispatcher->hasListeners(FormEvents::PRE_SUBMIT)) { - $event = new FormEvent($this, $submittedData); - $dispatcher->dispatch(FormEvents::PRE_SUBMIT, $event); + $event = new PreSubmitEvent($this, $submittedData); + $dispatcher->dispatch($event, FormEvents::PRE_SUBMIT); $submittedData = $event->getData(); } @@ -642,8 +648,8 @@ public function submit($submittedData, $clearMissing = true) // Hook to change content of the data in the normalized // representation if ($dispatcher->hasListeners(FormEvents::SUBMIT)) { - $event = new FormEvent($this, $normData); - $dispatcher->dispatch(FormEvents::SUBMIT, $event); + $event = new SubmitEvent($this, $normData); + $dispatcher->dispatch($event, FormEvents::SUBMIT); $normData = $event->getData(); } @@ -669,8 +675,8 @@ public function submit($submittedData, $clearMissing = true) $this->viewData = $viewData; if ($dispatcher->hasListeners(FormEvents::POST_SUBMIT)) { - $event = new FormEvent($this, $viewData); - $dispatcher->dispatch(FormEvents::POST_SUBMIT, $event); + $event = new PostSubmitEvent($this, $viewData); + $dispatcher->dispatch($event, FormEvents::POST_SUBMIT); } return $this; diff --git a/src/Symfony/Component/Form/FormEvents.php b/src/Symfony/Component/Form/FormEvents.php index c9b01736d495..da3824bc19a3 100644 --- a/src/Symfony/Component/Form/FormEvents.php +++ b/src/Symfony/Component/Form/FormEvents.php @@ -29,7 +29,7 @@ final class FormEvents * - Change data from the request, before submitting the data to the form. * - Add or remove form fields, before submitting the data to the form. * - * @Event("Symfony\Component\Form\FormEvent") + * @Event("Symfony\Component\Form\Event\PreSubmitEvent") */ const PRE_SUBMIT = 'form.pre_submit'; @@ -39,7 +39,7 @@ final class FormEvents * * It can be used to change data from the normalized representation of the data. * - * @Event("Symfony\Component\Form\FormEvent") + * @Event("Symfony\Component\Form\Event\SubmitEvent") */ const SUBMIT = 'form.submit'; @@ -49,7 +49,7 @@ final class FormEvents * * It can be used to fetch data after denormalization. * - * @Event("Symfony\Component\Form\FormEvent") + * @Event("Symfony\Component\Form\Event\PostSubmitEvent") */ const POST_SUBMIT = 'form.post_submit'; @@ -60,7 +60,7 @@ final class FormEvents * - Modify the data given during pre-population; * - Modify a form depending on the pre-populated data (adding or removing fields dynamically). * - * @Event("Symfony\Component\Form\FormEvent") + * @Event("Symfony\Component\Form\Event\PreSetDataEvent") */ const PRE_SET_DATA = 'form.pre_set_data'; @@ -69,7 +69,7 @@ final class FormEvents * * This event is mostly here for reading data after having pre-populated the form. * - * @Event("Symfony\Component\Form\FormEvent") + * @Event("Symfony\Component\Form\Event\PostSetDataEvent") */ const POST_SET_DATA = 'form.post_set_data'; diff --git a/src/Symfony/Component/Form/composer.json b/src/Symfony/Component/Form/composer.json index fd39d77edc19..ca968ab085eb 100644 --- a/src/Symfony/Component/Form/composer.json +++ b/src/Symfony/Component/Form/composer.json @@ -17,7 +17,7 @@ ], "require": { "php": "^7.1.3", - "symfony/event-dispatcher": "~3.4|~4.0", + "symfony/event-dispatcher": "^4.3", "symfony/intl": "~3.4|~4.0", "symfony/options-resolver": "~4.2", "symfony/polyfill-ctype": "~1.8", diff --git a/src/Symfony/Component/HttpKernel/CHANGELOG.md b/src/Symfony/Component/HttpKernel/CHANGELOG.md index 99c3c5228687..7b5dc2833296 100644 --- a/src/Symfony/Component/HttpKernel/CHANGELOG.md +++ b/src/Symfony/Component/HttpKernel/CHANGELOG.md @@ -14,6 +14,13 @@ CHANGELOG store all the serialized state in the data property instead * `DumpDataCollector` has been marked as `final` * added an event listener to prevent search engines from indexing applications in debug mode. + * renamed `FilterControllerArgumentsEvent` to `ControllerArgumentsEvent` + * renamed `FilterControllerEvent` to `ControllerEvent` + * renamed `FilterResponseEvent` to `ResponseEvent` + * renamed `GetResponseEvent` to `RequestEvent` + * renamed `GetResponseForControllerResultEvent` to `ViewEvent` + * renamed `GetResponseForExceptionEvent` to `ExceptionEvent` + * renamed `PostResponseEvent` to `TerminateEvent` 4.2.0 ----- diff --git a/src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php index 671118bad835..32624c963fa0 100644 --- a/src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php +++ b/src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php @@ -350,11 +350,17 @@ public function getForwardToken() return isset($this->data['forward_token']) ? $this->data['forward_token'] : null; } + /** + * @final since Symfony 4.3 + */ public function onKernelController(FilterControllerEvent $event) { $this->controllers[$event->getRequest()] = $event->getController(); } + /** + * @final since Symfony 4.3 + */ public function onKernelResponse(FilterResponseEvent $event) { if (!$event->isMasterRequest()) { diff --git a/src/Symfony/Component/HttpKernel/DataCollector/RouterDataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/RouterDataCollector.php index 432dc3618f8c..65fc90dc1921 100644 --- a/src/Symfony/Component/HttpKernel/DataCollector/RouterDataCollector.php +++ b/src/Symfony/Component/HttpKernel/DataCollector/RouterDataCollector.php @@ -17,8 +17,6 @@ use Symfony\Component\HttpKernel\Event\FilterControllerEvent; /** - * RouterDataCollector. - * * @author Fabien Potencier */ class RouterDataCollector extends DataCollector @@ -68,6 +66,8 @@ protected function guessRoute(Request $request, $controller) /** * Remembers the controller associated to each request. + * + * @final since Symfony 4.3 */ public function onKernelController(FilterControllerEvent $event) { diff --git a/src/Symfony/Component/HttpKernel/Event/ControllerArgumentsEvent.php b/src/Symfony/Component/HttpKernel/Event/ControllerArgumentsEvent.php new file mode 100644 index 000000000000..3dc6ea50ede1 --- /dev/null +++ b/src/Symfony/Component/HttpKernel/Event/ControllerArgumentsEvent.php @@ -0,0 +1,28 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\HttpKernel\Event; + +/** + * Allows filtering of controller arguments. + * + * You can call getController() to retrieve the controller and getArguments + * to retrieve the current arguments. With setArguments() you can replace + * arguments that are used to call the controller. + * + * Arguments set in the event must be compatible with the signature of the + * controller. + * + * @author Christophe Coevoet + */ +class ControllerArgumentsEvent extends FilterControllerArgumentsEvent +{ +} diff --git a/src/Symfony/Component/HttpKernel/Event/ControllerEvent.php b/src/Symfony/Component/HttpKernel/Event/ControllerEvent.php new file mode 100644 index 000000000000..9afb818a1d4f --- /dev/null +++ b/src/Symfony/Component/HttpKernel/Event/ControllerEvent.php @@ -0,0 +1,27 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\HttpKernel\Event; + +/** + * Allows filtering of a controller callable. + * + * You can call getController() to retrieve the current controller. With + * setController() you can set a new controller that is used in the processing + * of the request. + * + * Controllers should be callables. + * + * @author Bernhard Schussek + */ +class ControllerEvent extends FilterControllerEvent +{ +} diff --git a/src/Symfony/Component/HttpKernel/Event/ExceptionEvent.php b/src/Symfony/Component/HttpKernel/Event/ExceptionEvent.php new file mode 100644 index 000000000000..d3b2d8f6061f --- /dev/null +++ b/src/Symfony/Component/HttpKernel/Event/ExceptionEvent.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\HttpKernel\Event; + +/** + * Allows to create a response for a thrown exception. + * + * Call setResponse() to set the response that will be returned for the + * current request. The propagation of this event is stopped as soon as a + * response is set. + * + * You can also call setException() to replace the thrown exception. This + * exception will be thrown if no response is set during processing of this + * event. + * + * @author Bernhard Schussek + */ +class ExceptionEvent extends GetResponseForExceptionEvent +{ +} diff --git a/src/Symfony/Component/HttpKernel/Event/FilterControllerArgumentsEvent.php b/src/Symfony/Component/HttpKernel/Event/FilterControllerArgumentsEvent.php index 5e178f2b0bde..ac8e0263cabf 100644 --- a/src/Symfony/Component/HttpKernel/Event/FilterControllerArgumentsEvent.php +++ b/src/Symfony/Component/HttpKernel/Event/FilterControllerArgumentsEvent.php @@ -15,18 +15,9 @@ use Symfony\Component\HttpKernel\HttpKernelInterface; /** - * Allows filtering of controller arguments. - * - * You can call getController() to retrieve the controller and getArguments - * to retrieve the current arguments. With setArguments() you can replace - * arguments that are used to call the controller. - * - * Arguments set in the event must be compatible with the signature of the - * controller. - * - * @author Christophe Coevoet + * @deprecated since Symfony 4.3, use ControllerArgumentsEvent instead */ -class FilterControllerArgumentsEvent extends FilterControllerEvent +class FilterControllerArgumentsEvent extends ControllerEvent { private $arguments; diff --git a/src/Symfony/Component/HttpKernel/Event/FilterControllerEvent.php b/src/Symfony/Component/HttpKernel/Event/FilterControllerEvent.php index 7eab4493769b..74fa681f8098 100644 --- a/src/Symfony/Component/HttpKernel/Event/FilterControllerEvent.php +++ b/src/Symfony/Component/HttpKernel/Event/FilterControllerEvent.php @@ -15,15 +15,7 @@ use Symfony\Component\HttpKernel\HttpKernelInterface; /** - * Allows filtering of a controller callable. - * - * You can call getController() to retrieve the current controller. With - * setController() you can set a new controller that is used in the processing - * of the request. - * - * Controllers should be callables. - * - * @author Bernhard Schussek + * @deprecated since Symfony 4.3, use ControllerEvent instead */ class FilterControllerEvent extends KernelEvent { diff --git a/src/Symfony/Component/HttpKernel/Event/FilterResponseEvent.php b/src/Symfony/Component/HttpKernel/Event/FilterResponseEvent.php index 04589f7b5c32..eaa2e8256540 100644 --- a/src/Symfony/Component/HttpKernel/Event/FilterResponseEvent.php +++ b/src/Symfony/Component/HttpKernel/Event/FilterResponseEvent.php @@ -16,13 +16,7 @@ use Symfony\Component\HttpKernel\HttpKernelInterface; /** - * Allows to filter a Response object. - * - * You can call getResponse() to retrieve the current response. With - * setResponse() you can set a new response that will be returned to the - * browser. - * - * @author Bernhard Schussek + * @deprecated since Symfony 4.3, use ResponseEvent instead */ class FilterResponseEvent extends KernelEvent { diff --git a/src/Symfony/Component/HttpKernel/Event/GetResponseEvent.php b/src/Symfony/Component/HttpKernel/Event/GetResponseEvent.php index c25a0f1cf1a1..fbed7beef570 100644 --- a/src/Symfony/Component/HttpKernel/Event/GetResponseEvent.php +++ b/src/Symfony/Component/HttpKernel/Event/GetResponseEvent.php @@ -14,13 +14,7 @@ use Symfony\Component\HttpFoundation\Response; /** - * Allows to create a response for a request. - * - * Call setResponse() to set the response that will be returned for the - * current request. The propagation of this event is stopped as soon as a - * response is set. - * - * @author Bernhard Schussek + * @deprecated since Symfony 4.3, use RequestEvent instead */ class GetResponseEvent extends KernelEvent { diff --git a/src/Symfony/Component/HttpKernel/Event/GetResponseForControllerResultEvent.php b/src/Symfony/Component/HttpKernel/Event/GetResponseForControllerResultEvent.php index a0082821decc..4e70dbc63e53 100644 --- a/src/Symfony/Component/HttpKernel/Event/GetResponseForControllerResultEvent.php +++ b/src/Symfony/Component/HttpKernel/Event/GetResponseForControllerResultEvent.php @@ -15,15 +15,9 @@ use Symfony\Component\HttpKernel\HttpKernelInterface; /** - * Allows to create a response for the return value of a controller. - * - * Call setResponse() to set the response that will be returned for the - * current request. The propagation of this event is stopped as soon as a - * response is set. - * - * @author Bernhard Schussek + * @deprecated since Symfony 4.3, use ViewEvent instead */ -class GetResponseForControllerResultEvent extends GetResponseEvent +class GetResponseForControllerResultEvent extends RequestEvent { /** * The return value of the controller. diff --git a/src/Symfony/Component/HttpKernel/Event/GetResponseForExceptionEvent.php b/src/Symfony/Component/HttpKernel/Event/GetResponseForExceptionEvent.php index 7fab006d1305..3476c7e62a0c 100644 --- a/src/Symfony/Component/HttpKernel/Event/GetResponseForExceptionEvent.php +++ b/src/Symfony/Component/HttpKernel/Event/GetResponseForExceptionEvent.php @@ -15,19 +15,9 @@ use Symfony\Component\HttpKernel\HttpKernelInterface; /** - * Allows to create a response for a thrown exception. - * - * Call setResponse() to set the response that will be returned for the - * current request. The propagation of this event is stopped as soon as a - * response is set. - * - * You can also call setException() to replace the thrown exception. This - * exception will be thrown if no response is set during processing of this - * event. - * - * @author Bernhard Schussek + * @deprecated since Symfony 4.3, use ExceptionEvent instead */ -class GetResponseForExceptionEvent extends GetResponseEvent +class GetResponseForExceptionEvent extends RequestEvent { /** * The exception object. diff --git a/src/Symfony/Component/HttpKernel/Event/PostResponseEvent.php b/src/Symfony/Component/HttpKernel/Event/PostResponseEvent.php index 0981e64c9235..b86bf0774241 100644 --- a/src/Symfony/Component/HttpKernel/Event/PostResponseEvent.php +++ b/src/Symfony/Component/HttpKernel/Event/PostResponseEvent.php @@ -16,12 +16,7 @@ use Symfony\Component\HttpKernel\HttpKernelInterface; /** - * Allows to execute logic after a response was sent. - * - * Since it's only triggered on master requests, the `getRequestType()` method - * will always return the value of `HttpKernelInterface::MASTER_REQUEST`. - * - * @author Jordi Boggiano + * @deprecated since Symfony 4.3, use TerminateEvent instead */ class PostResponseEvent extends KernelEvent { diff --git a/src/Symfony/Component/HttpKernel/Event/RequestEvent.php b/src/Symfony/Component/HttpKernel/Event/RequestEvent.php new file mode 100644 index 000000000000..c1beb929f31e --- /dev/null +++ b/src/Symfony/Component/HttpKernel/Event/RequestEvent.php @@ -0,0 +1,25 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\HttpKernel\Event; + +/** + * Allows to create a response for a request. + * + * Call setResponse() to set the response that will be returned for the + * current request. The propagation of this event is stopped as soon as a + * response is set. + * + * @author Bernhard Schussek + */ +class RequestEvent extends GetResponseEvent +{ +} diff --git a/src/Symfony/Component/HttpKernel/Event/ResponseEvent.php b/src/Symfony/Component/HttpKernel/Event/ResponseEvent.php new file mode 100644 index 000000000000..88c1996eaa95 --- /dev/null +++ b/src/Symfony/Component/HttpKernel/Event/ResponseEvent.php @@ -0,0 +1,25 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\HttpKernel\Event; + +/** + * Allows to filter a Response object. + * + * You can call getResponse() to retrieve the current response. With + * setResponse() you can set a new response that will be returned to the + * browser. + * + * @author Bernhard Schussek + */ +class ResponseEvent extends FilterResponseEvent +{ +} diff --git a/src/Symfony/Component/HttpKernel/Event/TerminateEvent.php b/src/Symfony/Component/HttpKernel/Event/TerminateEvent.php new file mode 100644 index 000000000000..6ce23e43f310 --- /dev/null +++ b/src/Symfony/Component/HttpKernel/Event/TerminateEvent.php @@ -0,0 +1,24 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\HttpKernel\Event; + +/** + * Allows to execute logic after a response was sent. + * + * Since it's only triggered on master requests, the `getRequestType()` method + * will always return the value of `HttpKernelInterface::MASTER_REQUEST`. + * + * @author Jordi Boggiano + */ +class TerminateEvent extends PostResponseEvent +{ +} diff --git a/src/Symfony/Component/HttpKernel/Event/ViewEvent.php b/src/Symfony/Component/HttpKernel/Event/ViewEvent.php new file mode 100644 index 000000000000..1cb7e23980ba --- /dev/null +++ b/src/Symfony/Component/HttpKernel/Event/ViewEvent.php @@ -0,0 +1,25 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\HttpKernel\Event; + +/** + * Allows to create a response for the return value of a controller. + * + * Call setResponse() to set the response that will be returned for the + * current request. The propagation of this event is stopped as soon as a + * response is set. + * + * @author Bernhard Schussek + */ +class ViewEvent extends GetResponseForControllerResultEvent +{ +} diff --git a/src/Symfony/Component/HttpKernel/EventListener/AbstractSessionListener.php b/src/Symfony/Component/HttpKernel/EventListener/AbstractSessionListener.php index 80d57e506a2b..d89bc813f738 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/AbstractSessionListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/AbstractSessionListener.php @@ -32,6 +32,8 @@ * * @author Johannes M. Schmitt * @author Tobias Schultze + * + * @internal since Symfony 4.3 */ abstract class AbstractSessionListener implements EventSubscriberInterface { diff --git a/src/Symfony/Component/HttpKernel/EventListener/AbstractTestSessionListener.php b/src/Symfony/Component/HttpKernel/EventListener/AbstractTestSessionListener.php index 58b3580024c5..054695e6f2ab 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/AbstractTestSessionListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/AbstractTestSessionListener.php @@ -26,6 +26,8 @@ * * @author Bulat Shakirzyanov * @author Fabien Potencier + * + * @internal since Symfony 4.3 */ abstract class AbstractTestSessionListener implements EventSubscriberInterface { diff --git a/src/Symfony/Component/HttpKernel/EventListener/AddRequestFormatsListener.php b/src/Symfony/Component/HttpKernel/EventListener/AddRequestFormatsListener.php index 2372575517a1..47c7069c9ead 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/AddRequestFormatsListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/AddRequestFormatsListener.php @@ -19,6 +19,8 @@ * Adds configured formats to each request. * * @author Gildas Quemener + * + * @final since Symfony 4.3 */ class AddRequestFormatsListener implements EventSubscriberInterface { diff --git a/src/Symfony/Component/HttpKernel/EventListener/DisallowRobotsIndexingListener.php b/src/Symfony/Component/HttpKernel/EventListener/DisallowRobotsIndexingListener.php index 280bd90d069b..6607e49e999e 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/DisallowRobotsIndexingListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/DisallowRobotsIndexingListener.php @@ -12,7 +12,7 @@ namespace Symfony\Component\HttpKernel\EventListener; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; +use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\HttpKernel\KernelEvents; /** @@ -24,7 +24,7 @@ class DisallowRobotsIndexingListener implements EventSubscriberInterface { private const HEADER_NAME = 'X-Robots-Tag'; - public function onResponse(FilterResponseEvent $event): void + public function onResponse(ResponseEvent $event): void { if (!$event->getResponse()->headers->has(static::HEADER_NAME)) { $event->getResponse()->headers->set(static::HEADER_NAME, 'noindex'); diff --git a/src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php b/src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php index 811f99bd9de8..9d6d31ea96e6 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php @@ -18,7 +18,6 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface; use Symfony\Component\HttpKernel\HttpKernelInterface; @@ -26,9 +25,9 @@ use Symfony\Component\HttpKernel\Log\DebugLoggerInterface; /** - * ExceptionListener. - * * @author Fabien Potencier + * + * @final since Symfony 4.3 */ class ExceptionListener implements EventSubscriberInterface { @@ -96,7 +95,7 @@ public function onKernelException(GetResponseForExceptionEvent $event) $event->setResponse($response); if ($this->debug && $eventDispatcher instanceof EventDispatcherInterface) { - $cspRemovalListener = function (FilterResponseEvent $event) use (&$cspRemovalListener, $eventDispatcher) { + $cspRemovalListener = function ($event) use (&$cspRemovalListener, $eventDispatcher) { $event->getResponse()->headers->remove('Content-Security-Policy'); $eventDispatcher->removeListener(KernelEvents::RESPONSE, $cspRemovalListener); }; diff --git a/src/Symfony/Component/HttpKernel/EventListener/FragmentListener.php b/src/Symfony/Component/HttpKernel/EventListener/FragmentListener.php index 5a789a3eb9b2..32435ec8662a 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/FragmentListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/FragmentListener.php @@ -28,6 +28,8 @@ * is not signed or if it is not an internal sub-request. * * @author Fabien Potencier + * + * @final since Symfony 4.3 */ class FragmentListener implements EventSubscriberInterface { diff --git a/src/Symfony/Component/HttpKernel/EventListener/LocaleListener.php b/src/Symfony/Component/HttpKernel/EventListener/LocaleListener.php index 0c21d74020aa..cb8a194d49a9 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/LocaleListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/LocaleListener.php @@ -24,6 +24,8 @@ * Initializes the locale based on the current request. * * @author Fabien Potencier + * + * @final since Symfony 4.3 */ class LocaleListener implements EventSubscriberInterface { diff --git a/src/Symfony/Component/HttpKernel/EventListener/ProfilerListener.php b/src/Symfony/Component/HttpKernel/EventListener/ProfilerListener.php index df0e5cf8a68f..85a0aacb6184 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/ProfilerListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/ProfilerListener.php @@ -24,6 +24,8 @@ * ProfilerListener collects data for the current request by listening to the kernel events. * * @author Fabien Potencier + * + * @final since Symfony 4.3 */ class ProfilerListener implements EventSubscriberInterface { diff --git a/src/Symfony/Component/HttpKernel/EventListener/ResponseListener.php b/src/Symfony/Component/HttpKernel/EventListener/ResponseListener.php index 331694b176e6..01973e222a09 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/ResponseListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/ResponseListener.php @@ -19,6 +19,8 @@ * ResponseListener fixes the Response headers based on the Request. * * @author Fabien Potencier + * + * @final since Symfony 4.3 */ class ResponseListener implements EventSubscriberInterface { diff --git a/src/Symfony/Component/HttpKernel/EventListener/RouterListener.php b/src/Symfony/Component/HttpKernel/EventListener/RouterListener.php index 3098657760ef..01a95ebffbd2 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/RouterListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/RouterListener.php @@ -37,6 +37,8 @@ * * @author Fabien Potencier * @author Yonel Ceruto + * + * @final since Symfony 4.3 */ class RouterListener implements EventSubscriberInterface { diff --git a/src/Symfony/Component/HttpKernel/EventListener/StreamedResponseListener.php b/src/Symfony/Component/HttpKernel/EventListener/StreamedResponseListener.php index 895176a931ae..f28f5d868a2b 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/StreamedResponseListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/StreamedResponseListener.php @@ -21,6 +21,8 @@ * to the client. * * @author Fabien Potencier + * + * @final since Symfony 4.3 */ class StreamedResponseListener implements EventSubscriberInterface { diff --git a/src/Symfony/Component/HttpKernel/EventListener/SurrogateListener.php b/src/Symfony/Component/HttpKernel/EventListener/SurrogateListener.php index 0fddddde4233..9c3e960b0073 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/SurrogateListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/SurrogateListener.php @@ -21,6 +21,8 @@ * SurrogateListener adds a Surrogate-Control HTTP header when the Response needs to be parsed for Surrogates. * * @author Fabien Potencier + * + * @final since Symfony 4.3 */ class SurrogateListener implements EventSubscriberInterface { diff --git a/src/Symfony/Component/HttpKernel/EventListener/TranslatorListener.php b/src/Symfony/Component/HttpKernel/EventListener/TranslatorListener.php index 361b11fcec03..4d022f750c6f 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/TranslatorListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/TranslatorListener.php @@ -24,6 +24,8 @@ * Synchronizes the locale between the request and the translator. * * @author Fabien Potencier + * + * @final since Symfony 4.3 */ class TranslatorListener implements EventSubscriberInterface { diff --git a/src/Symfony/Component/HttpKernel/EventListener/ValidateRequestListener.php b/src/Symfony/Component/HttpKernel/EventListener/ValidateRequestListener.php index 2e921869b92f..69c86b409564 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/ValidateRequestListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/ValidateRequestListener.php @@ -19,6 +19,8 @@ * Validates Requests. * * @author Magnus Nordlander + * + * @final since Symfony 4.3 */ class ValidateRequestListener implements EventSubscriberInterface { diff --git a/src/Symfony/Component/HttpKernel/Fragment/InlineFragmentRenderer.php b/src/Symfony/Component/HttpKernel/Fragment/InlineFragmentRenderer.php index c01b09559afd..bc397438d248 100644 --- a/src/Symfony/Component/HttpKernel/Fragment/InlineFragmentRenderer.php +++ b/src/Symfony/Component/HttpKernel/Fragment/InlineFragmentRenderer.php @@ -12,10 +12,11 @@ namespace Symfony\Component\HttpKernel\Fragment; use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Controller\ControllerReference; -use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; +use Symfony\Component\HttpKernel\Event\ExceptionEvent; use Symfony\Component\HttpKernel\HttpCache\SubRequestHandler; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\KernelEvents; @@ -33,7 +34,7 @@ class InlineFragmentRenderer extends RoutableFragmentRenderer public function __construct(HttpKernelInterface $kernel, EventDispatcherInterface $dispatcher = null) { $this->kernel = $kernel; - $this->dispatcher = $dispatcher; + $this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher); } /** @@ -82,9 +83,9 @@ public function render($uri, Request $request, array $options = []) // we dispatch the exception event to trigger the logging // the response that comes back is ignored if (isset($options['ignore_errors']) && $options['ignore_errors'] && $this->dispatcher) { - $event = new GetResponseForExceptionEvent($this->kernel, $request, HttpKernelInterface::SUB_REQUEST, $e); + $event = new ExceptionEvent($this->kernel, $request, HttpKernelInterface::SUB_REQUEST, $e); - $this->dispatcher->dispatch(KernelEvents::EXCEPTION, $event); + $this->dispatcher->dispatch($event, KernelEvents::EXCEPTION); } // let's clean up the output buffers that were created by the sub-request diff --git a/src/Symfony/Component/HttpKernel/HttpKernel.php b/src/Symfony/Component/HttpKernel/HttpKernel.php index 11eb718aff08..3de9b0202b53 100644 --- a/src/Symfony/Component/HttpKernel/HttpKernel.php +++ b/src/Symfony/Component/HttpKernel/HttpKernel.php @@ -12,6 +12,7 @@ namespace Symfony\Component\HttpKernel; use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy; use Symfony\Component\HttpFoundation\Exception\RequestExceptionInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; @@ -19,14 +20,14 @@ use Symfony\Component\HttpKernel\Controller\ArgumentResolver; use Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface; use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface; -use Symfony\Component\HttpKernel\Event\FilterControllerArgumentsEvent; -use Symfony\Component\HttpKernel\Event\FilterControllerEvent; -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; +use Symfony\Component\HttpKernel\Event\ControllerArgumentsEvent; +use Symfony\Component\HttpKernel\Event\ControllerEvent; +use Symfony\Component\HttpKernel\Event\ExceptionEvent; use Symfony\Component\HttpKernel\Event\FinishRequestEvent; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; -use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent; -use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; -use Symfony\Component\HttpKernel\Event\PostResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; +use Symfony\Component\HttpKernel\Event\ResponseEvent; +use Symfony\Component\HttpKernel\Event\TerminateEvent; +use Symfony\Component\HttpKernel\Event\ViewEvent; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\HttpKernel\Exception\ControllerDoesNotReturnResponseException; use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface; @@ -46,7 +47,7 @@ class HttpKernel implements HttpKernelInterface, TerminableInterface public function __construct(EventDispatcherInterface $dispatcher, ControllerResolverInterface $resolver, RequestStack $requestStack = null, ArgumentResolverInterface $argumentResolver = null) { - $this->dispatcher = $dispatcher; + $this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher); $this->resolver = $resolver; $this->requestStack = $requestStack ?: new RequestStack(); $this->argumentResolver = $argumentResolver; @@ -84,7 +85,7 @@ public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQ */ public function terminate(Request $request, Response $response) { - $this->dispatcher->dispatch(KernelEvents::TERMINATE, new PostResponseEvent($this, $request, $response)); + $this->dispatcher->dispatch(new TerminateEvent($this, $request, $response), KernelEvents::TERMINATE); } /** @@ -122,8 +123,8 @@ private function handleRaw(Request $request, int $type = self::MASTER_REQUEST) $this->requestStack->push($request); // request - $event = new GetResponseEvent($this, $request, $type); - $this->dispatcher->dispatch(KernelEvents::REQUEST, $event); + $event = new RequestEvent($this, $request, $type); + $this->dispatcher->dispatch($event, KernelEvents::REQUEST); if ($event->hasResponse()) { return $this->filterResponse($event->getResponse(), $request, $type); @@ -134,15 +135,15 @@ private function handleRaw(Request $request, int $type = self::MASTER_REQUEST) throw new NotFoundHttpException(sprintf('Unable to find the controller for path "%s". The route is wrongly configured.', $request->getPathInfo())); } - $event = new FilterControllerEvent($this, $controller, $request, $type); - $this->dispatcher->dispatch(KernelEvents::CONTROLLER, $event); + $event = new ControllerEvent($this, $controller, $request, $type); + $this->dispatcher->dispatch($event, KernelEvents::CONTROLLER); $controller = $event->getController(); // controller arguments $arguments = $this->argumentResolver->getArguments($request, $controller); - $event = new FilterControllerArgumentsEvent($this, $controller, $arguments, $request, $type); - $this->dispatcher->dispatch(KernelEvents::CONTROLLER_ARGUMENTS, $event); + $event = new ControllerArgumentsEvent($this, $controller, $arguments, $request, $type); + $this->dispatcher->dispatch($event, KernelEvents::CONTROLLER_ARGUMENTS); $controller = $event->getController(); $arguments = $event->getArguments(); @@ -151,8 +152,8 @@ private function handleRaw(Request $request, int $type = self::MASTER_REQUEST) // view if (!$response instanceof Response) { - $event = new GetResponseForControllerResultEvent($this, $request, $type, $response); - $this->dispatcher->dispatch(KernelEvents::VIEW, $event); + $event = new ViewEvent($this, $request, $type, $response); + $this->dispatcher->dispatch($event, KernelEvents::VIEW); if ($event->hasResponse()) { $response = $event->getResponse(); @@ -184,9 +185,9 @@ private function handleRaw(Request $request, int $type = self::MASTER_REQUEST) */ private function filterResponse(Response $response, Request $request, int $type) { - $event = new FilterResponseEvent($this, $request, $type, $response); + $event = new ResponseEvent($this, $request, $type, $response); - $this->dispatcher->dispatch(KernelEvents::RESPONSE, $event); + $this->dispatcher->dispatch($event, KernelEvents::RESPONSE); $this->finishRequest($request, $type); @@ -202,7 +203,7 @@ private function filterResponse(Response $response, Request $request, int $type) */ private function finishRequest(Request $request, int $type) { - $this->dispatcher->dispatch(KernelEvents::FINISH_REQUEST, new FinishRequestEvent($this, $request, $type)); + $this->dispatcher->dispatch(new FinishRequestEvent($this, $request, $type), KernelEvents::FINISH_REQUEST); $this->requestStack->pop(); } @@ -217,8 +218,8 @@ private function finishRequest(Request $request, int $type) */ private function handleException(\Exception $e, Request $request, int $type): Response { - $event = new GetResponseForExceptionEvent($this, $request, $type, $e); - $this->dispatcher->dispatch(KernelEvents::EXCEPTION, $event); + $event = new ExceptionEvent($this, $request, $type, $e); + $this->dispatcher->dispatch($event, KernelEvents::EXCEPTION); // a listener might have replaced the exception $e = $event->getException(); diff --git a/src/Symfony/Component/HttpKernel/KernelEvents.php b/src/Symfony/Component/HttpKernel/KernelEvents.php index 674376325859..682561c32496 100644 --- a/src/Symfony/Component/HttpKernel/KernelEvents.php +++ b/src/Symfony/Component/HttpKernel/KernelEvents.php @@ -25,7 +25,7 @@ final class KernelEvents * This event allows you to create a response for a request before any * other code in the framework is executed. * - * @Event("Symfony\Component\HttpKernel\Event\GetResponseEvent") + * @Event("Symfony\Component\HttpKernel\Event\RequestEvent") */ const REQUEST = 'kernel.request'; @@ -35,7 +35,7 @@ final class KernelEvents * This event allows you to create a response for a thrown exception or * to modify the thrown exception. * - * @Event("Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent") + * @Event("Symfony\Component\HttpKernel\Event\ExceptionEvent") */ const EXCEPTION = 'kernel.exception'; @@ -46,7 +46,7 @@ final class KernelEvents * This event allows you to create a response for the return value of the * controller. * - * @Event("Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent") + * @Event("Symfony\Component\HttpKernel\Event\ViewEvent") */ const VIEW = 'kernel.view'; @@ -57,7 +57,7 @@ final class KernelEvents * This event allows you to change the controller that will handle the * request. * - * @Event("Symfony\Component\HttpKernel\Event\FilterControllerEvent") + * @Event("Symfony\Component\HttpKernel\Event\ControllerEvent") */ const CONTROLLER = 'kernel.controller'; @@ -67,7 +67,7 @@ final class KernelEvents * This event allows you to change the arguments that will be passed to * the controller. * - * @Event("Symfony\Component\HttpKernel\Event\FilterControllerArgumentsEvent") + * @Event("Symfony\Component\HttpKernel\Event\ControllerArgumentsEvent") */ const CONTROLLER_ARGUMENTS = 'kernel.controller_arguments'; @@ -78,7 +78,7 @@ final class KernelEvents * This event allows you to modify or replace the response that will be * replied. * - * @Event("Symfony\Component\HttpKernel\Event\FilterResponseEvent") + * @Event("Symfony\Component\HttpKernel\Event\ResponseEvent") */ const RESPONSE = 'kernel.response'; @@ -87,7 +87,7 @@ final class KernelEvents * * This event allows you to run expensive post-response jobs. * - * @Event("Symfony\Component\HttpKernel\Event\PostResponseEvent") + * @Event("Symfony\Component\HttpKernel\Event\TerminateEvent") */ const TERMINATE = 'kernel.terminate'; diff --git a/src/Symfony/Component/HttpKernel/Tests/DataCollector/RequestDataCollectorTest.php b/src/Symfony/Component/HttpKernel/Tests/DataCollector/RequestDataCollectorTest.php index f32247fd3224..42215ea0f761 100644 --- a/src/Symfony/Component/HttpKernel/Tests/DataCollector/RequestDataCollectorTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/DataCollector/RequestDataCollectorTest.php @@ -22,8 +22,8 @@ use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; use Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface; use Symfony\Component\HttpKernel\DataCollector\RequestDataCollector; -use Symfony\Component\HttpKernel\Event\FilterControllerEvent; -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; +use Symfony\Component\HttpKernel\Event\ControllerEvent; +use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\HttpKernel\HttpKernel; use Symfony\Component\HttpKernel\HttpKernelInterface; @@ -206,7 +206,7 @@ public function testItAddsRedirectedAttributesWhenRequestContainsSpecificCookie( $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); $c = new RequestDataCollector(); - $c->onKernelResponse(new FilterResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $this->createResponse())); + $c->onKernelResponse(new ResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $this->createResponse())); $this->assertTrue($request->attributes->get('_redirected')); } @@ -290,7 +290,7 @@ protected function injectController($collector, $controller, $request) { $resolver = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface')->getMock(); $httpKernel = new HttpKernel(new EventDispatcher(), $resolver, null, $this->getMockBuilder(ArgumentResolverInterface::class)->getMock()); - $event = new FilterControllerEvent($httpKernel, $controller, $request, HttpKernelInterface::MASTER_REQUEST); + $event = new ControllerEvent($httpKernel, $controller, $request, HttpKernelInterface::MASTER_REQUEST); $collector->onKernelController($event); } diff --git a/src/Symfony/Component/HttpKernel/Tests/Debug/TraceableEventDispatcherTest.php b/src/Symfony/Component/HttpKernel/Tests/Debug/TraceableEventDispatcherTest.php index 8b8e91aeb474..ef4f4bf66a89 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Debug/TraceableEventDispatcherTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Debug/TraceableEventDispatcherTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\HttpKernel\Tests\Debug; use PHPUnit\Framework\TestCase; +use Symfony\Component\EventDispatcher\Event; use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; @@ -89,10 +90,10 @@ public function testAddListenerNested() $called2 = true; }); }); - $dispatcher->dispatch('my-event'); + $dispatcher->dispatch(new Event(), 'my-event'); $this->assertTrue($called1); $this->assertFalse($called2); - $dispatcher->dispatch('my-event'); + $dispatcher->dispatch(new Event(), 'my-event'); $this->assertTrue($called2); } @@ -104,7 +105,7 @@ public function testListenerCanRemoveItselfWhenExecuted() }; $eventDispatcher->addListener('foo', $listener1); $eventDispatcher->addListener('foo', function () {}); - $eventDispatcher->dispatch('foo'); + $eventDispatcher->dispatch(new Event(), 'foo'); $this->assertCount(1, $eventDispatcher->getListeners('foo'), 'expected listener1 to be removed'); } diff --git a/src/Symfony/Component/HttpKernel/Tests/Event/ControllerArgumentsEventTest.php b/src/Symfony/Component/HttpKernel/Tests/Event/ControllerArgumentsEventTest.php new file mode 100644 index 000000000000..50faf232919b --- /dev/null +++ b/src/Symfony/Component/HttpKernel/Tests/Event/ControllerArgumentsEventTest.php @@ -0,0 +1,17 @@ +assertEquals($filterController->getArguments(), array('test')); + } +} diff --git a/src/Symfony/Component/HttpKernel/Tests/Event/GetResponseForExceptionEventTest.php b/src/Symfony/Component/HttpKernel/Tests/Event/ExceptionEventTest.php similarity index 71% rename from src/Symfony/Component/HttpKernel/Tests/Event/GetResponseForExceptionEventTest.php rename to src/Symfony/Component/HttpKernel/Tests/Event/ExceptionEventTest.php index 7242579301d9..6b061d3a3388 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Event/GetResponseForExceptionEventTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Event/ExceptionEventTest.php @@ -13,14 +13,14 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; +use Symfony\Component\HttpKernel\Event\ExceptionEvent; use Symfony\Component\HttpKernel\Tests\TestHttpKernel; -class GetResponseForExceptionEventTest extends TestCase +class ExceptionEventTest extends TestCase { public function testAllowSuccessfulResponseIsFalseByDefault() { - $event = new GetResponseForExceptionEvent(new TestHttpKernel(), new Request(), 1, new \Exception()); + $event = new ExceptionEvent(new TestHttpKernel(), new Request(), 1, new \Exception()); $this->assertFalse($event->isAllowingCustomResponseCode()); } diff --git a/src/Symfony/Component/HttpKernel/Tests/Event/FilterControllerArgumentsEventTest.php b/src/Symfony/Component/HttpKernel/Tests/Event/FilterControllerArgumentsEventTest.php deleted file mode 100644 index abc51ac51e77..000000000000 --- a/src/Symfony/Component/HttpKernel/Tests/Event/FilterControllerArgumentsEventTest.php +++ /dev/null @@ -1,17 +0,0 @@ -assertEquals($filterController->getArguments(), ['test']); - } -} diff --git a/src/Symfony/Component/HttpKernel/Tests/EventListener/AddRequestFormatsListenerTest.php b/src/Symfony/Component/HttpKernel/Tests/EventListener/AddRequestFormatsListenerTest.php index b4f92f97c13d..b8b4719206db 100644 --- a/src/Symfony/Component/HttpKernel/Tests/EventListener/AddRequestFormatsListenerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/EventListener/AddRequestFormatsListenerTest.php @@ -13,6 +13,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\EventListener\AddRequestFormatsListener; use Symfony\Component\HttpKernel\KernelEvents; @@ -54,7 +55,7 @@ public function testRegisteredEvent() public function testSetAdditionalFormats() { $request = $this->getRequestMock(); - $event = $this->getGetResponseEventMock($request); + $event = $this->getRequestEventMock($request); $request->expects($this->once()) ->method('setFormat') @@ -68,10 +69,10 @@ protected function getRequestMock() return $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')->getMock(); } - protected function getGetResponseEventMock(Request $request) + protected function getRequestEventMock(Request $request) { $event = $this - ->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent') + ->getMockBuilder(RequestEvent::class) ->disableOriginalConstructor() ->getMock(); diff --git a/src/Symfony/Component/HttpKernel/Tests/EventListener/DebugHandlersListenerTest.php b/src/Symfony/Component/HttpKernel/Tests/EventListener/DebugHandlersListenerTest.php index d9e261d35af5..f1a56e537b8b 100644 --- a/src/Symfony/Component/HttpKernel/Tests/EventListener/DebugHandlersListenerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/EventListener/DebugHandlersListenerTest.php @@ -112,7 +112,7 @@ public function testConsoleEvent() set_error_handler([$eHandler, 'handleError']); set_exception_handler([$eHandler, 'handleException']); try { - $dispatcher->dispatch(ConsoleEvents::COMMAND, $event); + $dispatcher->dispatch($event, ConsoleEvents::COMMAND); } catch (\Exception $exception) { } restore_exception_handler(); diff --git a/src/Symfony/Component/HttpKernel/Tests/EventListener/DisallowRobotsIndexingListenerTest.php b/src/Symfony/Component/HttpKernel/Tests/EventListener/DisallowRobotsIndexingListenerTest.php index b50ace673b14..53b317b7611c 100644 --- a/src/Symfony/Component/HttpKernel/Tests/EventListener/DisallowRobotsIndexingListenerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/EventListener/DisallowRobotsIndexingListenerTest.php @@ -14,7 +14,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; +use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\HttpKernel\EventListener\DisallowRobotsIndexingListener; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\KernelInterface; @@ -28,7 +28,7 @@ public function testInvoke(?string $expected, Response $response): void { $listener = new DisallowRobotsIndexingListener(); - $event = new FilterResponseEvent($this->createMock(HttpKernelInterface::class), $this->createMock(Request::class), KernelInterface::MASTER_REQUEST, $response); + $event = new ResponseEvent($this->createMock(HttpKernelInterface::class), $this->createMock(Request::class), KernelInterface::MASTER_REQUEST, $response); $listener->onResponse($event); diff --git a/src/Symfony/Component/HttpKernel/Tests/EventListener/ExceptionListenerTest.php b/src/Symfony/Component/HttpKernel/Tests/EventListener/ExceptionListenerTest.php index b7224ddceaad..18763c881bd3 100644 --- a/src/Symfony/Component/HttpKernel/Tests/EventListener/ExceptionListenerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/EventListener/ExceptionListenerTest.php @@ -15,8 +15,8 @@ use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; -use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; +use Symfony\Component\HttpKernel\Event\ExceptionEvent; +use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\HttpKernel\EventListener\ExceptionListener; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\KernelEvents; @@ -103,8 +103,8 @@ public function provider() $request = new Request(); $exception = new \Exception('foo'); - $event = new GetResponseForExceptionEvent(new TestKernel(), $request, HttpKernelInterface::MASTER_REQUEST, $exception); - $event2 = new GetResponseForExceptionEvent(new TestKernelThatThrowsException(), $request, HttpKernelInterface::MASTER_REQUEST, $exception); + $event = new ExceptionEvent(new TestKernel(), $request, HttpKernelInterface::MASTER_REQUEST, $exception); + $event2 = new ExceptionEvent(new TestKernelThatThrowsException(), $request, HttpKernelInterface::MASTER_REQUEST, $exception); return [ [$event, $event2], @@ -123,7 +123,7 @@ public function testSubRequestFormat() $request = Request::create('/'); $request->setRequestFormat('xml'); - $event = new GetResponseForExceptionEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, new \Exception('foo')); + $event = new ExceptionEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, new \Exception('foo')); $listener->onKernelException($event); $response = $event->getResponse(); @@ -143,14 +143,14 @@ public function testCSPHeaderIsRemoved() $dispatcher->addSubscriber($listener); $request = Request::create('/'); - $event = new GetResponseForExceptionEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, new \Exception('foo')); - $dispatcher->dispatch(KernelEvents::EXCEPTION, $event); + $event = new ExceptionEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, new \Exception('foo')); + $dispatcher->dispatch($event, KernelEvents::EXCEPTION); $response = new Response('', 200, ['content-security-policy' => "style-src 'self'"]); $this->assertTrue($response->headers->has('content-security-policy')); - $event = new FilterResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response); - $dispatcher->dispatch(KernelEvents::RESPONSE, $event); + $event = new ResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response); + $dispatcher->dispatch($event, KernelEvents::RESPONSE); $this->assertFalse($response->headers->has('content-security-policy'), 'CSP header has been removed'); $this->assertFalse($dispatcher->hasListeners(KernelEvents::RESPONSE), 'CSP removal listener has been removed'); @@ -166,7 +166,7 @@ public function testNullController() return $controller(); })); $request = Request::create('/'); - $event = new GetResponseForExceptionEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, new \Exception('foo')); + $event = new ExceptionEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, new \Exception('foo')); $listener->onKernelException($event); $this->assertNull($event->getResponse()); diff --git a/src/Symfony/Component/HttpKernel/Tests/EventListener/FragmentListenerTest.php b/src/Symfony/Component/HttpKernel/Tests/EventListener/FragmentListenerTest.php index 6408b1b21c7e..40da65d24030 100644 --- a/src/Symfony/Component/HttpKernel/Tests/EventListener/FragmentListenerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/EventListener/FragmentListenerTest.php @@ -13,7 +13,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\EventListener\FragmentListener; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\UriSigner; @@ -25,7 +25,7 @@ public function testOnlyTriggeredOnFragmentRoute() $request = Request::create('http://example.com/foo?_path=foo%3Dbar%26_controller%3Dfoo'); $listener = new FragmentListener(new UriSigner('foo')); - $event = $this->createGetResponseEvent($request); + $event = $this->createRequestEvent($request); $expected = $request->attributes->all(); @@ -41,7 +41,7 @@ public function testOnlyTriggeredIfControllerWasNotDefinedYet() $request->attributes->set('_controller', 'bar'); $listener = new FragmentListener(new UriSigner('foo')); - $event = $this->createGetResponseEvent($request, HttpKernelInterface::SUB_REQUEST); + $event = $this->createRequestEvent($request, HttpKernelInterface::SUB_REQUEST); $expected = $request->attributes->all(); @@ -58,7 +58,7 @@ public function testAccessDeniedWithNonSafeMethods() $request = Request::create('http://example.com/_fragment', 'POST'); $listener = new FragmentListener(new UriSigner('foo')); - $event = $this->createGetResponseEvent($request); + $event = $this->createRequestEvent($request); $listener->onKernelRequest($event); } @@ -71,7 +71,7 @@ public function testAccessDeniedWithWrongSignature() $request = Request::create('http://example.com/_fragment', 'GET', [], [], [], ['REMOTE_ADDR' => '10.0.0.1']); $listener = new FragmentListener(new UriSigner('foo')); - $event = $this->createGetResponseEvent($request); + $event = $this->createRequestEvent($request); $listener->onKernelRequest($event); } @@ -82,7 +82,7 @@ public function testWithSignature() $request = Request::create($signer->sign('http://example.com/_fragment?_path=foo%3Dbar%26_controller%3Dfoo'), 'GET', [], [], [], ['REMOTE_ADDR' => '10.0.0.1']); $listener = new FragmentListener($signer); - $event = $this->createGetResponseEvent($request); + $event = $this->createRequestEvent($request); $listener->onKernelRequest($event); @@ -95,7 +95,7 @@ public function testRemovesPathWithControllerDefined() $request = Request::create('http://example.com/_fragment?_path=foo%3Dbar%26_controller%3Dfoo'); $listener = new FragmentListener(new UriSigner('foo')); - $event = $this->createGetResponseEvent($request, HttpKernelInterface::SUB_REQUEST); + $event = $this->createRequestEvent($request, HttpKernelInterface::SUB_REQUEST); $listener->onKernelRequest($event); @@ -108,15 +108,15 @@ public function testRemovesPathWithControllerNotDefined() $request = Request::create($signer->sign('http://example.com/_fragment?_path=foo%3Dbar'), 'GET', [], [], [], ['REMOTE_ADDR' => '10.0.0.1']); $listener = new FragmentListener($signer); - $event = $this->createGetResponseEvent($request); + $event = $this->createRequestEvent($request); $listener->onKernelRequest($event); $this->assertFalse($request->query->has('_path')); } - private function createGetResponseEvent(Request $request, $requestType = HttpKernelInterface::MASTER_REQUEST) + private function createRequestEvent(Request $request, $requestType = HttpKernelInterface::MASTER_REQUEST) { - return new GetResponseEvent($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $request, $requestType); + return new RequestEvent($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $request, $requestType); } } diff --git a/src/Symfony/Component/HttpKernel/Tests/EventListener/LocaleListenerTest.php b/src/Symfony/Component/HttpKernel/Tests/EventListener/LocaleListenerTest.php index 5462fec978f4..1e9fbe23b380 100644 --- a/src/Symfony/Component/HttpKernel/Tests/EventListener/LocaleListenerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/EventListener/LocaleListenerTest.php @@ -14,7 +14,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\EventListener\LocaleListener; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\KernelEvents; @@ -113,8 +113,8 @@ public function testRequestLocaleIsNotOverridden() $this->assertEquals('de', $request->getLocale()); } - private function getEvent(Request $request) + private function getEvent(Request $request): RequestEvent { - return new GetResponseEvent($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $request, HttpKernelInterface::MASTER_REQUEST); + return new RequestEvent($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $request, HttpKernelInterface::MASTER_REQUEST); } } diff --git a/src/Symfony/Component/HttpKernel/Tests/EventListener/ProfilerListenerTest.php b/src/Symfony/Component/HttpKernel/Tests/EventListener/ProfilerListenerTest.php index 392aa2fc3581..6e73d0e9b05e 100644 --- a/src/Symfony/Component/HttpKernel/Tests/EventListener/ProfilerListenerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/EventListener/ProfilerListenerTest.php @@ -13,9 +13,9 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\RequestStack; -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; -use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; -use Symfony\Component\HttpKernel\Event\PostResponseEvent; +use Symfony\Component\HttpKernel\Event\ExceptionEvent; +use Symfony\Component\HttpKernel\Event\ResponseEvent; +use Symfony\Component\HttpKernel\Event\TerminateEvent; use Symfony\Component\HttpKernel\EventListener\ProfilerListener; use Symfony\Component\HttpKernel\Exception\HttpException; use Symfony\Component\HttpKernel\Kernel; @@ -59,12 +59,12 @@ public function testKernelTerminate() $listener = new ProfilerListener($profiler, $requestStack, null, $onlyException); // master request - $listener->onKernelResponse(new FilterResponseEvent($kernel, $masterRequest, Kernel::MASTER_REQUEST, $response)); + $listener->onKernelResponse(new ResponseEvent($kernel, $masterRequest, Kernel::MASTER_REQUEST, $response)); // sub request - $listener->onKernelException(new GetResponseForExceptionEvent($kernel, $subRequest, Kernel::SUB_REQUEST, new HttpException(404))); - $listener->onKernelResponse(new FilterResponseEvent($kernel, $subRequest, Kernel::SUB_REQUEST, $response)); + $listener->onKernelException(new ExceptionEvent($kernel, $subRequest, Kernel::SUB_REQUEST, new HttpException(404))); + $listener->onKernelResponse(new ResponseEvent($kernel, $subRequest, Kernel::SUB_REQUEST, $response)); - $listener->onKernelTerminate(new PostResponseEvent($kernel, $masterRequest, $response)); + $listener->onKernelTerminate(new TerminateEvent($kernel, $masterRequest, $response)); } } diff --git a/src/Symfony/Component/HttpKernel/Tests/EventListener/ResponseListenerTest.php b/src/Symfony/Component/HttpKernel/Tests/EventListener/ResponseListenerTest.php index aeab68f3e915..fbb2512c535c 100644 --- a/src/Symfony/Component/HttpKernel/Tests/EventListener/ResponseListenerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/EventListener/ResponseListenerTest.php @@ -15,7 +15,7 @@ use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; +use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\HttpKernel\EventListener\ResponseListener; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\KernelEvents; @@ -45,8 +45,8 @@ public function testFilterDoesNothingForSubRequests() { $response = new Response('foo'); - $event = new FilterResponseEvent($this->kernel, new Request(), HttpKernelInterface::SUB_REQUEST, $response); - $this->dispatcher->dispatch(KernelEvents::RESPONSE, $event); + $event = new ResponseEvent($this->kernel, new Request(), HttpKernelInterface::SUB_REQUEST, $response); + $this->dispatcher->dispatch($event, KernelEvents::RESPONSE); $this->assertEquals('', $event->getResponse()->headers->get('content-type')); } @@ -58,8 +58,8 @@ public function testFilterSetsNonDefaultCharsetIfNotOverridden() $response = new Response('foo'); - $event = new FilterResponseEvent($this->kernel, Request::create('/'), HttpKernelInterface::MASTER_REQUEST, $response); - $this->dispatcher->dispatch(KernelEvents::RESPONSE, $event); + $event = new ResponseEvent($this->kernel, Request::create('/'), HttpKernelInterface::MASTER_REQUEST, $response); + $this->dispatcher->dispatch($event, KernelEvents::RESPONSE); $this->assertEquals('ISO-8859-15', $response->getCharset()); } @@ -72,8 +72,8 @@ public function testFilterDoesNothingIfCharsetIsOverridden() $response = new Response('foo'); $response->setCharset('ISO-8859-1'); - $event = new FilterResponseEvent($this->kernel, Request::create('/'), HttpKernelInterface::MASTER_REQUEST, $response); - $this->dispatcher->dispatch(KernelEvents::RESPONSE, $event); + $event = new ResponseEvent($this->kernel, Request::create('/'), HttpKernelInterface::MASTER_REQUEST, $response); + $this->dispatcher->dispatch($event, KernelEvents::RESPONSE); $this->assertEquals('ISO-8859-1', $response->getCharset()); } @@ -87,8 +87,8 @@ public function testFiltersSetsNonDefaultCharsetIfNotOverriddenOnNonTextContentT $request = Request::create('/'); $request->setRequestFormat('application/json'); - $event = new FilterResponseEvent($this->kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response); - $this->dispatcher->dispatch(KernelEvents::RESPONSE, $event); + $event = new ResponseEvent($this->kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response); + $this->dispatcher->dispatch($event, KernelEvents::RESPONSE); $this->assertEquals('ISO-8859-15', $response->getCharset()); } diff --git a/src/Symfony/Component/HttpKernel/Tests/EventListener/RouterListenerTest.php b/src/Symfony/Component/HttpKernel/Tests/EventListener/RouterListenerTest.php index c27b34130076..7621ed8e6533 100644 --- a/src/Symfony/Component/HttpKernel/Tests/EventListener/RouterListenerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/EventListener/RouterListenerTest.php @@ -18,7 +18,7 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Controller\ArgumentResolver; use Symfony\Component\HttpKernel\Controller\ControllerResolver; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\EventListener\ExceptionListener; use Symfony\Component\HttpKernel\EventListener\RouterListener; use Symfony\Component\HttpKernel\EventListener\ValidateRequestListener; @@ -52,7 +52,7 @@ public function testPort($defaultHttpPort, $defaultHttpsPort, $uri, $expectedHtt ->will($this->returnValue($context)); $listener = new RouterListener($urlMatcher, $this->requestStack); - $event = $this->createGetResponseEventForUri($uri); + $event = $this->createRequestEventForUri($uri); $listener->onKernelRequest($event); $this->assertEquals($expectedHttpPort, $context->getHttpPort()); @@ -70,13 +70,13 @@ public function getPortData() ]; } - private function createGetResponseEventForUri(string $uri): GetResponseEvent + private function createRequestEventForUri(string $uri): RequestEvent { - $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(); + $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); $request = Request::create($uri); $request->attributes->set('_controller', null); // Prevents going in to routing process - return new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); + return new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); } /** @@ -89,9 +89,9 @@ public function testInvalidMatcher() public function testRequestMatcher() { - $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(); + $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); $request = Request::create('http://localhost/'); - $event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); + $event = new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); $requestMatcher = $this->getMockBuilder('Symfony\Component\Routing\Matcher\RequestMatcherInterface')->getMock(); $requestMatcher->expects($this->once()) @@ -105,9 +105,9 @@ public function testRequestMatcher() public function testSubRequestWithDifferentMethod() { - $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(); + $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); $request = Request::create('http://localhost/', 'post'); - $event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); + $event = new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); $requestMatcher = $this->getMockBuilder('Symfony\Component\Routing\Matcher\RequestMatcherInterface')->getMock(); $requestMatcher->expects($this->any()) @@ -121,9 +121,9 @@ public function testSubRequestWithDifferentMethod() $listener->onKernelRequest($event); // sub-request with another HTTP method - $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(); + $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); $request = Request::create('http://localhost/', 'get'); - $event = new GetResponseEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST); + $event = new RequestEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST); $listener->onKernelRequest($event); @@ -145,11 +145,11 @@ public function testLoggingParameter($parameter, $log, $parameters) ->method('info') ->with($this->equalTo($log), $this->equalTo($parameters)); - $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(); + $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); $request = Request::create('http://localhost/'); $listener = new RouterListener($requestMatcher, $this->requestStack, new RequestContext(), $logger); - $listener->onKernelRequest(new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST)); + $listener->onKernelRequest(new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST)); } public function getLoggingParameterData() @@ -209,9 +209,9 @@ public function testNoRoutingConfigurationResponse() */ public function testRequestWithBadHost() { - $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(); + $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); $request = Request::create('http://bad host %22/'); - $event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); + $event = new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); $requestMatcher = $this->getMockBuilder('Symfony\Component\Routing\Matcher\RequestMatcherInterface')->getMock(); diff --git a/src/Symfony/Component/HttpKernel/Tests/EventListener/SaveSessionListenerTest.php b/src/Symfony/Component/HttpKernel/Tests/EventListener/SaveSessionListenerTest.php index a903fd589169..6cdd7476c9b7 100644 --- a/src/Symfony/Component/HttpKernel/Tests/EventListener/SaveSessionListenerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/EventListener/SaveSessionListenerTest.php @@ -15,7 +15,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Session\SessionInterface; -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; +use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\HttpKernel\EventListener\SaveSessionListener; use Symfony\Component\HttpKernel\HttpKernelInterface; @@ -27,7 +27,7 @@ class SaveSessionListenerTest extends TestCase public function testOnlyTriggeredOnMasterRequest() { $listener = new SaveSessionListener(); - $event = $this->getMockBuilder(FilterResponseEvent::class)->disableOriginalConstructor()->getMock(); + $event = $this->getMockBuilder(ResponseEvent::class)->disableOriginalConstructor()->getMock(); $event->expects($this->once())->method('isMasterRequest')->willReturn(false); $event->expects($this->never())->method('getRequest'); @@ -47,6 +47,6 @@ public function testSessionSaved() $request = new Request(); $request->setSession($session); $response = new Response(); - $listener->onKernelResponse(new FilterResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response)); + $listener->onKernelResponse(new ResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response)); } } diff --git a/src/Symfony/Component/HttpKernel/Tests/EventListener/SessionListenerTest.php b/src/Symfony/Component/HttpKernel/Tests/EventListener/SessionListenerTest.php index 47ac75e8bcc1..48b800cd7738 100644 --- a/src/Symfony/Component/HttpKernel/Tests/EventListener/SessionListenerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/EventListener/SessionListenerTest.php @@ -17,9 +17,9 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Session\Session; -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; use Symfony\Component\HttpKernel\Event\FinishRequestEvent; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; +use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\HttpKernel\EventListener\AbstractSessionListener; use Symfony\Component\HttpKernel\EventListener\SessionListener; use Symfony\Component\HttpKernel\HttpKernelInterface; @@ -29,7 +29,7 @@ class SessionListenerTest extends TestCase public function testOnlyTriggeredOnMasterRequest() { $listener = $this->getMockForAbstractClass(AbstractSessionListener::class); - $event = $this->getMockBuilder(GetResponseEvent::class)->disableOriginalConstructor()->getMock(); + $event = $this->getMockBuilder(RequestEvent::class)->disableOriginalConstructor()->getMock(); $event->expects($this->once())->method('isMasterRequest')->willReturn(false); $event->expects($this->never())->method('getRequest'); @@ -47,7 +47,7 @@ public function testSessionIsSet() $request = new Request(); $listener = new SessionListener($container); - $event = $this->getMockBuilder(GetResponseEvent::class)->disableOriginalConstructor()->getMock(); + $event = $this->getMockBuilder(RequestEvent::class)->disableOriginalConstructor()->getMock(); $event->expects($this->once())->method('isMasterRequest')->willReturn(true); $event->expects($this->once())->method('getRequest')->willReturn($request); @@ -69,10 +69,10 @@ public function testResponseIsPrivateIfSessionStarted() $kernel = $this->getMockBuilder(HttpKernelInterface::class)->disableOriginalConstructor()->getMock(); $request = new Request(); - $listener->onKernelRequest(new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST)); + $listener->onKernelRequest(new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST)); $response = new Response(); - $listener->onKernelResponse(new FilterResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response)); + $listener->onKernelResponse(new ResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response)); $this->assertTrue($response->headers->hasCacheControlDirective('private')); $this->assertTrue($response->headers->hasCacheControlDirective('must-revalidate')); @@ -92,12 +92,12 @@ public function testResponseIsStillPublicIfSessionStartedAndHeaderPresent() $kernel = $this->getMockBuilder(HttpKernelInterface::class)->disableOriginalConstructor()->getMock(); $request = new Request(); - $listener->onKernelRequest(new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST)); + $listener->onKernelRequest(new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST)); $response = new Response(); $response->setSharedMaxAge(60); $response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER, 'true'); - $listener->onKernelResponse(new FilterResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response)); + $listener->onKernelResponse(new ResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response)); $this->assertTrue($response->headers->hasCacheControlDirective('public')); $this->assertFalse($response->headers->hasCacheControlDirective('private')); @@ -118,7 +118,7 @@ public function testUninitializedSession() ]); $listener = new SessionListener($container); - $listener->onKernelResponse(new FilterResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response)); + $listener->onKernelResponse(new ResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response)); $this->assertTrue($response->headers->hasCacheControlDirective('public')); $this->assertFalse($response->headers->hasCacheControlDirective('private')); $this->assertFalse($response->headers->hasCacheControlDirective('must-revalidate')); @@ -141,20 +141,20 @@ public function testSurrogateMasterRequestIsPublic() $request = new Request(); $response = new Response(); $response->setCache(['public' => true, 'max_age' => '30']); - $listener->onKernelRequest(new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST)); + $listener->onKernelRequest(new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST)); $this->assertTrue($request->hasSession()); $subRequest = clone $request; $this->assertSame($request->getSession(), $subRequest->getSession()); - $listener->onKernelRequest(new GetResponseEvent($kernel, $subRequest, HttpKernelInterface::MASTER_REQUEST)); - $listener->onKernelResponse(new FilterResponseEvent($kernel, $subRequest, HttpKernelInterface::MASTER_REQUEST, $response)); + $listener->onKernelRequest(new RequestEvent($kernel, $subRequest, HttpKernelInterface::MASTER_REQUEST)); + $listener->onKernelResponse(new ResponseEvent($kernel, $subRequest, HttpKernelInterface::MASTER_REQUEST, $response)); $listener->onFinishRequest(new FinishRequestEvent($kernel, $subRequest, HttpKernelInterface::MASTER_REQUEST)); $this->assertFalse($response->headers->hasCacheControlDirective('private')); $this->assertFalse($response->headers->hasCacheControlDirective('must-revalidate')); $this->assertSame('30', $response->headers->getCacheControlDirective('max-age')); - $listener->onKernelResponse(new FilterResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response)); + $listener->onKernelResponse(new ResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response)); $this->assertTrue($response->headers->hasCacheControlDirective('private')); $this->assertTrue($response->headers->hasCacheControlDirective('must-revalidate')); diff --git a/src/Symfony/Component/HttpKernel/Tests/EventListener/SurrogateListenerTest.php b/src/Symfony/Component/HttpKernel/Tests/EventListener/SurrogateListenerTest.php index 66e119f1239d..fc51de252e81 100644 --- a/src/Symfony/Component/HttpKernel/Tests/EventListener/SurrogateListenerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/EventListener/SurrogateListenerTest.php @@ -15,7 +15,7 @@ use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; +use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\HttpKernel\EventListener\SurrogateListener; use Symfony\Component\HttpKernel\HttpCache\Esi; use Symfony\Component\HttpKernel\HttpKernelInterface; @@ -31,8 +31,8 @@ public function testFilterDoesNothingForSubRequests() $listener = new SurrogateListener(new Esi()); $dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'onKernelResponse']); - $event = new FilterResponseEvent($kernel, new Request(), HttpKernelInterface::SUB_REQUEST, $response); - $dispatcher->dispatch(KernelEvents::RESPONSE, $event); + $event = new ResponseEvent($kernel, new Request(), HttpKernelInterface::SUB_REQUEST, $response); + $dispatcher->dispatch($event, KernelEvents::RESPONSE); $this->assertEquals('', $event->getResponse()->headers->get('Surrogate-Control')); } @@ -45,8 +45,8 @@ public function testFilterWhenThereIsSomeEsiIncludes() $listener = new SurrogateListener(new Esi()); $dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'onKernelResponse']); - $event = new FilterResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response); - $dispatcher->dispatch(KernelEvents::RESPONSE, $event); + $event = new ResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response); + $dispatcher->dispatch($event, KernelEvents::RESPONSE); $this->assertEquals('content="ESI/1.0"', $event->getResponse()->headers->get('Surrogate-Control')); } @@ -59,8 +59,8 @@ public function testFilterWhenThereIsNoEsiIncludes() $listener = new SurrogateListener(new Esi()); $dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'onKernelResponse']); - $event = new FilterResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response); - $dispatcher->dispatch(KernelEvents::RESPONSE, $event); + $event = new ResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response); + $dispatcher->dispatch($event, KernelEvents::RESPONSE); $this->assertEquals('', $event->getResponse()->headers->get('Surrogate-Control')); } diff --git a/src/Symfony/Component/HttpKernel/Tests/EventListener/TestSessionListenerTest.php b/src/Symfony/Component/HttpKernel/Tests/EventListener/TestSessionListenerTest.php index 9f6a5ef759ac..0eaa63f06a83 100644 --- a/src/Symfony/Component/HttpKernel/Tests/EventListener/TestSessionListenerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/EventListener/TestSessionListenerTest.php @@ -15,8 +15,8 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Session\SessionInterface; -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; +use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\HttpKernel\EventListener\SessionListener; use Symfony\Component\HttpKernel\EventListener\TestSessionListener; use Symfony\Component\HttpKernel\HttpKernelInterface; @@ -95,9 +95,9 @@ public function testEmptySessionWithNewSessionIdDoesSendCookie() $this->sessionIsEmpty(); $this->fixSessionId('456'); - $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(); + $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); $request = Request::create('/', 'GET', [], ['MOCKSESSID' => '123']); - $event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); + $event = new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); $this->listener->onKernelRequest($event); $response = $this->filterResponse(new Request(), HttpKernelInterface::MASTER_REQUEST); @@ -114,9 +114,9 @@ public function testSessionWithNewSessionIdAndNewCookieDoesNotSendAnotherCookie( $this->sessionIsEmpty(); $this->fixSessionId('456'); - $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(); + $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); $request = Request::create('/', 'GET', [], ['MOCKSESSID' => '123']); - $event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); + $event = new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); $this->listener->onKernelRequest($event); $response = new Response('', 200, ['Set-Cookie' => $existing]); @@ -145,8 +145,8 @@ public function testUnstartedSessionIsNotSave() public function testDoesNotThrowIfRequestDoesNotHaveASession() { - $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(); - $event = new FilterResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, new Response()); + $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $event = new ResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, new Response()); $this->listener->onKernelResponse($event); @@ -157,8 +157,8 @@ private function filterResponse(Request $request, $type = HttpKernelInterface::M { $request->setSession($this->session); $response = $response ?: new Response(); - $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(); - $event = new FilterResponseEvent($kernel, $request, $type, $response); + $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $event = new ResponseEvent($kernel, $request, $type, $response); $this->listener->onKernelResponse($event); diff --git a/src/Symfony/Component/HttpKernel/Tests/EventListener/TranslatorListenerTest.php b/src/Symfony/Component/HttpKernel/Tests/EventListener/TranslatorListenerTest.php index c75e7b980f46..3fecf9aab3ba 100644 --- a/src/Symfony/Component/HttpKernel/Tests/EventListener/TranslatorListenerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/EventListener/TranslatorListenerTest.php @@ -14,7 +14,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Event\FinishRequestEvent; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\EventListener\TranslatorListener; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Contracts\Translation\LocaleAwareInterface; @@ -39,7 +39,7 @@ public function testLocaleIsSetInOnKernelRequest() ->method('setLocale') ->with($this->equalTo('fr')); - $event = new GetResponseEvent($this->createHttpKernel(), $this->createRequest('fr'), HttpKernelInterface::MASTER_REQUEST); + $event = new RequestEvent($this->createHttpKernel(), $this->createRequest('fr'), HttpKernelInterface::MASTER_REQUEST); $this->listener->onKernelRequest($event); } @@ -54,7 +54,7 @@ public function testDefaultLocaleIsUsedOnExceptionsInOnKernelRequest() ->method('setLocale') ->with($this->equalTo('en')); - $event = new GetResponseEvent($this->createHttpKernel(), $this->createRequest('fr'), HttpKernelInterface::MASTER_REQUEST); + $event = new RequestEvent($this->createHttpKernel(), $this->createRequest('fr'), HttpKernelInterface::MASTER_REQUEST); $this->listener->onKernelRequest($event); } diff --git a/src/Symfony/Component/HttpKernel/Tests/EventListener/ValidateRequestListenerTest.php b/src/Symfony/Component/HttpKernel/Tests/EventListener/ValidateRequestListenerTest.php index fb7a4379bfa4..bbd596bc78dd 100644 --- a/src/Symfony/Component/HttpKernel/Tests/EventListener/ValidateRequestListenerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/EventListener/ValidateRequestListenerTest.php @@ -14,7 +14,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\EventListener\ValidateRequestListener; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\KernelEvents; @@ -41,8 +41,8 @@ public function testListenerThrowsWhenMasterRequestHasInconsistentClientIps() $request->headers->set('X_FORWARDED_FOR', '3.3.3.3'); $dispatcher->addListener(KernelEvents::REQUEST, [new ValidateRequestListener(), 'onKernelRequest']); - $event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); + $event = new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); - $dispatcher->dispatch(KernelEvents::REQUEST, $event); + $dispatcher->dispatch($event, KernelEvents::REQUEST); } } diff --git a/src/Symfony/Component/HttpKernel/Tests/Fragment/InlineFragmentRendererTest.php b/src/Symfony/Component/HttpKernel/Tests/Fragment/InlineFragmentRendererTest.php index 155493d7f448..c8b79e8ff3c9 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Fragment/InlineFragmentRendererTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Fragment/InlineFragmentRendererTest.php @@ -17,6 +17,7 @@ use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Controller\ControllerReference; +use Symfony\Component\HttpKernel\Event\ExceptionEvent; use Symfony\Component\HttpKernel\Fragment\InlineFragmentRenderer; use Symfony\Component\HttpKernel\HttpKernel; use Symfony\Component\HttpKernel\KernelEvents; @@ -82,12 +83,16 @@ public function testRenderExceptionNoIgnoreErrors() public function testRenderExceptionIgnoreErrors() { + $exception = new \RuntimeException('foo'); + $kernel = $this->getKernel($this->throwException($exception)); + $request = Request::create('/'); + $expectedEvent = new ExceptionEvent($kernel, $request, $kernel::SUB_REQUEST, $exception); $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock(); - $dispatcher->expects($this->once())->method('dispatch')->with(KernelEvents::EXCEPTION); + $dispatcher->expects($this->once())->method('dispatch')->with($expectedEvent, KernelEvents::EXCEPTION); - $strategy = new InlineFragmentRenderer($this->getKernel($this->throwException(new \RuntimeException('foo'))), $dispatcher); + $strategy = new InlineFragmentRenderer($kernel, $dispatcher); - $this->assertEmpty($strategy->render('/', Request::create('/'), ['ignore_errors' => true])->getContent()); + $this->assertEmpty($strategy->render('/', $request, ['ignore_errors' => true])->getContent()); } public function testRenderExceptionIgnoreErrorsWithAlt() diff --git a/src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php b/src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php index 40a63f4d0719..d1162f0431f7 100644 --- a/src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php @@ -20,8 +20,6 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface; use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface; -use Symfony\Component\HttpKernel\Event\FilterControllerArgumentsEvent; -use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\Exception\ControllerDoesNotReturnResponseException; use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException; @@ -128,7 +126,7 @@ public function getStatusCodes() public function testHandleWhenAnExceptionIsHandledWithASpecificStatusCode($expectedStatusCode) { $dispatcher = new EventDispatcher(); - $dispatcher->addListener(KernelEvents::EXCEPTION, function (GetResponseForExceptionEvent $event) use ($expectedStatusCode) { + $dispatcher->addListener(KernelEvents::EXCEPTION, function ($event) use ($expectedStatusCode) { $event->allowCustomResponseCode(); $event->setResponse(new Response('', $expectedStatusCode)); }); @@ -256,7 +254,7 @@ public function testHandleWithAResponseListener() public function testHandleAllowChangingControllerArguments() { $dispatcher = new EventDispatcher(); - $dispatcher->addListener(KernelEvents::CONTROLLER_ARGUMENTS, function (FilterControllerArgumentsEvent $event) { + $dispatcher->addListener(KernelEvents::CONTROLLER_ARGUMENTS, function ($event) { $event->setArguments(['foo']); }); @@ -268,7 +266,7 @@ public function testHandleAllowChangingControllerArguments() public function testHandleAllowChangingControllerAndArguments() { $dispatcher = new EventDispatcher(); - $dispatcher->addListener(KernelEvents::CONTROLLER_ARGUMENTS, function (FilterControllerArgumentsEvent $event) { + $dispatcher->addListener(KernelEvents::CONTROLLER_ARGUMENTS, function ($event) { $oldController = $event->getController(); $oldArguments = $event->getArguments(); diff --git a/src/Symfony/Component/HttpKernel/composer.json b/src/Symfony/Component/HttpKernel/composer.json index 7cae1e74845f..dd38c04ee061 100644 --- a/src/Symfony/Component/HttpKernel/composer.json +++ b/src/Symfony/Component/HttpKernel/composer.json @@ -18,7 +18,7 @@ "require": { "php": "^7.1.3", "symfony/contracts": "^1.0.2", - "symfony/event-dispatcher": "~4.1", + "symfony/event-dispatcher": "^4.3", "symfony/http-foundation": "^4.1.1", "symfony/debug": "~3.4|~4.0", "symfony/polyfill-ctype": "~1.8", diff --git a/src/Symfony/Component/Security/CHANGELOG.md b/src/Symfony/Component/Security/CHANGELOG.md index a04fd47e46ad..e29070f0cc4c 100644 --- a/src/Symfony/Component/Security/CHANGELOG.md +++ b/src/Symfony/Component/Security/CHANGELOG.md @@ -14,6 +14,12 @@ CHANGELOG * Made the `serialize()` and `unserialize()` methods of `AbstractToken` and `AuthenticationException` final, use `getState()`/`setState()` instead * `AuthenticationException` doesn't implement `Serializable` anymore + * Deprecated the `ListenerInterface`, turn your listeners into callables instead + * Deprecated `Firewall::handleRequest()`, use `Firewall::callListeners()` instead + * Dispatch `AuthenticationSuccessEvent` on `security.authentication.success` + * Dispatch `AuthenticationFailureEvent` on `security.authentication.failure` + * Dispatch `InteractiveLoginEvent` on `security.interactive_login` + * Dispatch `SwitchUserEvent` on `security.switch_user` 4.2.0 ----- diff --git a/src/Symfony/Component/Security/Core/Authentication/AuthenticationProviderManager.php b/src/Symfony/Component/Security/Core/Authentication/AuthenticationProviderManager.php index 96dc6ad220ca..5a3a4cec53c5 100644 --- a/src/Symfony/Component/Security/Core/Authentication/AuthenticationProviderManager.php +++ b/src/Symfony/Component/Security/Core/Authentication/AuthenticationProviderManager.php @@ -12,10 +12,11 @@ namespace Symfony\Component\Security\Core\Authentication; use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy; use Symfony\Component\Security\Core\Authentication\Provider\AuthenticationProviderInterface; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\AuthenticationEvents; -use Symfony\Component\Security\Core\Event\AuthenticationEvent; +use Symfony\Component\Security\Core\Event\AuthenticationSuccessEvent; use Symfony\Component\Security\Core\Event\AuthenticationFailureEvent; use Symfony\Component\Security\Core\Exception\AccountStatusException; use Symfony\Component\Security\Core\Exception\AuthenticationException; @@ -52,7 +53,7 @@ public function __construct(iterable $providers, bool $eraseCredentials = true) public function setEventDispatcher(EventDispatcherInterface $dispatcher) { - $this->eventDispatcher = $dispatcher; + $this->eventDispatcher = LegacyEventDispatcherProxy::decorate($dispatcher); } /** @@ -93,7 +94,7 @@ public function authenticate(TokenInterface $token) } if (null !== $this->eventDispatcher) { - $this->eventDispatcher->dispatch(AuthenticationEvents::AUTHENTICATION_SUCCESS, new AuthenticationEvent($result)); + $this->eventDispatcher->dispatch(new AuthenticationSuccessEvent($result), AuthenticationEvents::AUTHENTICATION_SUCCESS); } return $result; @@ -104,7 +105,7 @@ public function authenticate(TokenInterface $token) } if (null !== $this->eventDispatcher) { - $this->eventDispatcher->dispatch(AuthenticationEvents::AUTHENTICATION_FAILURE, new AuthenticationFailureEvent($token, $lastException)); + $this->eventDispatcher->dispatch(new AuthenticationFailureEvent($token, $lastException), AuthenticationEvents::AUTHENTICATION_FAILURE); } $lastException->setToken($token); diff --git a/src/Symfony/Component/Security/Core/AuthenticationEvents.php b/src/Symfony/Component/Security/Core/AuthenticationEvents.php index 6aad681ba308..06358275f731 100644 --- a/src/Symfony/Component/Security/Core/AuthenticationEvents.php +++ b/src/Symfony/Component/Security/Core/AuthenticationEvents.php @@ -17,7 +17,7 @@ final class AuthenticationEvents * The AUTHENTICATION_SUCCESS event occurs after a user is authenticated * by one provider. * - * @Event("Symfony\Component\Security\Core\Event\AuthenticationEvent") + * @Event("Symfony\Component\Security\Core\Event\AuthenticationSuccessEvent") */ const AUTHENTICATION_SUCCESS = 'security.authentication.success'; diff --git a/src/Symfony/Component/Security/Core/Event/AuthenticationSuccessEvent.php b/src/Symfony/Component/Security/Core/Event/AuthenticationSuccessEvent.php new file mode 100644 index 000000000000..7126ba19d6f2 --- /dev/null +++ b/src/Symfony/Component/Security/Core/Event/AuthenticationSuccessEvent.php @@ -0,0 +1,16 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Security\Core\Event; + +class AuthenticationSuccessEvent extends AuthenticationEvent +{ +} diff --git a/src/Symfony/Component/Security/Core/Tests/Authentication/AuthenticationProviderManagerTest.php b/src/Symfony/Component/Security/Core/Tests/Authentication/AuthenticationProviderManagerTest.php index fd2de0ca25d4..c2a66a49f68b 100644 --- a/src/Symfony/Component/Security/Core/Tests/Authentication/AuthenticationProviderManagerTest.php +++ b/src/Symfony/Component/Security/Core/Tests/Authentication/AuthenticationProviderManagerTest.php @@ -16,7 +16,7 @@ use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; use Symfony\Component\Security\Core\AuthenticationEvents; -use Symfony\Component\Security\Core\Event\AuthenticationEvent; +use Symfony\Component\Security\Core\Event\AuthenticationSuccessEvent; use Symfony\Component\Security\Core\Event\AuthenticationFailureEvent; use Symfony\Component\Security\Core\Exception\AccountStatusException; use Symfony\Component\Security\Core\Exception\AuthenticationException; @@ -139,7 +139,7 @@ public function testAuthenticateDispatchesAuthenticationFailureEvent() $dispatcher ->expects($this->once()) ->method('dispatch') - ->with(AuthenticationEvents::AUTHENTICATION_FAILURE, $this->equalTo(new AuthenticationFailureEvent($token, $exception))); + ->with($this->equalTo(new AuthenticationFailureEvent($token, $exception)), AuthenticationEvents::AUTHENTICATION_FAILURE); $manager = new AuthenticationProviderManager([$provider]); $manager->setEventDispatcher($dispatcher); @@ -164,7 +164,7 @@ public function testAuthenticateDispatchesAuthenticationSuccessEvent() $dispatcher ->expects($this->once()) ->method('dispatch') - ->with(AuthenticationEvents::AUTHENTICATION_SUCCESS, $this->equalTo(new AuthenticationEvent($token))); + ->with($this->equalTo(new AuthenticationSuccessEvent($token)), AuthenticationEvents::AUTHENTICATION_SUCCESS); $manager = new AuthenticationProviderManager([$provider]); $manager->setEventDispatcher($dispatcher); diff --git a/src/Symfony/Component/Security/Core/composer.json b/src/Symfony/Component/Security/Core/composer.json index 3f297cec44f7..42691b86c38a 100644 --- a/src/Symfony/Component/Security/Core/composer.json +++ b/src/Symfony/Component/Security/Core/composer.json @@ -21,7 +21,7 @@ }, "require-dev": { "psr/container": "^1.0", - "symfony/event-dispatcher": "~3.4|~4.0", + "symfony/event-dispatcher": "^4.3", "symfony/expression-language": "~3.4|~4.0", "symfony/http-foundation": "~3.4|~4.0", "symfony/ldap": "~3.4|~4.0", @@ -29,6 +29,7 @@ "psr/log": "~1.0" }, "conflict": { + "symfony/event-dispatcher": "<4.3", "symfony/security-guard": "<4.3" }, "suggest": { diff --git a/src/Symfony/Component/Security/Guard/Firewall/GuardAuthenticationListener.php b/src/Symfony/Component/Security/Guard/Firewall/GuardAuthenticationListener.php index 663a82e8c5fe..2821d2a91d83 100644 --- a/src/Symfony/Component/Security/Guard/Firewall/GuardAuthenticationListener.php +++ b/src/Symfony/Component/Security/Guard/Firewall/GuardAuthenticationListener.php @@ -14,7 +14,7 @@ use Psr\Log\LoggerInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\Exception\AuthenticationException; @@ -22,6 +22,7 @@ use Symfony\Component\Security\Guard\GuardAuthenticatorHandler; use Symfony\Component\Security\Guard\Token\PreAuthenticationGuardToken; use Symfony\Component\Security\Http\Firewall\ListenerInterface; +use Symfony\Component\Security\Http\Firewall\LegacyListenerTrait; use Symfony\Component\Security\Http\RememberMe\RememberMeServicesInterface; /** @@ -29,9 +30,13 @@ * * @author Ryan Weaver * @author Amaury Leroux de Lens + * + * @final since Symfony 4.3 */ class GuardAuthenticationListener implements ListenerInterface { + use LegacyListenerTrait; + private $guardHandler; private $authenticationManager; private $providerKey; @@ -62,7 +67,7 @@ public function __construct(GuardAuthenticatorHandler $guardHandler, Authenticat /** * Iterates over each authenticator to see if each wants to authenticate the request. */ - public function handle(GetResponseEvent $event) + public function __invoke(RequestEvent $event) { if (null !== $this->logger) { $context = ['firewall_key' => $this->providerKey]; @@ -91,7 +96,7 @@ public function handle(GetResponseEvent $event) } } - private function executeGuardAuthenticator($uniqueGuardKey, AuthenticatorInterface $guardAuthenticator, GetResponseEvent $event) + private function executeGuardAuthenticator($uniqueGuardKey, AuthenticatorInterface $guardAuthenticator, RequestEvent $event) { $request = $event->getRequest(); try { diff --git a/src/Symfony/Component/Security/Guard/GuardAuthenticatorHandler.php b/src/Symfony/Component/Security/Guard/GuardAuthenticatorHandler.php index 1f7e157f446e..780dd93b4404 100644 --- a/src/Symfony/Component/Security/Guard/GuardAuthenticatorHandler.php +++ b/src/Symfony/Component/Security/Guard/GuardAuthenticatorHandler.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Security\Guard; use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; @@ -45,7 +46,7 @@ class GuardAuthenticatorHandler public function __construct(TokenStorageInterface $tokenStorage, EventDispatcherInterface $eventDispatcher = null, array $statelessProviderKeys = []) { $this->tokenStorage = $tokenStorage; - $this->dispatcher = $eventDispatcher; + $this->dispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher); $this->statelessProviderKeys = $statelessProviderKeys; } @@ -61,7 +62,7 @@ public function authenticateWithToken(TokenInterface $token, Request $request, s if (null !== $this->dispatcher) { $loginEvent = new InteractiveLoginEvent($request, $token); - $this->dispatcher->dispatch(SecurityEvents::INTERACTIVE_LOGIN, $loginEvent); + $this->dispatcher->dispatch($loginEvent, SecurityEvents::INTERACTIVE_LOGIN); } } diff --git a/src/Symfony/Component/Security/Guard/Tests/Firewall/GuardAuthenticationListenerTest.php b/src/Symfony/Component/Security/Guard/Tests/Firewall/GuardAuthenticationListenerTest.php index 5a95eb6ae750..b13aab7f8b0e 100644 --- a/src/Symfony/Component/Security/Guard/Tests/Firewall/GuardAuthenticationListenerTest.php +++ b/src/Symfony/Component/Security/Guard/Tests/Firewall/GuardAuthenticationListenerTest.php @@ -85,7 +85,7 @@ public function testHandleSuccess() ->expects($this->never()) ->method('loginSuccess'); - $listener->handle($this->event); + $listener($this->event); } public function testHandleSuccessStopsAfterResponseIsSet() @@ -119,7 +119,7 @@ public function testHandleSuccessStopsAfterResponseIsSet() $this->logger ); - $listener->handle($this->event); + $listener($this->event); } public function testHandleSuccessWithRememberMe() @@ -167,7 +167,7 @@ public function testHandleSuccessWithRememberMe() ->expects($this->once()) ->method('loginSuccess'); - $listener->handle($this->event); + $listener($this->event); } public function testHandleCatchesAuthenticationException() @@ -203,7 +203,7 @@ public function testHandleCatchesAuthenticationException() $this->logger ); - $listener->handle($this->event); + $listener($this->event); } public function testSupportsReturnFalseSkipAuth() @@ -229,7 +229,7 @@ public function testSupportsReturnFalseSkipAuth() $this->logger ); - $listener->handle($this->event); + $listener($this->event); } /** @@ -259,7 +259,7 @@ public function testReturnNullFromGetCredentials() $this->logger ); - $listener->handle($this->event); + $listener($this->event); } protected function setUp() @@ -274,7 +274,7 @@ protected function setUp() $this->request = new Request([], [], [], [], [], []); - $this->event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent') + $this->event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\RequestEvent') ->disableOriginalConstructor() ->setMethods(['getRequest']) ->getMock(); diff --git a/src/Symfony/Component/Security/Guard/Tests/GuardAuthenticatorHandlerTest.php b/src/Symfony/Component/Security/Guard/Tests/GuardAuthenticatorHandlerTest.php index 9950426de9e2..9b513c42f941 100644 --- a/src/Symfony/Component/Security/Guard/Tests/GuardAuthenticatorHandlerTest.php +++ b/src/Symfony/Component/Security/Guard/Tests/GuardAuthenticatorHandlerTest.php @@ -40,7 +40,7 @@ public function testAuthenticateWithToken() $this->dispatcher ->expects($this->once()) ->method('dispatch') - ->with($this->equalTo(SecurityEvents::INTERACTIVE_LOGIN), $this->equalTo($loginEvent)) + ->with($this->equalTo($loginEvent), $this->equalTo(SecurityEvents::INTERACTIVE_LOGIN)) ; $handler = new GuardAuthenticatorHandler($this->tokenStorage, $this->dispatcher); diff --git a/src/Symfony/Component/Security/Guard/composer.json b/src/Symfony/Component/Security/Guard/composer.json index 215bcf58a15d..f424f4a29566 100644 --- a/src/Symfony/Component/Security/Guard/composer.json +++ b/src/Symfony/Component/Security/Guard/composer.json @@ -18,7 +18,7 @@ "require": { "php": "^7.1.3", "symfony/security-core": "~3.4.22|^4.2.3", - "symfony/security-http": "~3.4|~4.0" + "symfony/security-http": "^4.3" }, "require-dev": { "psr/log": "~1.0" diff --git a/src/Symfony/Component/Security/Http/Firewall.php b/src/Symfony/Component/Security/Http/Firewall.php index 79ba93108ebf..a1bdaa02be97 100644 --- a/src/Symfony/Component/Security/Http/Firewall.php +++ b/src/Symfony/Component/Security/Http/Firewall.php @@ -14,6 +14,7 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpKernel\Event\FinishRequestEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\Security\Http\Firewall\AccessListener; @@ -42,6 +43,9 @@ public function __construct(FirewallMapInterface $map, EventDispatcherInterface $this->exceptionListeners = new \SplObjectStorage(); } + /** + * @internal since Symfony 4.3 + */ public function onKernelRequest(GetResponseEvent $event) { if (!$event->isMasterRequest()) { @@ -87,9 +91,16 @@ public function onKernelRequest(GetResponseEvent $event) } }; - $this->handleRequest($event, $authenticationListeners()); + if ($event instanceof RequestEvent) { + $this->callListeners($event, $authenticationListeners()); + } else { + $this->handleRequest($event, $authenticationListeners()); + } } + /** + * @internal since Symfony 4.3 + */ public function onKernelFinishRequest(FinishRequestEvent $event) { $request = $event->getRequest(); @@ -111,10 +122,23 @@ public static function getSubscribedEvents() ]; } + protected function callListeners(RequestEvent $event, iterable $listeners) + { + $this->handleRequest($event, $listeners); + } + + /** + * @deprecated since Symfony 4.3, use callListeners instead + */ protected function handleRequest(GetResponseEvent $event, $listeners) { foreach ($listeners as $listener) { - $listener->handle($event); + if (\is_callable($listener)) { + $listener($event); + } else { + @trigger_error(sprintf('Calling the "%s::handle()" method from the firewall is deprecated since Symfony 4.3, implement "__invoke()" instead.', \get_class($this)), E_USER_DEPRECATED); + $listener->handle($event); + } if ($event->hasResponse()) { break; diff --git a/src/Symfony/Component/Security/Http/Firewall/AbstractAuthenticationListener.php b/src/Symfony/Component/Security/Http/Firewall/AbstractAuthenticationListener.php index a46e59063de7..06a3b2d2a7eb 100644 --- a/src/Symfony/Component/Security/Http/Firewall/AbstractAuthenticationListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/AbstractAuthenticationListener.php @@ -13,9 +13,10 @@ use Psr\Log\LoggerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; @@ -47,9 +48,13 @@ * * @author Fabien Potencier * @author Johannes M. Schmitt + * + * @internal since Symfony 4.3 */ abstract class AbstractAuthenticationListener implements ListenerInterface { + use LegacyListenerTrait; + protected $options; protected $logger; protected $authenticationManager; @@ -90,7 +95,7 @@ public function __construct(TokenStorageInterface $tokenStorage, AuthenticationM 'require_previous_session' => true, ], $options); $this->logger = $logger; - $this->dispatcher = $dispatcher; + $this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher); $this->httpUtils = $httpUtils; } @@ -108,7 +113,7 @@ public function setRememberMeServices(RememberMeServicesInterface $rememberMeSer * @throws \RuntimeException * @throws SessionUnavailableException */ - final public function handle(GetResponseEvent $event) + public function __invoke(RequestEvent $event) { $request = $event->getRequest(); @@ -202,7 +207,7 @@ private function onSuccess(Request $request, TokenInterface $token) if (null !== $this->dispatcher) { $loginEvent = new InteractiveLoginEvent($request, $token); - $this->dispatcher->dispatch(SecurityEvents::INTERACTIVE_LOGIN, $loginEvent); + $this->dispatcher->dispatch($loginEvent, SecurityEvents::INTERACTIVE_LOGIN); } $response = $this->successHandler->onAuthenticationSuccess($request, $token); diff --git a/src/Symfony/Component/Security/Http/Firewall/AbstractPreAuthenticatedListener.php b/src/Symfony/Component/Security/Http/Firewall/AbstractPreAuthenticatedListener.php index d6ceef8e3005..60817ecd1c63 100644 --- a/src/Symfony/Component/Security/Http/Firewall/AbstractPreAuthenticatedListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/AbstractPreAuthenticatedListener.php @@ -13,8 +13,9 @@ use Psr\Log\LoggerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface; use Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; @@ -31,9 +32,13 @@ * for instance). * * @author Fabien Potencier + * + * @internal since Symfony 4.3 */ abstract class AbstractPreAuthenticatedListener implements ListenerInterface { + use LegacyListenerTrait; + protected $logger; private $tokenStorage; private $authenticationManager; @@ -47,13 +52,13 @@ public function __construct(TokenStorageInterface $tokenStorage, AuthenticationM $this->authenticationManager = $authenticationManager; $this->providerKey = $providerKey; $this->logger = $logger; - $this->dispatcher = $dispatcher; + $this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher); } /** * Handles pre-authentication. */ - final public function handle(GetResponseEvent $event) + public function __invoke(RequestEvent $event) { $request = $event->getRequest(); @@ -92,7 +97,7 @@ final public function handle(GetResponseEvent $event) if (null !== $this->dispatcher) { $loginEvent = new InteractiveLoginEvent($request, $token); - $this->dispatcher->dispatch(SecurityEvents::INTERACTIVE_LOGIN, $loginEvent); + $this->dispatcher->dispatch($loginEvent, SecurityEvents::INTERACTIVE_LOGIN); } } catch (AuthenticationException $e) { $this->clearToken($e); diff --git a/src/Symfony/Component/Security/Http/Firewall/AccessListener.php b/src/Symfony/Component/Security/Http/Firewall/AccessListener.php index e285a249f371..e915f024b99a 100644 --- a/src/Symfony/Component/Security/Http/Firewall/AccessListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/AccessListener.php @@ -11,7 +11,7 @@ namespace Symfony\Component\Security\Http\Firewall; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface; @@ -23,9 +23,13 @@ * AccessListener enforces access control rules. * * @author Fabien Potencier + * + * @final since Symfony 4.3 */ class AccessListener implements ListenerInterface { + use LegacyListenerTrait; + private $tokenStorage; private $accessDecisionManager; private $map; @@ -45,7 +49,7 @@ public function __construct(TokenStorageInterface $tokenStorage, AccessDecisionM * @throws AccessDeniedException * @throws AuthenticationCredentialsNotFoundException */ - public function handle(GetResponseEvent $event) + public function __invoke(RequestEvent $event) { if (null === $token = $this->tokenStorage->getToken()) { throw new AuthenticationCredentialsNotFoundException('A Token was not found in the TokenStorage.'); diff --git a/src/Symfony/Component/Security/Http/Firewall/AnonymousAuthenticationListener.php b/src/Symfony/Component/Security/Http/Firewall/AnonymousAuthenticationListener.php index b3c15a293089..b7a7381bfc88 100644 --- a/src/Symfony/Component/Security/Http/Firewall/AnonymousAuthenticationListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/AnonymousAuthenticationListener.php @@ -12,7 +12,7 @@ namespace Symfony\Component\Security\Http\Firewall; use Psr\Log\LoggerInterface; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface; use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; @@ -23,9 +23,13 @@ * already present. * * @author Fabien Potencier + * + * @final since Symfony 4.3 */ class AnonymousAuthenticationListener implements ListenerInterface { + use LegacyListenerTrait; + private $tokenStorage; private $secret; private $authenticationManager; @@ -42,7 +46,7 @@ public function __construct(TokenStorageInterface $tokenStorage, string $secret, /** * Handles anonymous authentication. */ - public function handle(GetResponseEvent $event) + public function __invoke(RequestEvent $event) { if (null !== $this->tokenStorage->getToken()) { return; diff --git a/src/Symfony/Component/Security/Http/Firewall/BasicAuthenticationListener.php b/src/Symfony/Component/Security/Http/Firewall/BasicAuthenticationListener.php index 6c48162e728e..9d6d81715c29 100644 --- a/src/Symfony/Component/Security/Http/Firewall/BasicAuthenticationListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/BasicAuthenticationListener.php @@ -13,7 +13,7 @@ use Psr\Log\LoggerInterface; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; @@ -26,9 +26,13 @@ * BasicAuthenticationListener implements Basic HTTP authentication. * * @author Fabien Potencier + * + * @final since Symfony 4.3 */ class BasicAuthenticationListener implements ListenerInterface { + use LegacyListenerTrait; + private $tokenStorage; private $authenticationManager; private $providerKey; @@ -54,7 +58,7 @@ public function __construct(TokenStorageInterface $tokenStorage, AuthenticationM /** * Handles basic authentication. */ - public function handle(GetResponseEvent $event) + public function __invoke(RequestEvent $event) { $request = $event->getRequest(); diff --git a/src/Symfony/Component/Security/Http/Firewall/ChannelListener.php b/src/Symfony/Component/Security/Http/Firewall/ChannelListener.php index 11dec6cb4598..671f279fdf9a 100644 --- a/src/Symfony/Component/Security/Http/Firewall/ChannelListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/ChannelListener.php @@ -12,7 +12,7 @@ namespace Symfony\Component\Security\Http\Firewall; use Psr\Log\LoggerInterface; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\Security\Http\AccessMapInterface; use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface; @@ -21,9 +21,13 @@ * configuration. * * @author Fabien Potencier + * + * @final since Symfony 4.3 */ class ChannelListener implements ListenerInterface { + use LegacyListenerTrait; + private $map; private $authenticationEntryPoint; private $logger; @@ -38,7 +42,7 @@ public function __construct(AccessMapInterface $map, AuthenticationEntryPointInt /** * Handles channel management. */ - public function handle(GetResponseEvent $event) + public function __invoke(RequestEvent $event) { $request = $event->getRequest(); diff --git a/src/Symfony/Component/Security/Http/Firewall/ContextListener.php b/src/Symfony/Component/Security/Http/Firewall/ContextListener.php index e86dc5f2302e..2947105fc29a 100644 --- a/src/Symfony/Component/Security/Http/Firewall/ContextListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/ContextListener.php @@ -14,7 +14,7 @@ use Psr\Log\LoggerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpKernel\Event\FilterResponseEvent; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolver; use Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface; @@ -34,9 +34,13 @@ * * @author Fabien Potencier * @author Johannes M. Schmitt + * + * @final since Symfony 4.3 */ class ContextListener implements ListenerInterface { + use LegacyListenerTrait; + private $tokenStorage; private $sessionKey; private $logger; @@ -77,7 +81,7 @@ public function setLogoutOnUserChange($logoutOnUserChange) /** * Reads the Security Token from the session. */ - public function handle(GetResponseEvent $event) + public function __invoke(RequestEvent $event) { if (!$this->registered && null !== $this->dispatcher && $event->isMasterRequest()) { $this->dispatcher->addListener(KernelEvents::RESPONSE, [$this, 'onKernelResponse']); diff --git a/src/Symfony/Component/Security/Http/Firewall/ExceptionListener.php b/src/Symfony/Component/Security/Http/Firewall/ExceptionListener.php index 2aa3ac621fc1..bfd4d5be298a 100644 --- a/src/Symfony/Component/Security/Http/Firewall/ExceptionListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/ExceptionListener.php @@ -38,6 +38,8 @@ * Response instances. * * @author Fabien Potencier + * + * @final since Symfony 4.3 */ class ExceptionListener { diff --git a/src/Symfony/Component/Security/Http/Firewall/LegacyListenerTrait.php b/src/Symfony/Component/Security/Http/Firewall/LegacyListenerTrait.php new file mode 100644 index 000000000000..98933e0f3eef --- /dev/null +++ b/src/Symfony/Component/Security/Http/Firewall/LegacyListenerTrait.php @@ -0,0 +1,60 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Security\Http\Firewall; + +use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; + +/** + * @deprecated + * + * @internal + */ +trait LegacyListenerTrait +{ + /** + * @deprecated since Symfony 4.3, use __invoke() instead + */ + public function handle(GetResponseEvent $event) + { + @trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.3, use __invoke() instead.', __METHOD__), E_USER_DEPRECATED); + + if (!$event instanceof RequestEvent) { + $event = new class($event) extends RequestEvent { + private $event; + + public function __construct(GetResponseEvent $event) + { + parent::__construct($event->getKernel(), $event->getRequest(), $event->getRequestType()); + $this->event = $event; + } + + public function getResponse() + { + return $this->event->getResponse(); + } + + public function setResponse(Response $response) + { + $this->event->setResponse($response); + } + + public function hasResponse() + { + return $this->event->hasResponse(); + } + }; + } + + $this->__invoke($event); + } +} diff --git a/src/Symfony/Component/Security/Http/Firewall/ListenerInterface.php b/src/Symfony/Component/Security/Http/Firewall/ListenerInterface.php index d881badd01f1..88c999a543f8 100644 --- a/src/Symfony/Component/Security/Http/Firewall/ListenerInterface.php +++ b/src/Symfony/Component/Security/Http/Firewall/ListenerInterface.php @@ -17,6 +17,8 @@ * Interface that must be implemented by firewall listeners. * * @author Johannes M. Schmitt + * + * @deprecated since Symfony 4.3, turn listeners into callables instead */ interface ListenerInterface { diff --git a/src/Symfony/Component/Security/Http/Firewall/LogoutListener.php b/src/Symfony/Component/Security/Http/Firewall/LogoutListener.php index 6a762e1fbd57..4dabe20a9cb3 100644 --- a/src/Symfony/Component/Security/Http/Firewall/LogoutListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/LogoutListener.php @@ -13,7 +13,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Security\Core\Exception\LogoutException; use Symfony\Component\Security\Csrf\CsrfToken; @@ -27,9 +27,13 @@ * LogoutListener logout users. * * @author Fabien Potencier + * + * @final since Symfony 4.3 */ class LogoutListener implements ListenerInterface { + use LegacyListenerTrait; + private $tokenStorage; private $options; private $handlers; @@ -72,7 +76,7 @@ public function addHandler(LogoutHandlerInterface $handler) * @throws LogoutException if the CSRF token is invalid * @throws \RuntimeException if the LogoutSuccessHandlerInterface instance does not return a response */ - public function handle(GetResponseEvent $event) + public function __invoke(RequestEvent $event) { $request = $event->getRequest(); diff --git a/src/Symfony/Component/Security/Http/Firewall/RememberMeListener.php b/src/Symfony/Component/Security/Http/Firewall/RememberMeListener.php index 4ff742463471..16073859f85b 100644 --- a/src/Symfony/Component/Security/Http/Firewall/RememberMeListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/RememberMeListener.php @@ -13,7 +13,8 @@ use Psr\Log\LoggerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Security\Core\Exception\AuthenticationException; @@ -27,9 +28,13 @@ * RememberMeListener implements authentication capabilities via a cookie. * * @author Johannes M. Schmitt + * + * @final since Symfony 4.3 */ class RememberMeListener implements ListenerInterface { + use LegacyListenerTrait; + private $tokenStorage; private $rememberMeServices; private $authenticationManager; @@ -44,7 +49,7 @@ public function __construct(TokenStorageInterface $tokenStorage, RememberMeServi $this->rememberMeServices = $rememberMeServices; $this->authenticationManager = $authenticationManager; $this->logger = $logger; - $this->dispatcher = $dispatcher; + $this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher); $this->catchExceptions = $catchExceptions; $this->sessionStrategy = null === $sessionStrategy ? new SessionAuthenticationStrategy(SessionAuthenticationStrategy::MIGRATE) : $sessionStrategy; } @@ -52,7 +57,7 @@ public function __construct(TokenStorageInterface $tokenStorage, RememberMeServi /** * Handles remember-me cookie based authentication. */ - public function handle(GetResponseEvent $event) + public function __invoke(RequestEvent $event) { if (null !== $this->tokenStorage->getToken()) { return; @@ -90,7 +95,7 @@ public function handle(GetResponseEvent $event) if (null !== $this->dispatcher) { $loginEvent = new InteractiveLoginEvent($request, $token); - $this->dispatcher->dispatch(SecurityEvents::INTERACTIVE_LOGIN, $loginEvent); + $this->dispatcher->dispatch($loginEvent, SecurityEvents::INTERACTIVE_LOGIN); } if (null !== $this->logger) { diff --git a/src/Symfony/Component/Security/Http/Firewall/SimplePreAuthenticationListener.php b/src/Symfony/Component/Security/Http/Firewall/SimplePreAuthenticationListener.php index c33b1fb30ac5..2c444e823b6f 100644 --- a/src/Symfony/Component/Security/Http/Firewall/SimplePreAuthenticationListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/SimplePreAuthenticationListener.php @@ -13,9 +13,10 @@ use Psr\Log\LoggerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface; use Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolver; use Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface; @@ -42,6 +43,8 @@ */ class SimplePreAuthenticationListener implements ListenerInterface { + use LegacyListenerTrait; + private $tokenStorage; private $authenticationManager; private $providerKey; @@ -62,7 +65,7 @@ public function __construct(TokenStorageInterface $tokenStorage, AuthenticationM $this->providerKey = $providerKey; $this->simpleAuthenticator = $simpleAuthenticator; $this->logger = $logger; - $this->dispatcher = $dispatcher; + $this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher); $this->trustResolver = $trustResolver ?: new AuthenticationTrustResolver(AnonymousToken::class, RememberMeToken::class); } @@ -79,7 +82,7 @@ public function setSessionAuthenticationStrategy(SessionAuthenticationStrategyIn /** * Handles basic authentication. */ - public function handle(GetResponseEvent $event) + public function __invoke(RequestEvent $event) { $request = $event->getRequest(); @@ -107,7 +110,7 @@ public function handle(GetResponseEvent $event) if (null !== $this->dispatcher) { $loginEvent = new InteractiveLoginEvent($request, $token); - $this->dispatcher->dispatch(SecurityEvents::INTERACTIVE_LOGIN, $loginEvent); + $this->dispatcher->dispatch($loginEvent, SecurityEvents::INTERACTIVE_LOGIN); } } catch (AuthenticationException $e) { $this->tokenStorage->setToken(null); diff --git a/src/Symfony/Component/Security/Http/Firewall/SwitchUserListener.php b/src/Symfony/Component/Security/Http/Firewall/SwitchUserListener.php index 102ab3061520..092b334ae6ff 100644 --- a/src/Symfony/Component/Security/Http/Firewall/SwitchUserListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/SwitchUserListener.php @@ -13,9 +13,10 @@ use Psr\Log\LoggerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Security\Core\Authentication\Token\SwitchUserToken; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; @@ -35,9 +36,13 @@ * (like the Unix su command). * * @author Fabien Potencier + * + * @final since Symfony 4.3 */ class SwitchUserListener implements ListenerInterface { + use LegacyListenerTrait; + const EXIT_VALUE = '_exit'; private $tokenStorage; @@ -65,7 +70,7 @@ public function __construct(TokenStorageInterface $tokenStorage, UserProviderInt $this->usernameParameter = $usernameParameter; $this->role = $role; $this->logger = $logger; - $this->dispatcher = $dispatcher; + $this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher); $this->stateless = $stateless; } @@ -74,7 +79,7 @@ public function __construct(TokenStorageInterface $tokenStorage, UserProviderInt * * @throws \LogicException if switching to a user failed */ - public function handle(GetResponseEvent $event) + public function __invoke(RequestEvent $event) { $request = $event->getRequest(); $username = $request->get($this->usernameParameter) ?: $request->headers->get($this->usernameParameter); @@ -152,7 +157,7 @@ private function attemptSwitchUser(Request $request, $username) if (null !== $this->dispatcher) { $switchEvent = new SwitchUserEvent($request, $token->getUser(), $token); - $this->dispatcher->dispatch(SecurityEvents::SWITCH_USER, $switchEvent); + $this->dispatcher->dispatch($switchEvent, SecurityEvents::SWITCH_USER); // use the token from the event in case any listeners have replaced it. $token = $switchEvent->getToken(); } @@ -176,7 +181,7 @@ private function attemptExitUser(Request $request) if (null !== $this->dispatcher && $original->getUser() instanceof UserInterface) { $user = $this->provider->refreshUser($original->getUser()); $switchEvent = new SwitchUserEvent($request, $user, $original); - $this->dispatcher->dispatch(SecurityEvents::SWITCH_USER, $switchEvent); + $this->dispatcher->dispatch($switchEvent, SecurityEvents::SWITCH_USER); $original = $switchEvent->getToken(); } diff --git a/src/Symfony/Component/Security/Http/Firewall/UsernamePasswordJsonAuthenticationListener.php b/src/Symfony/Component/Security/Http/Firewall/UsernamePasswordJsonAuthenticationListener.php index f7b69f0da539..90a8225b35dc 100644 --- a/src/Symfony/Component/Security/Http/Firewall/UsernamePasswordJsonAuthenticationListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/UsernamePasswordJsonAuthenticationListener.php @@ -13,10 +13,11 @@ use Psr\Log\LoggerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\PropertyAccess\Exception\AccessException; use Symfony\Component\PropertyAccess\PropertyAccess; @@ -40,9 +41,13 @@ * an authentication via a JSON document composed of a username and a password. * * @author KĂ©vin Dunglas + * + * @final since Symfony 4.3 */ class UsernamePasswordJsonAuthenticationListener implements ListenerInterface { + use LegacyListenerTrait; + private $tokenStorage; private $authenticationManager; private $httpUtils; @@ -64,7 +69,7 @@ public function __construct(TokenStorageInterface $tokenStorage, AuthenticationM $this->successHandler = $successHandler; $this->failureHandler = $failureHandler; $this->logger = $logger; - $this->eventDispatcher = $eventDispatcher; + $this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher); $this->options = array_merge(['username_path' => 'username', 'password_path' => 'password'], $options); $this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor(); } @@ -72,7 +77,7 @@ public function __construct(TokenStorageInterface $tokenStorage, AuthenticationM /** * {@inheritdoc} */ - public function handle(GetResponseEvent $event) + public function __invoke(RequestEvent $event) { $request = $event->getRequest(); if (false === strpos($request->getRequestFormat(), 'json') @@ -147,7 +152,7 @@ private function onSuccess(Request $request, TokenInterface $token) if (null !== $this->eventDispatcher) { $loginEvent = new InteractiveLoginEvent($request, $token); - $this->eventDispatcher->dispatch(SecurityEvents::INTERACTIVE_LOGIN, $loginEvent); + $this->eventDispatcher->dispatch($loginEvent, SecurityEvents::INTERACTIVE_LOGIN); } if (!$this->successHandler) { diff --git a/src/Symfony/Component/Security/Http/RememberMe/ResponseListener.php b/src/Symfony/Component/Security/Http/RememberMe/ResponseListener.php index 7d931166dd13..1993db5731bc 100644 --- a/src/Symfony/Component/Security/Http/RememberMe/ResponseListener.php +++ b/src/Symfony/Component/Security/Http/RememberMe/ResponseListener.php @@ -19,6 +19,8 @@ * Adds remember-me cookies to the Response. * * @author Johannes M. Schmitt + * + * @final since Symfony 4.3 */ class ResponseListener implements EventSubscriberInterface { diff --git a/src/Symfony/Component/Security/Http/Tests/Firewall/AbstractPreAuthenticatedListenerTest.php b/src/Symfony/Component/Security/Http/Tests/Firewall/AbstractPreAuthenticatedListenerTest.php index 44bbf4423be5..4ae01ef1136f 100644 --- a/src/Symfony/Component/Security/Http/Tests/Firewall/AbstractPreAuthenticatedListenerTest.php +++ b/src/Symfony/Component/Security/Http/Tests/Firewall/AbstractPreAuthenticatedListenerTest.php @@ -13,6 +13,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken; use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; use Symfony\Component\Security\Core\Exception\AuthenticationException; @@ -57,14 +58,14 @@ public function testHandleWithValidValues() ->method('getPreAuthenticatedData') ->will($this->returnValue($userCredentials)); - $event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock(); + $event = $this->getMockBuilder(RequestEvent::class)->disableOriginalConstructor()->getMock(); $event ->expects($this->any()) ->method('getRequest') ->will($this->returnValue($request)) ; - $listener->handle($event); + $listener($event); } public function testHandleWhenAuthenticationFails() @@ -103,14 +104,14 @@ public function testHandleWhenAuthenticationFails() ->method('getPreAuthenticatedData') ->will($this->returnValue($userCredentials)); - $event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock(); + $event = $this->getMockBuilder(RequestEvent::class)->disableOriginalConstructor()->getMock(); $event ->expects($this->any()) ->method('getRequest') ->will($this->returnValue($request)) ; - $listener->handle($event); + $listener($event); } public function testHandleWhenAuthenticationFailsWithDifferentToken() @@ -151,14 +152,14 @@ public function testHandleWhenAuthenticationFailsWithDifferentToken() ->method('getPreAuthenticatedData') ->will($this->returnValue($userCredentials)); - $event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock(); + $event = $this->getMockBuilder(RequestEvent::class)->disableOriginalConstructor()->getMock(); $event ->expects($this->any()) ->method('getRequest') ->will($this->returnValue($request)) ; - $listener->handle($event); + $listener($event); } public function testHandleWithASimilarAuthenticatedToken() @@ -192,14 +193,14 @@ public function testHandleWithASimilarAuthenticatedToken() ->method('getPreAuthenticatedData') ->will($this->returnValue($userCredentials)); - $event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock(); + $event = $this->getMockBuilder(RequestEvent::class)->disableOriginalConstructor()->getMock(); $event ->expects($this->any()) ->method('getRequest') ->will($this->returnValue($request)) ; - $listener->handle($event); + $listener($event); } public function testHandleWithAnInvalidSimilarToken() @@ -241,13 +242,13 @@ public function testHandleWithAnInvalidSimilarToken() ->method('getPreAuthenticatedData') ->will($this->returnValue($userCredentials)); - $event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock(); + $event = $this->getMockBuilder(RequestEvent::class)->disableOriginalConstructor()->getMock(); $event ->expects($this->any()) ->method('getRequest') ->will($this->returnValue($request)) ; - $listener->handle($event); + $listener($event); } } diff --git a/src/Symfony/Component/Security/Http/Tests/Firewall/AccessListenerTest.php b/src/Symfony/Component/Security/Http/Tests/Firewall/AccessListenerTest.php index 92b2270877fb..b62a49956a51 100644 --- a/src/Symfony/Component/Security/Http/Tests/Firewall/AccessListenerTest.php +++ b/src/Symfony/Component/Security/Http/Tests/Firewall/AccessListenerTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Security\Http\Tests\Firewall; use PHPUnit\Framework\TestCase; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\Security\Http\Firewall\AccessListener; class AccessListenerTest extends TestCase @@ -60,14 +61,14 @@ public function testHandleWhenTheAccessDecisionManagerDecidesToRefuseAccess() $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')->getMock() ); - $event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock(); + $event = $this->getMockBuilder(RequestEvent::class)->disableOriginalConstructor()->getMock(); $event ->expects($this->any()) ->method('getRequest') ->will($this->returnValue($request)) ; - $listener->handle($event); + $listener($event); } public function testHandleWhenTheTokenIsNotAuthenticated() @@ -131,14 +132,14 @@ public function testHandleWhenTheTokenIsNotAuthenticated() $authManager ); - $event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock(); + $event = $this->getMockBuilder(RequestEvent::class)->disableOriginalConstructor()->getMock(); $event ->expects($this->any()) ->method('getRequest') ->will($this->returnValue($request)) ; - $listener->handle($event); + $listener($event); } public function testHandleWhenThereIsNoAccessMapEntryMatchingTheRequest() @@ -173,14 +174,14 @@ public function testHandleWhenThereIsNoAccessMapEntryMatchingTheRequest() $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')->getMock() ); - $event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock(); + $event = $this->getMockBuilder(RequestEvent::class)->disableOriginalConstructor()->getMock(); $event ->expects($this->any()) ->method('getRequest') ->will($this->returnValue($request)) ; - $listener->handle($event); + $listener($event); } /** @@ -202,8 +203,8 @@ public function testHandleWhenTheSecurityTokenStorageHasNoToken() $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')->getMock() ); - $event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock(); + $event = $this->getMockBuilder(RequestEvent::class)->disableOriginalConstructor()->getMock(); - $listener->handle($event); + $listener($event); } } diff --git a/src/Symfony/Component/Security/Http/Tests/Firewall/AnonymousAuthenticationListenerTest.php b/src/Symfony/Component/Security/Http/Tests/Firewall/AnonymousAuthenticationListenerTest.php index f6f36415d37e..fd48c27a5e26 100644 --- a/src/Symfony/Component/Security/Http/Tests/Firewall/AnonymousAuthenticationListenerTest.php +++ b/src/Symfony/Component/Security/Http/Tests/Firewall/AnonymousAuthenticationListenerTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Security\Http\Tests\Firewall; use PHPUnit\Framework\TestCase; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken; use Symfony\Component\Security\Http\Firewall\AnonymousAuthenticationListener; @@ -37,7 +38,7 @@ public function testHandleWithTokenStorageHavingAToken() ; $listener = new AnonymousAuthenticationListener($tokenStorage, 'TheSecret', null, $authenticationManager); - $listener->handle($this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock()); + $listener($this->getMockBuilder(RequestEvent::class)->disableOriginalConstructor()->getMock()); } public function testHandleWithTokenStorageHavingNoToken() @@ -68,7 +69,7 @@ public function testHandleWithTokenStorageHavingNoToken() ; $listener = new AnonymousAuthenticationListener($tokenStorage, 'TheSecret', null, $authenticationManager); - $listener->handle($this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock()); + $listener($this->getMockBuilder(RequestEvent::class)->disableOriginalConstructor()->getMock()); } public function testHandledEventIsLogged() @@ -83,6 +84,6 @@ public function testHandledEventIsLogged() $authenticationManager = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')->getMock(); $listener = new AnonymousAuthenticationListener($tokenStorage, 'TheSecret', $logger, $authenticationManager); - $listener->handle($this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock()); + $listener($this->getMockBuilder(RequestEvent::class)->disableOriginalConstructor()->getMock()); } } diff --git a/src/Symfony/Component/Security/Http/Tests/Firewall/BasicAuthenticationListenerTest.php b/src/Symfony/Component/Security/Http/Tests/Firewall/BasicAuthenticationListenerTest.php index 2eec46b1d16a..574cab862183 100644 --- a/src/Symfony/Component/Security/Http/Tests/Firewall/BasicAuthenticationListenerTest.php +++ b/src/Symfony/Component/Security/Http/Tests/Firewall/BasicAuthenticationListenerTest.php @@ -14,6 +14,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\Security\Core\Authentication\AuthenticationProviderManager; use Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken; use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; @@ -57,14 +58,14 @@ public function testHandleWithValidUsernameAndPasswordServerParameters() $this->getMockBuilder('Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface')->getMock() ); - $event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock(); + $event = $this->getMockBuilder(RequestEvent::class)->disableOriginalConstructor()->getMock(); $event ->expects($this->any()) ->method('getRequest') ->will($this->returnValue($request)) ; - $listener->handle($event); + $listener($event); } public function testHandleWhenAuthenticationFails() @@ -104,7 +105,7 @@ public function testHandleWhenAuthenticationFails() $authenticationEntryPoint ); - $event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock(); + $event = $this->getMockBuilder(RequestEvent::class)->disableOriginalConstructor()->getMock(); $event ->expects($this->any()) ->method('getRequest') @@ -116,7 +117,7 @@ public function testHandleWhenAuthenticationFails() ->with($this->equalTo($response)) ; - $listener->handle($event); + $listener($event); } public function testHandleWithNoUsernameServerParameter() @@ -136,14 +137,14 @@ public function testHandleWithNoUsernameServerParameter() $this->getMockBuilder('Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface')->getMock() ); - $event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock(); + $event = $this->getMockBuilder(RequestEvent::class)->disableOriginalConstructor()->getMock(); $event ->expects($this->any()) ->method('getRequest') ->will($this->returnValue($request)) ; - $listener->handle($event); + $listener($event); } public function testHandleWithASimilarAuthenticatedToken() @@ -172,14 +173,14 @@ public function testHandleWithASimilarAuthenticatedToken() $this->getMockBuilder('Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface')->getMock() ); - $event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock(); + $event = $this->getMockBuilder(RequestEvent::class)->disableOriginalConstructor()->getMock(); $event ->expects($this->any()) ->method('getRequest') ->will($this->returnValue($request)) ; - $listener->handle($event); + $listener($event); } /** @@ -233,7 +234,7 @@ public function testHandleWithADifferentAuthenticatedToken() $authenticationEntryPoint ); - $event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock(); + $event = $this->getMockBuilder(RequestEvent::class)->disableOriginalConstructor()->getMock(); $event ->expects($this->any()) ->method('getRequest') @@ -245,6 +246,6 @@ public function testHandleWithADifferentAuthenticatedToken() ->with($this->equalTo($response)) ; - $listener->handle($event); + $listener($event); } } diff --git a/src/Symfony/Component/Security/Http/Tests/Firewall/ChannelListenerTest.php b/src/Symfony/Component/Security/Http/Tests/Firewall/ChannelListenerTest.php index 3740faec8ba8..4b7238a8cdff 100644 --- a/src/Symfony/Component/Security/Http/Tests/Firewall/ChannelListenerTest.php +++ b/src/Symfony/Component/Security/Http/Tests/Firewall/ChannelListenerTest.php @@ -13,6 +13,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\Security\Http\Firewall\ChannelListener; class ChannelListenerTest extends TestCase @@ -40,7 +41,7 @@ public function testHandleWithNotSecuredRequestAndHttpChannel() ->method('start') ; - $event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock(); + $event = $this->getMockBuilder(RequestEvent::class)->disableOriginalConstructor()->getMock(); $event ->expects($this->any()) ->method('getRequest') @@ -52,7 +53,7 @@ public function testHandleWithNotSecuredRequestAndHttpChannel() ; $listener = new ChannelListener($accessMap, $entryPoint); - $listener->handle($event); + $listener($event); } public function testHandleWithSecuredRequestAndHttpsChannel() @@ -78,7 +79,7 @@ public function testHandleWithSecuredRequestAndHttpsChannel() ->method('start') ; - $event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock(); + $event = $this->getMockBuilder(RequestEvent::class)->disableOriginalConstructor()->getMock(); $event ->expects($this->any()) ->method('getRequest') @@ -90,7 +91,7 @@ public function testHandleWithSecuredRequestAndHttpsChannel() ; $listener = new ChannelListener($accessMap, $entryPoint); - $listener->handle($event); + $listener($event); } public function testHandleWithNotSecuredRequestAndHttpsChannel() @@ -120,7 +121,7 @@ public function testHandleWithNotSecuredRequestAndHttpsChannel() ->will($this->returnValue($response)) ; - $event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock(); + $event = $this->getMockBuilder(RequestEvent::class)->disableOriginalConstructor()->getMock(); $event ->expects($this->any()) ->method('getRequest') @@ -133,7 +134,7 @@ public function testHandleWithNotSecuredRequestAndHttpsChannel() ; $listener = new ChannelListener($accessMap, $entryPoint); - $listener->handle($event); + $listener($event); } public function testHandleWithSecuredRequestAndHttpChannel() @@ -163,7 +164,7 @@ public function testHandleWithSecuredRequestAndHttpChannel() ->will($this->returnValue($response)) ; - $event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock(); + $event = $this->getMockBuilder(RequestEvent::class)->disableOriginalConstructor()->getMock(); $event ->expects($this->any()) ->method('getRequest') @@ -176,6 +177,6 @@ public function testHandleWithSecuredRequestAndHttpChannel() ; $listener = new ChannelListener($accessMap, $entryPoint); - $listener->handle($event); + $listener($event); } } diff --git a/src/Symfony/Component/Security/Http/Tests/Firewall/ContextListenerTest.php b/src/Symfony/Component/Security/Http/Tests/Firewall/ContextListenerTest.php index e3c55d33ed1c..644ba93ec57e 100644 --- a/src/Symfony/Component/Security/Http/Tests/Firewall/ContextListenerTest.php +++ b/src/Symfony/Component/Security/Http/Tests/Firewall/ContextListenerTest.php @@ -13,12 +13,13 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\EventDispatcher\EventDispatcher; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; +use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken; @@ -41,7 +42,7 @@ class ContextListenerTest extends TestCase public function testItRequiresContextKey() { new ContextListener( - $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock(), + $this->getMockBuilder(TokenStorageInterface::class)->getMock(), [], '' ); @@ -105,8 +106,8 @@ public function testOnKernelResponseWithoutSession() $session = new Session(new MockArraySessionStorage()); $request->setSession($session); - $event = new FilterResponseEvent( - $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), + $event = new ResponseEvent( + $this->getMockBuilder(HttpKernelInterface::class)->getMock(), $request, HttpKernelInterface::MASTER_REQUEST, new Response() @@ -124,8 +125,8 @@ public function testOnKernelResponseWithoutSessionNorToken() $session = new Session(new MockArraySessionStorage()); $request->setSession($session); - $event = new FilterResponseEvent( - $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), + $event = new ResponseEvent( + $this->getMockBuilder(HttpKernelInterface::class)->getMock(), $request, HttpKernelInterface::MASTER_REQUEST, new Response() @@ -142,8 +143,8 @@ public function testOnKernelResponseWithoutSessionNorToken() */ public function testInvalidTokenInSession($token) { - $tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock(); - $event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent') + $tokenStorage = $this->getMockBuilder(TokenStorageInterface::class)->getMock(); + $event = $this->getMockBuilder(RequestEvent::class) ->disableOriginalConstructor() ->getMock(); $request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')->getMock(); @@ -167,7 +168,7 @@ public function testInvalidTokenInSession($token) ->with(null); $listener = new ContextListener($tokenStorage, [], 'key123'); - $listener->handle($event); + $listener($event); } public function provideInvalidToken() @@ -183,9 +184,9 @@ public function provideInvalidToken() public function testHandleAddsKernelResponseListener() { - $tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock(); - $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock(); - $event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent') + $tokenStorage = $this->getMockBuilder(TokenStorageInterface::class)->getMock(); + $dispatcher = $this->getMockBuilder(EventDispatcherInterface::class)->getMock(); + $event = $this->getMockBuilder(RequestEvent::class) ->disableOriginalConstructor() ->getMock(); @@ -202,14 +203,14 @@ public function testHandleAddsKernelResponseListener() ->method('addListener') ->with(KernelEvents::RESPONSE, [$listener, 'onKernelResponse']); - $listener->handle($event); + $listener($event); } public function testOnKernelResponseListenerRemovesItself() { - $tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock(); - $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock(); - $event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\FilterResponseEvent') + $tokenStorage = $this->getMockBuilder(TokenStorageInterface::class)->getMock(); + $dispatcher = $this->getMockBuilder(EventDispatcherInterface::class)->getMock(); + $event = $this->getMockBuilder(ResponseEvent::class) ->disableOriginalConstructor() ->getMock(); @@ -239,16 +240,16 @@ public function testHandleRemovesTokenIfNoPreviousSessionWasFound() $request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')->getMock(); $request->expects($this->any())->method('hasPreviousSession')->will($this->returnValue(false)); - $event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent') + $event = $this->getMockBuilder(RequestEvent::class) ->disableOriginalConstructor() ->getMock(); $event->expects($this->any())->method('getRequest')->will($this->returnValue($request)); - $tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock(); + $tokenStorage = $this->getMockBuilder(TokenStorageInterface::class)->getMock(); $tokenStorage->expects($this->once())->method('setToken')->with(null); $listener = new ContextListener($tokenStorage, [], 'key123'); - $listener->handle($event); + $listener($event); } public function testIfTokenIsDeauthenticated() @@ -327,8 +328,8 @@ protected function runSessionOnKernelResponse($newToken, $original = null) $request->setSession($session); $request->cookies->set('MOCKSESSID', true); - $event = new FilterResponseEvent( - $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), + $event = new ResponseEvent( + $this->getMockBuilder(HttpKernelInterface::class)->getMock(), $request, HttpKernelInterface::MASTER_REQUEST, new Response() @@ -351,7 +352,7 @@ private function handleEventWithPreviousSession(TokenStorageInterface $tokenStor $request->cookies->set('MOCKSESSID', true); $listener = new ContextListener($tokenStorage, $userProviders, 'context_key'); - $listener->handle(new GetResponseEvent($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $request, HttpKernelInterface::MASTER_REQUEST)); + $listener(new RequestEvent($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $request, HttpKernelInterface::MASTER_REQUEST)); } } diff --git a/src/Symfony/Component/Security/Http/Tests/Firewall/ExceptionListenerTest.php b/src/Symfony/Component/Security/Http/Tests/Firewall/ExceptionListenerTest.php index 53fedebcad70..96b8940ccbd0 100644 --- a/src/Symfony/Component/Security/Http/Tests/Firewall/ExceptionListenerTest.php +++ b/src/Symfony/Component/Security/Http/Tests/Firewall/ExceptionListenerTest.php @@ -14,8 +14,9 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; use Symfony\Component\HttpKernel\Exception\HttpException; +use Symfony\Component\HttpKernel\Event\ExceptionEvent; +use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; @@ -190,6 +191,10 @@ private function createEvent(\Exception $exception, $kernel = null) $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(); } + if (class_exists(ExceptionEvent::class)) { + return new ExceptionEvent($kernel, Request::create('/'), HttpKernelInterface::MASTER_REQUEST, $exception); + } + return new GetResponseForExceptionEvent($kernel, Request::create('/'), HttpKernelInterface::MASTER_REQUEST, $exception); } diff --git a/src/Symfony/Component/Security/Http/Tests/Firewall/LogoutListenerTest.php b/src/Symfony/Component/Security/Http/Tests/Firewall/LogoutListenerTest.php index fbcea3d738e7..b2cbc0a03539 100644 --- a/src/Symfony/Component/Security/Http/Tests/Firewall/LogoutListenerTest.php +++ b/src/Symfony/Component/Security/Http/Tests/Firewall/LogoutListenerTest.php @@ -14,6 +14,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\Security\Http\Firewall\LogoutListener; class LogoutListenerTest extends TestCase @@ -32,7 +33,7 @@ public function testHandleUnmatchedPath() ->with($request, $options['logout_path']) ->will($this->returnValue(false)); - $listener->handle($event); + $listener($event); } public function testHandleMatchedPathWithSuccessHandlerAndCsrfValidation() @@ -79,7 +80,7 @@ public function testHandleMatchedPathWithSuccessHandlerAndCsrfValidation() $listener->addHandler($handler); - $listener->handle($event); + $listener($event); } public function testHandleMatchedPathWithoutSuccessHandlerAndCsrfValidation() @@ -119,7 +120,7 @@ public function testHandleMatchedPathWithoutSuccessHandlerAndCsrfValidation() $listener->addHandler($handler); - $listener->handle($event); + $listener($event); } /** @@ -143,7 +144,7 @@ public function testSuccessHandlerReturnsNonResponse() ->with($request) ->will($this->returnValue(null)); - $listener->handle($event); + $listener($event); } /** @@ -168,7 +169,7 @@ public function testCsrfValidationFails() ->method('isTokenValid') ->will($this->returnValue(false)); - $listener->handle($event); + $listener($event); } private function getTokenManager() @@ -183,7 +184,7 @@ private function getTokenStorage() private function getGetResponseEvent() { - $event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent') + $event = $this->getMockBuilder(RequestEvent::class) ->disableOriginalConstructor() ->getMock(); diff --git a/src/Symfony/Component/Security/Http/Tests/Firewall/RememberMeListenerTest.php b/src/Symfony/Component/Security/Http/Tests/Firewall/RememberMeListenerTest.php index 686c7231e689..fe237e3dbf04 100644 --- a/src/Symfony/Component/Security/Http/Tests/Firewall/RememberMeListenerTest.php +++ b/src/Symfony/Component/Security/Http/Tests/Firewall/RememberMeListenerTest.php @@ -13,6 +13,8 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpKernel\Event\RequestEvent; +use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\Security\Core\Exception\AuthenticationException; use Symfony\Component\Security\Http\Firewall\RememberMeListener; use Symfony\Component\Security\Http\SecurityEvents; @@ -34,7 +36,7 @@ public function testOnCoreSecurityDoesNotTryToPopulateNonEmptyTokenStorage() ->method('setToken') ; - $this->assertNull($listener->handle($this->getGetResponseEvent())); + $this->assertNull($listener($this->getGetResponseEvent())); } public function testOnCoreSecurityDoesNothingWhenNoCookieIsSet() @@ -60,7 +62,7 @@ public function testOnCoreSecurityDoesNothingWhenNoCookieIsSet() ->will($this->returnValue(new Request())) ; - $this->assertNull($listener->handle($event)); + $this->assertNull($listener($event)); } public function testOnCoreSecurityIgnoresAuthenticationExceptionThrownByAuthenticationManagerImplementation() @@ -100,7 +102,7 @@ public function testOnCoreSecurityIgnoresAuthenticationExceptionThrownByAuthenti ->will($this->returnValue($request)) ; - $listener->handle($event); + $listener($event); } /** @@ -142,7 +144,7 @@ public function testOnCoreSecurityIgnoresAuthenticationOptionallyRethrowsExcepti ->will($this->returnValue(new Request())) ; - $listener->handle($event); + $listener($event); } public function testOnCoreSecurityAuthenticationExceptionDuringAutoLoginTriggersLoginFail() @@ -179,7 +181,7 @@ public function testOnCoreSecurityAuthenticationExceptionDuringAutoLoginTriggers ->will($this->returnValue(new Request())) ; - $listener->handle($event); + $listener($event); } public function testOnCoreSecurity() @@ -218,7 +220,7 @@ public function testOnCoreSecurity() ->will($this->returnValue(new Request())) ; - $listener->handle($event); + $listener($event); } public function testSessionStrategy() @@ -283,7 +285,7 @@ public function testSessionStrategy() ->will($this->returnValue(null)) ; - $listener->handle($event); + $listener($event); } public function testSessionIsMigratedByDefault() @@ -346,7 +348,7 @@ public function testSessionIsMigratedByDefault() ->will($this->returnValue($request)) ; - $listener->handle($event); + $listener($event); } public function testOnCoreSecurityInteractiveLoginEventIsDispatchedIfDispatcherIsPresent() @@ -390,22 +392,22 @@ public function testOnCoreSecurityInteractiveLoginEventIsDispatchedIfDispatcherI ->expects($this->once()) ->method('dispatch') ->with( - SecurityEvents::INTERACTIVE_LOGIN, - $this->isInstanceOf('Symfony\Component\Security\Http\Event\InteractiveLoginEvent') + $this->isInstanceOf('Symfony\Component\Security\Http\Event\InteractiveLoginEvent'), + SecurityEvents::INTERACTIVE_LOGIN ) ; - $listener->handle($event); + $listener($event); } protected function getGetResponseEvent() { - return $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock(); + return $this->getMockBuilder(RequestEvent::class)->disableOriginalConstructor()->getMock(); } - protected function getFilterResponseEvent() + protected function getResponseEvent(): ResponseEvent { - return $this->getMockBuilder('Symfony\Component\HttpKernel\Event\FilterResponseEvent')->disableOriginalConstructor()->getMock(); + return $this->getMockBuilder(ResponseEvent::class)->disableOriginalConstructor()->getMock(); } protected function getListener($withDispatcher = false, $catchExceptions = true, $withSessionStrategy = false) diff --git a/src/Symfony/Component/Security/Http/Tests/Firewall/SimplePreAuthenticationListenerTest.php b/src/Symfony/Component/Security/Http/Tests/Firewall/SimplePreAuthenticationListenerTest.php index e35c9e97f242..97feb180cef1 100644 --- a/src/Symfony/Component/Security/Http/Tests/Firewall/SimplePreAuthenticationListenerTest.php +++ b/src/Symfony/Component/Security/Http/Tests/Firewall/SimplePreAuthenticationListenerTest.php @@ -13,6 +13,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\Security\Core\Exception\AuthenticationException; use Symfony\Component\Security\Http\Event\InteractiveLoginEvent; use Symfony\Component\Security\Http\Firewall\SimplePreAuthenticationListener; @@ -59,12 +60,12 @@ public function testHandle() $this->dispatcher ->expects($this->once()) ->method('dispatch') - ->with($this->equalTo(SecurityEvents::INTERACTIVE_LOGIN), $this->equalTo($loginEvent)) + ->with($this->equalTo($loginEvent), $this->equalTo(SecurityEvents::INTERACTIVE_LOGIN)) ; $listener = new SimplePreAuthenticationListener($this->tokenStorage, $this->authenticationManager, 'secured_area', $simpleAuthenticator, $this->logger, $this->dispatcher); - $listener->handle($this->event); + $listener($this->event); } public function testHandlecatchAuthenticationException() @@ -93,7 +94,7 @@ public function testHandlecatchAuthenticationException() $listener = new SimplePreAuthenticationListener($this->tokenStorage, $this->authenticationManager, 'secured_area', $simpleAuthenticator, $this->logger, $this->dispatcher); - $listener->handle($this->event); + $listener($this->event); } protected function setUp() @@ -107,7 +108,7 @@ protected function setUp() $this->request = new Request([], [], [], [], [], []); - $this->event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock(); + $this->event = $this->getMockBuilder(RequestEvent::class)->disableOriginalConstructor()->getMock(); $this->event ->expects($this->any()) ->method('getRequest') diff --git a/src/Symfony/Component/Security/Http/Tests/Firewall/SwitchUserListenerTest.php b/src/Symfony/Component/Security/Http/Tests/Firewall/SwitchUserListenerTest.php index fad023cd5230..c8b3ed245cb6 100644 --- a/src/Symfony/Component/Security/Http/Tests/Firewall/SwitchUserListenerTest.php +++ b/src/Symfony/Component/Security/Http/Tests/Firewall/SwitchUserListenerTest.php @@ -13,7 +13,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; use Symfony\Component\Security\Core\Authentication\Token\SwitchUserToken; @@ -45,7 +45,7 @@ protected function setUp() $this->userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')->getMock(); $this->accessDecisionManager = $this->getMockBuilder('Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface')->getMock(); $this->request = new Request(); - $this->event = new GetResponseEvent($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $this->request, HttpKernelInterface::MASTER_REQUEST); + $this->event = new RequestEvent($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $this->request, HttpKernelInterface::MASTER_REQUEST); } /** @@ -60,7 +60,7 @@ public function testProviderKeyIsRequired() public function testEventIsIgnoredIfUsernameIsNotPassedWithTheRequest() { $listener = new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager); - $listener->handle($this->event); + $listener($this->event); $this->assertNull($this->event->getResponse()); $this->assertNull($this->tokenStorage->getToken()); @@ -74,7 +74,7 @@ public function testExitUserThrowsAuthenticationExceptionIfNoCurrentToken() $this->tokenStorage->setToken(null); $this->request->query->set('_switch_user', '_exit'); $listener = new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager); - $listener->handle($this->event); + $listener($this->event); } /** @@ -88,7 +88,7 @@ public function testExitUserThrowsAuthenticationExceptionIfOriginalTokenCannotBe $this->request->query->set('_switch_user', SwitchUserListener::EXIT_VALUE); $listener = new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager); - $listener->handle($this->event); + $listener($this->event); } public function testExitUserUpdatesToken() @@ -99,7 +99,7 @@ public function testExitUserUpdatesToken() $this->request->query->set('_switch_user', SwitchUserListener::EXIT_VALUE); $listener = new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager); - $listener->handle($this->event); + $listener($this->event); $this->assertSame([], $this->request->query->all()); $this->assertSame('', $this->request->server->get('QUERY_STRING')); @@ -119,7 +119,7 @@ public function testExitUserBasedOnSwitchUserRoleUpdatesToken() $this->request->query->set('_switch_user', SwitchUserListener::EXIT_VALUE); $listener = new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager); - $listener->handle($this->event); + $listener($this->event); $this->assertSame($originalToken, $this->tokenStorage->getToken()); } @@ -142,13 +142,16 @@ public function testExitUserDispatchesEventWithRefreshedUser() $dispatcher ->expects($this->once()) ->method('dispatch') - ->with(SecurityEvents::SWITCH_USER, $this->callback(function (SwitchUserEvent $event) use ($refreshedUser) { - return $event->getTargetUser() === $refreshedUser; - })) + ->with( + $this->callback(function (SwitchUserEvent $event) use ($refreshedUser) { + return $event->getTargetUser() === $refreshedUser; + }), + SecurityEvents::SWITCH_USER + ) ; $listener = new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager, null, '_switch_user', 'ROLE_ALLOWED_TO_SWITCH', $dispatcher); - $listener->handle($this->event); + $listener($this->event); } public function testExitUserDoesNotDispatchEventWithStringUser() @@ -169,7 +172,7 @@ public function testExitUserDoesNotDispatchEventWithStringUser() ; $listener = new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager, null, '_switch_user', 'ROLE_ALLOWED_TO_SWITCH', $dispatcher); - $listener->handle($this->event); + $listener($this->event); } /** @@ -187,7 +190,7 @@ public function testSwitchUserIsDisallowed() ->will($this->returnValue(false)); $listener = new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager); - $listener->handle($this->event); + $listener($this->event); } public function testSwitchUser() @@ -209,7 +212,7 @@ public function testSwitchUser() ->method('checkPostAuth')->with($user); $listener = new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager); - $listener->handle($this->event); + $listener($this->event); $this->assertSame([], $this->request->query->all()); $this->assertSame('', $this->request->server->get('QUERY_STRING')); @@ -239,7 +242,7 @@ public function testSwitchUserKeepsOtherQueryStringParameters() ->method('checkPostAuth')->with($user); $listener = new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager); - $listener->handle($this->event); + $listener($this->event); $this->assertSame('page=3§ion=2', $this->request->server->get('QUERY_STRING')); $this->assertInstanceOf('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken', $this->tokenStorage->getToken()); @@ -268,7 +271,7 @@ public function testSwitchUserWithReplacedToken() $dispatcher ->expects($this->once()) ->method('dispatch') - ->with(SecurityEvents::SWITCH_USER, + ->with( $this->callback(function (SwitchUserEvent $event) use ($replacedToken, $user) { if ($user !== $event->getTargetUser()) { return false; @@ -276,10 +279,12 @@ public function testSwitchUserWithReplacedToken() $event->setToken($replacedToken); return true; - })); + }), + SecurityEvents::SWITCH_USER + ); $listener = new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager, null, '_switch_user', 'ROLE_ALLOWED_TO_SWITCH', $dispatcher); - $listener->handle($this->event); + $listener($this->event); $this->assertSame($replacedToken, $this->tokenStorage->getToken()); } @@ -292,7 +297,7 @@ public function testSwitchtUserThrowsAuthenticationExceptionIfNoCurrentToken() $this->tokenStorage->setToken(null); $this->request->query->set('_switch_user', 'username'); $listener = new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager); - $listener->handle($this->event); + $listener($this->event); } public function testSwitchUserStateless() @@ -314,7 +319,7 @@ public function testSwitchUserStateless() ->method('checkPostAuth')->with($user); $listener = new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager, null, '_switch_user', 'ROLE_ALLOWED_TO_SWITCH', null, true); - $listener->handle($this->event); + $listener($this->event); $this->assertInstanceOf('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken', $this->tokenStorage->getToken()); $this->assertFalse($this->event->hasResponse()); diff --git a/src/Symfony/Component/Security/Http/Tests/Firewall/UsernamePasswordFormAuthenticationListenerTest.php b/src/Symfony/Component/Security/Http/Tests/Firewall/UsernamePasswordFormAuthenticationListenerTest.php index f1536db6d25a..8d6fa19e01e7 100644 --- a/src/Symfony/Component/Security/Http/Tests/Firewall/UsernamePasswordFormAuthenticationListenerTest.php +++ b/src/Symfony/Component/Security/Http/Tests/Firewall/UsernamePasswordFormAuthenticationListenerTest.php @@ -14,7 +14,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; use Symfony\Component\Security\Core\Security; @@ -66,14 +66,14 @@ public function testHandleWhenUsernameLength($username, $ok) ['require_previous_session' => false] ); - $event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock(); + $event = $this->getMockBuilder(RequestEvent::class)->disableOriginalConstructor()->getMock(); $event ->expects($this->any()) ->method('getRequest') ->will($this->returnValue($request)) ; - $listener->handle($event); + $listener($event); } /** @@ -95,8 +95,8 @@ public function testHandleNonStringUsernameWithArray($postOnly) new DefaultAuthenticationFailureHandler($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $httpUtils), ['require_previous_session' => false, 'post_only' => $postOnly] ); - $event = new GetResponseEvent($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $request, HttpKernelInterface::MASTER_REQUEST); - $listener->handle($event); + $event = new RequestEvent($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $request, HttpKernelInterface::MASTER_REQUEST); + $listener($event); } /** @@ -118,8 +118,8 @@ public function testHandleNonStringUsernameWithInt($postOnly) new DefaultAuthenticationFailureHandler($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $httpUtils), ['require_previous_session' => false, 'post_only' => $postOnly] ); - $event = new GetResponseEvent($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $request, HttpKernelInterface::MASTER_REQUEST); - $listener->handle($event); + $event = new RequestEvent($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $request, HttpKernelInterface::MASTER_REQUEST); + $listener($event); } /** @@ -141,8 +141,8 @@ public function testHandleNonStringUsernameWithObject($postOnly) new DefaultAuthenticationFailureHandler($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $httpUtils), ['require_previous_session' => false, 'post_only' => $postOnly] ); - $event = new GetResponseEvent($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $request, HttpKernelInterface::MASTER_REQUEST); - $listener->handle($event); + $event = new RequestEvent($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $request, HttpKernelInterface::MASTER_REQUEST); + $listener($event); } /** @@ -168,8 +168,8 @@ public function testHandleNonStringUsernameWith__toString($postOnly) new DefaultAuthenticationFailureHandler($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $httpUtils), ['require_previous_session' => false, 'post_only' => $postOnly] ); - $event = new GetResponseEvent($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $request, HttpKernelInterface::MASTER_REQUEST); - $listener->handle($event); + $event = new RequestEvent($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $request, HttpKernelInterface::MASTER_REQUEST); + $listener($event); } public function postOnlyDataProvider() diff --git a/src/Symfony/Component/Security/Http/Tests/Firewall/UsernamePasswordJsonAuthenticationListenerTest.php b/src/Symfony/Component/Security/Http/Tests/Firewall/UsernamePasswordJsonAuthenticationListenerTest.php index ed7acfbe5d7a..07c85d7b40d4 100644 --- a/src/Symfony/Component/Security/Http/Tests/Firewall/UsernamePasswordJsonAuthenticationListenerTest.php +++ b/src/Symfony/Component/Security/Http/Tests/Firewall/UsernamePasswordJsonAuthenticationListenerTest.php @@ -14,7 +14,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; @@ -67,9 +67,9 @@ public function testHandleSuccessIfRequestContentTypeIsJson() { $this->createListener(); $request = new Request([], [], [], [], [], ['HTTP_CONTENT_TYPE' => 'application/json'], '{"username": "dunglas", "password": "foo"}'); - $event = new GetResponseEvent($this->getMockBuilder(KernelInterface::class)->getMock(), $request, KernelInterface::MASTER_REQUEST); + $event = new RequestEvent($this->getMockBuilder(KernelInterface::class)->getMock(), $request, KernelInterface::MASTER_REQUEST); - $this->listener->handle($event); + ($this->listener)($event); $this->assertEquals('ok', $event->getResponse()->getContent()); } @@ -78,9 +78,9 @@ public function testSuccessIfRequestFormatIsJsonLD() $this->createListener(); $request = new Request([], [], [], [], [], [], '{"username": "dunglas", "password": "foo"}'); $request->setRequestFormat('json-ld'); - $event = new GetResponseEvent($this->getMockBuilder(KernelInterface::class)->getMock(), $request, KernelInterface::MASTER_REQUEST); + $event = new RequestEvent($this->getMockBuilder(KernelInterface::class)->getMock(), $request, KernelInterface::MASTER_REQUEST); - $this->listener->handle($event); + ($this->listener)($event); $this->assertEquals('ok', $event->getResponse()->getContent()); } @@ -88,9 +88,9 @@ public function testHandleFailure() { $this->createListener([], false); $request = new Request([], [], [], [], [], ['HTTP_CONTENT_TYPE' => 'application/json'], '{"username": "dunglas", "password": "foo"}'); - $event = new GetResponseEvent($this->getMockBuilder(KernelInterface::class)->getMock(), $request, KernelInterface::MASTER_REQUEST); + $event = new RequestEvent($this->getMockBuilder(KernelInterface::class)->getMock(), $request, KernelInterface::MASTER_REQUEST); - $this->listener->handle($event); + ($this->listener)($event); $this->assertEquals('ko', $event->getResponse()->getContent()); } @@ -98,9 +98,9 @@ public function testUsePath() { $this->createListener(['username_path' => 'user.login', 'password_path' => 'user.pwd']); $request = new Request([], [], [], [], [], ['HTTP_CONTENT_TYPE' => 'application/json'], '{"user": {"login": "dunglas", "pwd": "foo"}}'); - $event = new GetResponseEvent($this->getMockBuilder(KernelInterface::class)->getMock(), $request, KernelInterface::MASTER_REQUEST); + $event = new RequestEvent($this->getMockBuilder(KernelInterface::class)->getMock(), $request, KernelInterface::MASTER_REQUEST); - $this->listener->handle($event); + ($this->listener)($event); $this->assertEquals('ok', $event->getResponse()->getContent()); } @@ -113,9 +113,9 @@ public function testAttemptAuthenticationNoJson() $this->createListener(); $request = new Request(); $request->setRequestFormat('json'); - $event = new GetResponseEvent($this->getMockBuilder(KernelInterface::class)->getMock(), $request, KernelInterface::MASTER_REQUEST); + $event = new RequestEvent($this->getMockBuilder(KernelInterface::class)->getMock(), $request, KernelInterface::MASTER_REQUEST); - $this->listener->handle($event); + ($this->listener)($event); } /** @@ -126,9 +126,9 @@ public function testAttemptAuthenticationNoUsername() { $this->createListener(); $request = new Request([], [], [], [], [], ['HTTP_CONTENT_TYPE' => 'application/json'], '{"usr": "dunglas", "password": "foo"}'); - $event = new GetResponseEvent($this->getMockBuilder(KernelInterface::class)->getMock(), $request, KernelInterface::MASTER_REQUEST); + $event = new RequestEvent($this->getMockBuilder(KernelInterface::class)->getMock(), $request, KernelInterface::MASTER_REQUEST); - $this->listener->handle($event); + ($this->listener)($event); } /** @@ -139,9 +139,9 @@ public function testAttemptAuthenticationNoPassword() { $this->createListener(); $request = new Request([], [], [], [], [], ['HTTP_CONTENT_TYPE' => 'application/json'], '{"username": "dunglas", "pass": "foo"}'); - $event = new GetResponseEvent($this->getMockBuilder(KernelInterface::class)->getMock(), $request, KernelInterface::MASTER_REQUEST); + $event = new RequestEvent($this->getMockBuilder(KernelInterface::class)->getMock(), $request, KernelInterface::MASTER_REQUEST); - $this->listener->handle($event); + ($this->listener)($event); } /** @@ -152,9 +152,9 @@ public function testAttemptAuthenticationUsernameNotAString() { $this->createListener(); $request = new Request([], [], [], [], [], ['HTTP_CONTENT_TYPE' => 'application/json'], '{"username": 1, "password": "foo"}'); - $event = new GetResponseEvent($this->getMockBuilder(KernelInterface::class)->getMock(), $request, KernelInterface::MASTER_REQUEST); + $event = new RequestEvent($this->getMockBuilder(KernelInterface::class)->getMock(), $request, KernelInterface::MASTER_REQUEST); - $this->listener->handle($event); + ($this->listener)($event); } /** @@ -165,9 +165,9 @@ public function testAttemptAuthenticationPasswordNotAString() { $this->createListener(); $request = new Request([], [], [], [], [], ['HTTP_CONTENT_TYPE' => 'application/json'], '{"username": "dunglas", "password": 1}'); - $event = new GetResponseEvent($this->getMockBuilder(KernelInterface::class)->getMock(), $request, KernelInterface::MASTER_REQUEST); + $event = new RequestEvent($this->getMockBuilder(KernelInterface::class)->getMock(), $request, KernelInterface::MASTER_REQUEST); - $this->listener->handle($event); + ($this->listener)($event); } public function testAttemptAuthenticationUsernameTooLong() @@ -175,9 +175,9 @@ public function testAttemptAuthenticationUsernameTooLong() $this->createListener(); $username = str_repeat('x', Security::MAX_USERNAME_LENGTH + 1); $request = new Request([], [], [], [], [], ['HTTP_CONTENT_TYPE' => 'application/json'], sprintf('{"username": "%s", "password": 1}', $username)); - $event = new GetResponseEvent($this->getMockBuilder(KernelInterface::class)->getMock(), $request, KernelInterface::MASTER_REQUEST); + $event = new RequestEvent($this->getMockBuilder(KernelInterface::class)->getMock(), $request, KernelInterface::MASTER_REQUEST); - $this->listener->handle($event); + ($this->listener)($event); $this->assertSame('ko', $event->getResponse()->getContent()); } @@ -185,10 +185,10 @@ public function testDoesNotAttemptAuthenticationIfRequestPathDoesNotMatchCheckPa { $this->createListener(['check_path' => '/'], true, false); $request = new Request([], [], [], [], [], ['HTTP_CONTENT_TYPE' => 'application/json']); - $event = new GetResponseEvent($this->getMockBuilder(KernelInterface::class)->getMock(), $request, KernelInterface::MASTER_REQUEST); + $event = new RequestEvent($this->getMockBuilder(KernelInterface::class)->getMock(), $request, KernelInterface::MASTER_REQUEST); $event->setResponse(new Response('original')); - $this->listener->handle($event); + ($this->listener)($event); $this->assertSame('original', $event->getResponse()->getContent()); } @@ -196,10 +196,10 @@ public function testDoesNotAttemptAuthenticationIfRequestContentTypeIsNotJson() { $this->createListener(); $request = new Request([], [], [], [], [], [], '{"username": "dunglas", "password": "foo"}'); - $event = new GetResponseEvent($this->getMockBuilder(KernelInterface::class)->getMock(), $request, KernelInterface::MASTER_REQUEST); + $event = new RequestEvent($this->getMockBuilder(KernelInterface::class)->getMock(), $request, KernelInterface::MASTER_REQUEST); $event->setResponse(new Response('original')); - $this->listener->handle($event); + ($this->listener)($event); $this->assertSame('original', $event->getResponse()->getContent()); } @@ -207,9 +207,9 @@ public function testAttemptAuthenticationIfRequestPathMatchesCheckPath() { $this->createListener(['check_path' => '/']); $request = new Request([], [], [], [], [], ['HTTP_CONTENT_TYPE' => 'application/json'], '{"username": "dunglas", "password": "foo"}'); - $event = new GetResponseEvent($this->getMockBuilder(KernelInterface::class)->getMock(), $request, KernelInterface::MASTER_REQUEST); + $event = new RequestEvent($this->getMockBuilder(KernelInterface::class)->getMock(), $request, KernelInterface::MASTER_REQUEST); - $this->listener->handle($event); + ($this->listener)($event); $this->assertSame('ok', $event->getResponse()->getContent()); } @@ -218,9 +218,9 @@ public function testNoErrorOnMissingSessionStrategy() $this->createListener(); $request = new Request([], [], [], [], [], ['HTTP_CONTENT_TYPE' => 'application/json'], '{"username": "dunglas", "password": "foo"}'); $this->configurePreviousSession($request); - $event = new GetResponseEvent($this->getMockBuilder(KernelInterface::class)->getMock(), $request, KernelInterface::MASTER_REQUEST); + $event = new RequestEvent($this->getMockBuilder(KernelInterface::class)->getMock(), $request, KernelInterface::MASTER_REQUEST); - $this->listener->handle($event); + ($this->listener)($event); $this->assertEquals('ok', $event->getResponse()->getContent()); } @@ -229,7 +229,7 @@ public function testMigratesViaSessionStrategy() $this->createListener(); $request = new Request([], [], [], [], [], ['HTTP_CONTENT_TYPE' => 'application/json'], '{"username": "dunglas", "password": "foo"}'); $this->configurePreviousSession($request); - $event = new GetResponseEvent($this->getMockBuilder(KernelInterface::class)->getMock(), $request, KernelInterface::MASTER_REQUEST); + $event = new RequestEvent($this->getMockBuilder(KernelInterface::class)->getMock(), $request, KernelInterface::MASTER_REQUEST); $sessionStrategy = $this->getMockBuilder('Symfony\Component\Security\Http\Session\SessionAuthenticationStrategyInterface')->getMock(); $sessionStrategy->expects($this->once()) @@ -237,7 +237,7 @@ public function testMigratesViaSessionStrategy() ->with($request, $this->isInstanceOf(TokenInterface::class)); $this->listener->setSessionAuthenticationStrategy($sessionStrategy); - $this->listener->handle($event); + ($this->listener)($event); $this->assertEquals('ok', $event->getResponse()->getContent()); } diff --git a/src/Symfony/Component/Security/Http/Tests/FirewallMapTest.php b/src/Symfony/Component/Security/Http/Tests/FirewallMapTest.php index 04fe3b4ea305..0fce1979f1c7 100644 --- a/src/Symfony/Component/Security/Http/Tests/FirewallMapTest.php +++ b/src/Symfony/Component/Security/Http/Tests/FirewallMapTest.php @@ -31,7 +31,7 @@ public function testGetListeners() ->will($this->returnValue(false)) ; - $map->add($notMatchingMatcher, [$this->getMockBuilder('Symfony\Component\Security\Http\Firewall\ListenerInterface')->getMock()]); + $map->add($notMatchingMatcher, [function () {}]); $matchingMatcher = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestMatcher')->getMock(); $matchingMatcher @@ -40,7 +40,7 @@ public function testGetListeners() ->with($this->equalTo($request)) ->will($this->returnValue(true)) ; - $theListener = $this->getMockBuilder('Symfony\Component\Security\Http\Firewall\ListenerInterface')->getMock(); + $theListener = function () {}; $theException = $this->getMockBuilder('Symfony\Component\Security\Http\Firewall\ExceptionListener')->disableOriginalConstructor()->getMock(); $map->add($matchingMatcher, [$theListener], $theException); @@ -51,7 +51,7 @@ public function testGetListeners() ->method('matches') ; - $map->add($tooLateMatcher, [$this->getMockBuilder('Symfony\Component\Security\Http\Firewall\ListenerInterface')->getMock()]); + $map->add($tooLateMatcher, [function () {}]); list($listeners, $exception) = $map->getListeners($request); @@ -73,9 +73,9 @@ public function testGetListenersWithAnEntryHavingNoRequestMatcher() ->will($this->returnValue(false)) ; - $map->add($notMatchingMatcher, [$this->getMockBuilder('Symfony\Component\Security\Http\Firewall\ListenerInterface')->getMock()]); + $map->add($notMatchingMatcher, [function () {}]); - $theListener = $this->getMockBuilder('Symfony\Component\Security\Http\Firewall\ListenerInterface')->getMock(); + $theListener = function () {}; $theException = $this->getMockBuilder('Symfony\Component\Security\Http\Firewall\ExceptionListener')->disableOriginalConstructor()->getMock(); $map->add(null, [$theListener], $theException); @@ -86,7 +86,7 @@ public function testGetListenersWithAnEntryHavingNoRequestMatcher() ->method('matches') ; - $map->add($tooLateMatcher, [$this->getMockBuilder('Symfony\Component\Security\Http\Firewall\ListenerInterface')->getMock()]); + $map->add($tooLateMatcher, [function () {}]); list($listeners, $exception) = $map->getListeners($request); @@ -108,7 +108,7 @@ public function testGetListenersWithNoMatchingEntry() ->will($this->returnValue(false)) ; - $map->add($notMatchingMatcher, [$this->getMockBuilder('Symfony\Component\Security\Http\Firewall\ListenerInterface')->getMock()]); + $map->add($notMatchingMatcher, [function () {}]); list($listeners, $exception) = $map->getListeners($request); diff --git a/src/Symfony/Component/Security/Http/Tests/FirewallTest.php b/src/Symfony/Component/Security/Http/Tests/FirewallTest.php index 7a601f6050e5..e730c12448c9 100644 --- a/src/Symfony/Component/Security/Http/Tests/FirewallTest.php +++ b/src/Symfony/Component/Security/Http/Tests/FirewallTest.php @@ -15,7 +15,7 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\Security\Http\Firewall; use Symfony\Component\Security\Http\Firewall\ExceptionListener; @@ -44,7 +44,7 @@ public function testOnKernelRequestRegistersExceptionListener() ->will($this->returnValue([[], $listener, null])) ; - $event = new GetResponseEvent($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $request, HttpKernelInterface::MASTER_REQUEST); + $event = new RequestEvent($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $request, HttpKernelInterface::MASTER_REQUEST); $firewall = new Firewall($map, $dispatcher); $firewall->onKernelRequest($event); @@ -54,17 +54,15 @@ public function testOnKernelRequestStopsWhenThereIsAResponse() { $response = new Response(); - $first = $this->getMockBuilder('Symfony\Component\Security\Http\Firewall\ListenerInterface')->getMock(); - $first - ->expects($this->once()) - ->method('handle') - ; + $called = []; - $second = $this->getMockBuilder('Symfony\Component\Security\Http\Firewall\ListenerInterface')->getMock(); - $second - ->expects($this->never()) - ->method('handle') - ; + $first = function () use (&$called) { + $called[] = 1; + }; + + $second = function () use (&$called) { + $called[] = 2; + }; $map = $this->getMockBuilder('Symfony\Component\Security\Http\FirewallMapInterface')->getMock(); $map @@ -73,7 +71,7 @@ public function testOnKernelRequestStopsWhenThereIsAResponse() ->will($this->returnValue([[$first, $second], null, null])) ; - $event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent') + $event = $this->getMockBuilder(RequestEvent::class) ->setMethods(['hasResponse']) ->setConstructorArgs([ $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), @@ -90,6 +88,8 @@ public function testOnKernelRequestStopsWhenThereIsAResponse() $firewall = new Firewall($map, $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock()); $firewall->onKernelRequest($event); + + $this->assertSame([1], $called); } public function testOnKernelRequestWithSubRequest() @@ -100,7 +100,7 @@ public function testOnKernelRequestWithSubRequest() ->method('getListeners') ; - $event = new GetResponseEvent( + $event = new RequestEvent( $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')->getMock(), HttpKernelInterface::SUB_REQUEST @@ -138,6 +138,6 @@ public function testMissingLogoutListener() ; $firewall = new Firewall($map, $dispatcher); - $firewall->onKernelRequest(new GetResponseEvent($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $request, HttpKernelInterface::MASTER_REQUEST)); + $firewall->onKernelRequest(new RequestEvent($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $request, HttpKernelInterface::MASTER_REQUEST)); } } diff --git a/src/Symfony/Component/Security/Http/Tests/RememberMe/ResponseListenerTest.php b/src/Symfony/Component/Security/Http/Tests/RememberMe/ResponseListenerTest.php index e72bf2631361..20f6714a3315 100644 --- a/src/Symfony/Component/Security/Http/Tests/RememberMe/ResponseListenerTest.php +++ b/src/Symfony/Component/Security/Http/Tests/RememberMe/ResponseListenerTest.php @@ -15,6 +15,7 @@ use Symfony\Component\HttpFoundation\Cookie; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\Security\Http\RememberMe\RememberMeServicesInterface; @@ -91,7 +92,7 @@ private function getResponse() private function getEvent($request, $response, $type = HttpKernelInterface::MASTER_REQUEST) { - $event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\FilterResponseEvent') + $event = $this->getMockBuilder(ResponseEvent::class) ->disableOriginalConstructor() ->getMock(); diff --git a/src/Symfony/Component/Security/Http/composer.json b/src/Symfony/Component/Security/Http/composer.json index 7bfac0fdcf85..402951b30840 100644 --- a/src/Symfony/Component/Security/Http/composer.json +++ b/src/Symfony/Component/Security/Http/composer.json @@ -17,10 +17,9 @@ ], "require": { "php": "^7.1.3", - "symfony/security-core": "~4.3", - "symfony/event-dispatcher": "~3.4|~4.0", + "symfony/security-core": "^4.3", "symfony/http-foundation": "~3.4|~4.0", - "symfony/http-kernel": "~3.4|~4.0", + "symfony/http-kernel": "^4.3", "symfony/property-access": "~3.4|~4.0" }, "require-dev": { diff --git a/src/Symfony/Component/Security/composer.json b/src/Symfony/Component/Security/composer.json index 80e62d923a56..fddc5165910f 100644 --- a/src/Symfony/Component/Security/composer.json +++ b/src/Symfony/Component/Security/composer.json @@ -18,9 +18,8 @@ "require": { "php": "^7.1.3", "symfony/contracts": "^1.0", - "symfony/event-dispatcher": "~3.4|~4.0", "symfony/http-foundation": "~3.4|~4.0", - "symfony/http-kernel": "~3.4|~4.0", + "symfony/http-kernel": "^4.3", "symfony/property-access": "~3.4|~4.0" }, "replace": { diff --git a/src/Symfony/Component/WebLink/EventListener/AddLinkHeaderListener.php b/src/Symfony/Component/WebLink/EventListener/AddLinkHeaderListener.php index 3d04f9a13fb2..d743f4664c30 100644 --- a/src/Symfony/Component/WebLink/EventListener/AddLinkHeaderListener.php +++ b/src/Symfony/Component/WebLink/EventListener/AddLinkHeaderListener.php @@ -13,7 +13,7 @@ use Psr\Link\LinkProviderInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; +use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\WebLink\HttpHeaderSerializer; @@ -33,7 +33,7 @@ public function __construct() $this->serializer = new HttpHeaderSerializer(); } - public function onKernelResponse(FilterResponseEvent $event) + public function onKernelResponse(ResponseEvent $event) { if (!$event->isMasterRequest()) { return; diff --git a/src/Symfony/Component/WebLink/Tests/EventListener/AddLinkHeaderListenerTest.php b/src/Symfony/Component/WebLink/Tests/EventListener/AddLinkHeaderListenerTest.php index 5a714715789f..f3aae1eb3192 100644 --- a/src/Symfony/Component/WebLink/Tests/EventListener/AddLinkHeaderListenerTest.php +++ b/src/Symfony/Component/WebLink/Tests/EventListener/AddLinkHeaderListenerTest.php @@ -17,7 +17,7 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; +use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\WebLink\EventListener\AddLinkHeaderListener; @@ -33,7 +33,7 @@ public function testOnKernelResponse() $subscriber = new AddLinkHeaderListener(); - $event = $this->getMockBuilder(FilterResponseEvent::class)->disableOriginalConstructor()->getMock(); + $event = $this->getMockBuilder(ResponseEvent::class)->disableOriginalConstructor()->getMock(); $event->method('isMasterRequest')->willReturn(true); $event->method('getRequest')->willReturn($request); $event->method('getResponse')->willReturn($response); diff --git a/src/Symfony/Component/WebLink/composer.json b/src/Symfony/Component/WebLink/composer.json index 57f96c1a6c2f..14a519d7d0cf 100644 --- a/src/Symfony/Component/WebLink/composer.json +++ b/src/Symfony/Component/WebLink/composer.json @@ -24,9 +24,11 @@ "symfony/http-kernel": "" }, "require-dev": { - "symfony/event-dispatcher": "~3.4|~4.0", "symfony/http-foundation": "~3.4|~4.0", - "symfony/http-kernel": "~3.4|~4.0" + "symfony/http-kernel": "^4.3" + }, + "conflict": { + "symfony/http-kernel": "<4.3" }, "autoload": { "psr-4": { "Symfony\\Component\\WebLink\\": "" }, diff --git a/src/Symfony/Component/Workflow/CHANGELOG.md b/src/Symfony/Component/Workflow/CHANGELOG.md index 7e54a59a61e8..41421dfa6dfb 100644 --- a/src/Symfony/Component/Workflow/CHANGELOG.md +++ b/src/Symfony/Component/Workflow/CHANGELOG.md @@ -6,6 +6,13 @@ CHANGELOG * Trigger `entered` event for subject entering in the Workflow for the first time * Added a context to `Workflow::apply()`. The `MethodMarkingStore` could be used to leverage this feature. + * Dispatch `GuardEvent` on `workflow.guard` + * Dispatch `LeaveEvent` on `workflow.leave` + * Dispatch `TransitionEvent` on `workflow.transition` + * Dispatch `EnterEvent` on `workflow.enter` + * Dispatch `EnteredEvent` on `workflow.entered` + * Dispatch `CompletedEvent` on `workflow.completed` + * Dispatch `AnnounceEvent` on `workflow.announce` 4.1.0 ----- diff --git a/src/Symfony/Component/Workflow/Event/AnnounceEvent.php b/src/Symfony/Component/Workflow/Event/AnnounceEvent.php new file mode 100644 index 000000000000..aaef62a74717 --- /dev/null +++ b/src/Symfony/Component/Workflow/Event/AnnounceEvent.php @@ -0,0 +1,16 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Workflow\Event; + +class AnnounceEvent extends Event +{ +} diff --git a/src/Symfony/Component/Workflow/Event/CompletedEvent.php b/src/Symfony/Component/Workflow/Event/CompletedEvent.php new file mode 100644 index 000000000000..2250d9bf05d2 --- /dev/null +++ b/src/Symfony/Component/Workflow/Event/CompletedEvent.php @@ -0,0 +1,16 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Workflow\Event; + +class CompletedEvent extends Event +{ +} diff --git a/src/Symfony/Component/Workflow/Event/EnterEvent.php b/src/Symfony/Component/Workflow/Event/EnterEvent.php new file mode 100644 index 000000000000..fde615c3b04a --- /dev/null +++ b/src/Symfony/Component/Workflow/Event/EnterEvent.php @@ -0,0 +1,16 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Workflow\Event; + +class EnterEvent extends Event +{ +} diff --git a/src/Symfony/Component/Workflow/Event/EnteredEvent.php b/src/Symfony/Component/Workflow/Event/EnteredEvent.php new file mode 100644 index 000000000000..cd766a3fced9 --- /dev/null +++ b/src/Symfony/Component/Workflow/Event/EnteredEvent.php @@ -0,0 +1,16 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Workflow\Event; + +class EnteredEvent extends Event +{ +} diff --git a/src/Symfony/Component/Workflow/Event/LeaveEvent.php b/src/Symfony/Component/Workflow/Event/LeaveEvent.php new file mode 100644 index 000000000000..494bb6c2c9ff --- /dev/null +++ b/src/Symfony/Component/Workflow/Event/LeaveEvent.php @@ -0,0 +1,16 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Workflow\Event; + +class LeaveEvent extends Event +{ +} diff --git a/src/Symfony/Component/Workflow/Event/TransitionEvent.php b/src/Symfony/Component/Workflow/Event/TransitionEvent.php new file mode 100644 index 000000000000..d45583fc1ebb --- /dev/null +++ b/src/Symfony/Component/Workflow/Event/TransitionEvent.php @@ -0,0 +1,16 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Workflow\Event; + +class TransitionEvent extends Event +{ +} diff --git a/src/Symfony/Component/Workflow/Tests/WorkflowTest.php b/src/Symfony/Component/Workflow/Tests/WorkflowTest.php index c0b9da72d17b..62150d2cb732 100644 --- a/src/Symfony/Component/Workflow/Tests/WorkflowTest.php +++ b/src/Symfony/Component/Workflow/Tests/WorkflowTest.php @@ -548,7 +548,7 @@ class EventDispatcherMock implements \Symfony\Component\EventDispatcher\EventDis { public $dispatchedEvents = []; - public function dispatch($eventName, \Symfony\Component\EventDispatcher\Event $event = null) + public function dispatch($event, string $eventName = null) { $this->dispatchedEvents[] = $eventName; } diff --git a/src/Symfony/Component/Workflow/Workflow.php b/src/Symfony/Component/Workflow/Workflow.php index 7269defa2e11..c0866c663796 100644 --- a/src/Symfony/Component/Workflow/Workflow.php +++ b/src/Symfony/Component/Workflow/Workflow.php @@ -12,8 +12,15 @@ namespace Symfony\Component\Workflow; use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy; use Symfony\Component\Workflow\Event\Event; use Symfony\Component\Workflow\Event\GuardEvent; +use Symfony\Component\Workflow\Event\AnnounceEvent; +use Symfony\Component\Workflow\Event\EnterEvent; +use Symfony\Component\Workflow\Event\EnteredEvent; +use Symfony\Component\Workflow\Event\LeaveEvent; +use Symfony\Component\Workflow\Event\CompletedEvent; +use Symfony\Component\Workflow\Event\TransitionEvent; use Symfony\Component\Workflow\Exception\LogicException; use Symfony\Component\Workflow\Exception\NotEnabledTransitionException; use Symfony\Component\Workflow\Exception\UndefinedTransitionException; @@ -37,7 +44,7 @@ public function __construct(Definition $definition, MarkingStoreInterface $marki { $this->definition = $definition; $this->markingStore = $markingStore ?: new MultipleStateMarkingStore(); - $this->dispatcher = $dispatcher; + $this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher); $this->name = $name; } @@ -273,9 +280,9 @@ private function guardTransition($subject, Marking $marking, Transition $transit $event = new GuardEvent($subject, $marking, $transition, $this); - $this->dispatcher->dispatch('workflow.guard', $event); - $this->dispatcher->dispatch(sprintf('workflow.%s.guard', $this->name), $event); - $this->dispatcher->dispatch(sprintf('workflow.%s.guard.%s', $this->name, $transition->getName()), $event); + $this->dispatcher->dispatch($event, WorkflowEvents::GUARD); + $this->dispatcher->dispatch($event, sprintf('workflow.%s.guard', $this->name)); + $this->dispatcher->dispatch($event, sprintf('workflow.%s.guard.%s', $this->name, $transition->getName())); return $event; } @@ -285,13 +292,13 @@ private function leave($subject, Transition $transition, Marking $marking): void $places = $transition->getFroms(); if (null !== $this->dispatcher) { - $event = new Event($subject, $marking, $transition, $this); + $event = new LeaveEvent($subject, $marking, $transition, $this); - $this->dispatcher->dispatch('workflow.leave', $event); - $this->dispatcher->dispatch(sprintf('workflow.%s.leave', $this->name), $event); + $this->dispatcher->dispatch($event, WorkflowEvents::LEAVE); + $this->dispatcher->dispatch($event, sprintf('workflow.%s.leave', $this->name)); foreach ($places as $place) { - $this->dispatcher->dispatch(sprintf('workflow.%s.leave.%s', $this->name, $place), $event); + $this->dispatcher->dispatch($event, sprintf('workflow.%s.leave.%s', $this->name, $place)); } } @@ -306,11 +313,11 @@ private function transition($subject, Transition $transition, Marking $marking): return; } - $event = new Event($subject, $marking, $transition, $this); + $event = new TransitionEvent($subject, $marking, $transition, $this); - $this->dispatcher->dispatch('workflow.transition', $event); - $this->dispatcher->dispatch(sprintf('workflow.%s.transition', $this->name), $event); - $this->dispatcher->dispatch(sprintf('workflow.%s.transition.%s', $this->name, $transition->getName()), $event); + $this->dispatcher->dispatch($event, WorkflowEvents::TRANSITION); + $this->dispatcher->dispatch($event, sprintf('workflow.%s.transition', $this->name)); + $this->dispatcher->dispatch($event, sprintf('workflow.%s.transition.%s', $this->name, $transition->getName())); } private function enter($subject, Transition $transition, Marking $marking): void @@ -318,13 +325,13 @@ private function enter($subject, Transition $transition, Marking $marking): void $places = $transition->getTos(); if (null !== $this->dispatcher) { - $event = new Event($subject, $marking, $transition, $this); + $event = new EnterEvent($subject, $marking, $transition, $this); - $this->dispatcher->dispatch('workflow.enter', $event); - $this->dispatcher->dispatch(sprintf('workflow.%s.enter', $this->name), $event); + $this->dispatcher->dispatch($event, WorkflowEvents::ENTER); + $this->dispatcher->dispatch($event, sprintf('workflow.%s.enter', $this->name)); foreach ($places as $place) { - $this->dispatcher->dispatch(sprintf('workflow.%s.enter.%s', $this->name, $place), $event); + $this->dispatcher->dispatch($event, sprintf('workflow.%s.enter.%s', $this->name, $place)); } } @@ -339,14 +346,14 @@ private function entered($subject, Transition $transition = null, Marking $marki return; } - $event = new Event($subject, $marking, $transition, $this); + $event = new EnteredEvent($subject, $marking, $transition, $this); - $this->dispatcher->dispatch('workflow.entered', $event); - $this->dispatcher->dispatch(sprintf('workflow.%s.entered', $this->name), $event); + $this->dispatcher->dispatch($event, WorkflowEvents::ENTERED); + $this->dispatcher->dispatch($event, sprintf('workflow.%s.entered', $this->name)); if ($transition) { foreach ($transition->getTos() as $place) { - $this->dispatcher->dispatch(sprintf('workflow.%s.entered.%s', $this->name, $place), $event); + $this->dispatcher->dispatch($event, sprintf('workflow.%s.entered.%s', $this->name, $place)); } } } @@ -357,11 +364,11 @@ private function completed($subject, Transition $transition, Marking $marking): return; } - $event = new Event($subject, $marking, $transition, $this); + $event = new CompletedEvent($subject, $marking, $transition, $this); - $this->dispatcher->dispatch('workflow.completed', $event); - $this->dispatcher->dispatch(sprintf('workflow.%s.completed', $this->name), $event); - $this->dispatcher->dispatch(sprintf('workflow.%s.completed.%s', $this->name, $transition->getName()), $event); + $this->dispatcher->dispatch($event, WorkflowEvents::COMPLETED); + $this->dispatcher->dispatch($event, sprintf('workflow.%s.completed', $this->name)); + $this->dispatcher->dispatch($event, sprintf('workflow.%s.completed.%s', $this->name, $transition->getName())); } private function announce($subject, Transition $initialTransition, Marking $marking): void @@ -370,13 +377,13 @@ private function announce($subject, Transition $initialTransition, Marking $mark return; } - $event = new Event($subject, $marking, $initialTransition, $this); + $event = new AnnounceEvent($subject, $marking, $initialTransition, $this); - $this->dispatcher->dispatch('workflow.announce', $event); - $this->dispatcher->dispatch(sprintf('workflow.%s.announce', $this->name), $event); + $this->dispatcher->dispatch($event, WorkflowEvents::ANNOUNCE); + $this->dispatcher->dispatch($event, sprintf('workflow.%s.announce', $this->name)); foreach ($this->getEnabledTransitions($subject) as $transition) { - $this->dispatcher->dispatch(sprintf('workflow.%s.announce.%s', $this->name, $transition->getName()), $event); + $this->dispatcher->dispatch($event, sprintf('workflow.%s.announce.%s', $this->name, $transition->getName())); } } } diff --git a/src/Symfony/Component/Workflow/WorkflowEvents.php b/src/Symfony/Component/Workflow/WorkflowEvents.php new file mode 100644 index 000000000000..dba91f7d2a64 --- /dev/null +++ b/src/Symfony/Component/Workflow/WorkflowEvents.php @@ -0,0 +1,58 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Workflow; + +/** + * To learn more about how form events work check the documentation + * entry at {@link https://symfony.com/doc/current/workflow/usage.html#using-events}. + */ +final class WorkflowEvents +{ + /** + * @Event("Symfony\Component\Workflow\Event\GuardEvent") + */ + const GUARD = 'workflow.guard'; + + /** + * @Event("Symfony\Component\Workflow\Event\AnnounceEvent") + */ + const ANNOUNCE = 'workflow.announce'; + + /** + * @Event("Symfony\Component\Workflow\Event\CompletedEvent") + */ + const COMPLETED = 'workflow.completed'; + + /** + * @Event("Symfony\Component\Workflow\Event\EnterEvent") + */ + const ENTER = 'workflow.enter'; + + /** + * @Event("Symfony\Component\Workflow\Event\EnteredEvent") + */ + const ENTERED = 'workflow.entered'; + + /** + * @Event("Symfony\Component\Workflow\Event\EnteredEvent") + */ + const LEAVE = 'workflow.leave'; + + /** + * @Event("Symfony\Component\Workflow\Event\TransitionEvent") + */ + const TRANSITION = 'workflow.transition'; + + private function __construct() + { + } +} diff --git a/src/Symfony/Component/Workflow/composer.json b/src/Symfony/Component/Workflow/composer.json index 40dc178e16fe..42a7e0cab7e1 100644 --- a/src/Symfony/Component/Workflow/composer.json +++ b/src/Symfony/Component/Workflow/composer.json @@ -26,11 +26,14 @@ "require-dev": { "psr/log": "~1.0", "symfony/dependency-injection": "~3.4|~4.0", - "symfony/event-dispatcher": "~3.4|~4.0", + "symfony/event-dispatcher": "^4.3", "symfony/expression-language": "~3.4|~4.0", "symfony/security-core": "~3.4|~4.0", "symfony/validator": "~3.4|~4.0" }, + "conflict": { + "symfony/event-dispatcher": "<4.3" + }, "autoload": { "psr-4": { "Symfony\\Component\\Workflow\\": "" } },