From 3c3db2f14a8d8dc96581560f8a24ce2f866eabda Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 25 Mar 2019 17:04:58 +0100 Subject: [PATCH] [Contracts][EventDispatcher] add EventDispatcherInterface to symfony/contracts and use it where possible --- .../Resources/config/services.xml | 1 + .../AutowiringTypes/AutowiredServices.php | 2 +- .../Bundle/FrameworkBundle/composer.json | 2 +- .../EventListener/FirewallListener.php | 2 + .../SecurityDataCollectorTest.php | 2 +- src/Symfony/Component/Console/Application.php | 3 + src/Symfony/Component/Console/composer.json | 2 +- .../Compiler/AutowirePass.php | 11 +--- .../Exception/AutowiringFailedException.php | 4 ++ .../Debug/TraceableEventDispatcher.php | 33 ++++++++--- .../EventDispatcher/Debug/WrappedListener.php | 5 +- .../EventDispatcher/EventDispatcher.php | 18 +++++- .../EventDispatcherInterface.php | 15 +---- .../LegacyEventDispatcherProxy.php | 8 ++- .../Component/EventDispatcher/composer.json | 6 +- .../Component/Form/Test/TypeTestCase.php | 6 +- .../DataCollector/EventDataCollector.php | 2 +- .../Debug/TraceableEventDispatcher.php | 4 +- .../EventListener/ExceptionListener.php | 4 ++ .../Fragment/InlineFragmentRenderer.php | 2 +- .../Component/HttpKernel/HttpKernel.php | 2 +- .../Fragment/InlineFragmentRendererTest.php | 5 +- .../Component/HttpKernel/composer.json | 2 +- .../Command/ConsumeMessagesCommand.php | 2 +- .../Event/AbstractWorkerMessageEvent.php | 3 +- .../Event/SendMessageToTransportsEvent.php | 3 +- .../Middleware/SendMessageMiddleware.php | 2 +- .../Middleware/SendMessageMiddlewareTest.php | 2 +- .../Component/Messenger/Tests/WorkerTest.php | 2 +- src/Symfony/Component/Messenger/Worker.php | 5 +- .../AuthenticationProviderManager.php | 3 + .../Authorization/Voter/TraceableVoter.php | 7 ++- .../Voter/TraceableVoterTest.php | 4 +- .../Component/Security/Core/composer.json | 2 +- .../Guard/GuardAuthenticatorHandler.php | 2 +- .../Tests/GuardAuthenticatorHandlerTest.php | 12 ++-- .../Component/Security/Http/Firewall.php | 2 + .../AbstractAuthenticationListener.php | 2 +- .../AbstractPreAuthenticatedListener.php | 2 +- .../Http/Firewall/ExceptionListener.php | 2 +- .../Http/Firewall/RememberMeListener.php | 2 +- .../RemoteUserAuthenticationListener.php | 2 +- .../Http/Firewall/SwitchUserListener.php | 2 +- ...namePasswordFormAuthenticationListener.php | 2 +- ...namePasswordJsonAuthenticationListener.php | 2 +- .../Firewall/X509AuthenticationListener.php | 2 +- .../Tests/Firewall/RememberMeListenerTest.php | 3 +- .../Tests/Firewall/SwitchUserListenerTest.php | 7 ++- src/Symfony/Component/Security/composer.json | 2 +- .../Component/Workflow/StateMachine.php | 2 +- .../Component/Workflow/Tests/RegistryTest.php | 2 +- src/Symfony/Component/Workflow/Workflow.php | 2 +- src/Symfony/Contracts/CHANGELOG.md | 1 + .../EventDispatcherInterface.php | 58 +++++++++++++++++++ src/Symfony/Contracts/composer.json | 1 + 55 files changed, 196 insertions(+), 92 deletions(-) create mode 100644 src/Symfony/Contracts/EventDispatcher/EventDispatcherInterface.php diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml index b4829942f2de..7f4f5890fa89 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml @@ -49,6 +49,7 @@ + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/AutowiringTypes/AutowiredServices.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/AutowiringTypes/AutowiredServices.php index d9a7b59d46ba..4743460e6ee5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/AutowiringTypes/AutowiredServices.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/AutowiringTypes/AutowiredServices.php @@ -13,7 +13,7 @@ use Doctrine\Common\Annotations\Reader; use Psr\Cache\CacheItemPoolInterface; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; class AutowiredServices { diff --git a/src/Symfony/Bundle/FrameworkBundle/composer.json b/src/Symfony/Bundle/FrameworkBundle/composer.json index 57a7e256234c..853711aca32c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/composer.json +++ b/src/Symfony/Bundle/FrameworkBundle/composer.json @@ -20,7 +20,7 @@ "ext-xml": "*", "symfony/cache": "~4.3", "symfony/config": "~4.2", - "symfony/contracts": "^1.0.2", + "symfony/contracts": "^1.1", "symfony/dependency-injection": "^4.3", "symfony/http-foundation": "^4.3", "symfony/http-kernel": "^4.3", diff --git a/src/Symfony/Bundle/SecurityBundle/EventListener/FirewallListener.php b/src/Symfony/Bundle/SecurityBundle/EventListener/FirewallListener.php index 1a3712c7507c..3dca451d9ab1 100644 --- a/src/Symfony/Bundle/SecurityBundle/EventListener/FirewallListener.php +++ b/src/Symfony/Bundle/SecurityBundle/EventListener/FirewallListener.php @@ -30,6 +30,8 @@ class FirewallListener extends Firewall public function __construct(FirewallMapInterface $map, EventDispatcherInterface $dispatcher, LogoutUrlGenerator $logoutUrlGenerator) { + // the type-hint will be updated to the "EventDispatcherInterface" from symfony/contracts in 5.0 + $this->map = $map; $this->logoutUrlGenerator = $logoutUrlGenerator; diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/DataCollector/SecurityDataCollectorTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/DataCollector/SecurityDataCollectorTest.php index 209248cc85bd..7e583facf7b0 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/DataCollector/SecurityDataCollectorTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/DataCollector/SecurityDataCollectorTest.php @@ -17,7 +17,6 @@ use Symfony\Bundle\SecurityBundle\Security\FirewallConfig; use Symfony\Bundle\SecurityBundle\Security\FirewallMap; use Symfony\Component\EventDispatcher\EventDispatcher; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Event\RequestEvent; @@ -34,6 +33,7 @@ use Symfony\Component\Security\Core\Role\SwitchUserRole; use Symfony\Component\Security\Http\FirewallMapInterface; use Symfony\Component\Security\Http\Logout\LogoutUrlGenerator; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; class SecurityDataCollectorTest extends TestCase { diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index fcb334a8a175..667be07b5afd 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -91,6 +91,9 @@ public function __construct(string $name = 'UNKNOWN', string $version = 'UNKNOWN $this->defaultCommand = 'list'; } + /** + * @final since Symfony 4.3, the type-hint will be updated to the interface from symfony/contracts in 5.0 + */ public function setDispatcher(EventDispatcherInterface $dispatcher) { $this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher); diff --git a/src/Symfony/Component/Console/composer.json b/src/Symfony/Component/Console/composer.json index 8eff5b7458e4..b8033b2272fe 100644 --- a/src/Symfony/Component/Console/composer.json +++ b/src/Symfony/Component/Console/composer.json @@ -17,7 +17,7 @@ ], "require": { "php": "^7.1.3", - "symfony/contracts": "^1.0", + "symfony/contracts": "^1.1", "symfony/polyfill-mbstring": "~1.0", "symfony/polyfill-php73": "^1.8" }, diff --git a/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php b/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php index 6a9c9237682f..5aa6680e7e01 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php @@ -226,16 +226,7 @@ private function autowireMethod(\ReflectionFunctionAbstract $reflectionMethod, a if ($parameter->isDefaultValueAvailable()) { $value = $parameter->getDefaultValue(); } elseif (!$parameter->allowsNull()) { - if (\function_exists('xdebug_disable')) { - xdebug_disable(); - } - try { - throw new AutowiringFailedException($this->currentId, $failureMessage); - } finally { - if (\function_exists('xdebug_enable')) { - xdebug_enable(); - } - } + throw new AutowiringFailedException($this->currentId, $failureMessage); } } diff --git a/src/Symfony/Component/DependencyInjection/Exception/AutowiringFailedException.php b/src/Symfony/Component/DependencyInjection/Exception/AutowiringFailedException.php index be2bd26dcad1..99a5b17ccd04 100644 --- a/src/Symfony/Component/DependencyInjection/Exception/AutowiringFailedException.php +++ b/src/Symfony/Component/DependencyInjection/Exception/AutowiringFailedException.php @@ -23,6 +23,10 @@ public function __construct(string $serviceId, $message = '', int $code = 0, \Ex { $this->serviceId = $serviceId; + if ($message instanceof \Closure && \function_exists('xdebug_is_enabled') && xdebug_is_enabled()) { + $message = $message(); + } + if (!$message instanceof \Closure) { parent::__construct($message, $code, $previous); diff --git a/src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php b/src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php index 0a0dde4230d0..f40dfa4bef98 100644 --- a/src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php +++ b/src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php @@ -11,6 +11,7 @@ namespace Symfony\Component\EventDispatcher\Debug; +use Psr\EventDispatcher\StoppableEventInterface; use Psr\Log\LoggerInterface; use Symfony\Component\EventDispatcher\Event; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -133,7 +134,7 @@ public function dispatch($event/*, string $eventName = null*/) $eventName = 1 < \func_num_args() ? \func_get_arg(1) : null; - if ($event instanceof Event) { + if (\is_object($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); @@ -146,13 +147,13 @@ public function dispatch($event/*, string $eventName = null*/) } } - if (null !== $this->logger && $event->isPropagationStopped()) { + if (null !== $this->logger && ($event instanceof Event || $event instanceof StoppableEventInterface) && $event->isPropagationStopped()) { $this->logger->debug(sprintf('The "%s" event is already stopped. No listeners have been called.', $eventName)); } $this->preProcess($eventName); try { - $this->preDispatch($eventName, $event); + $this->beforeDispatch($eventName, $event); try { $e = $this->stopwatch->start($eventName, 'section'); try { @@ -163,7 +164,7 @@ public function dispatch($event/*, string $eventName = null*/) } } } finally { - $this->postDispatch($eventName, $event); + $this->afterDispatch($eventName, $event); } } finally { $this->postProcess($eventName); @@ -262,18 +263,32 @@ public function __call($method, $arguments) /** * Called before dispatching the event. * - * @param string $eventName The event name - * @param Event $event The event + * @param object $event */ - protected function preDispatch($eventName, Event $event) + protected function beforeDispatch(string $eventName, $event) { + $this->preDispatch($eventName, $event); } /** * Called after dispatching the event. * - * @param string $eventName The event name - * @param Event $event The event + * @param object $event + */ + protected function afterDispatch(string $eventName, $event) + { + $this->postDispatch($eventName, $event); + } + + /** + * @deprecated since Symfony 4.3, will be removed in 5.0, use beforeDispatch instead + */ + protected function preDispatch($eventName, Event $event) + { + } + + /** + * @deprecated since Symfony 4.3, will be removed in 5.0, use afterDispatch instead */ protected function postDispatch($eventName, Event $event) { diff --git a/src/Symfony/Component/EventDispatcher/Debug/WrappedListener.php b/src/Symfony/Component/EventDispatcher/Debug/WrappedListener.php index 8aa3f80a7671..5342fc88a1a5 100644 --- a/src/Symfony/Component/EventDispatcher/Debug/WrappedListener.php +++ b/src/Symfony/Component/EventDispatcher/Debug/WrappedListener.php @@ -11,6 +11,7 @@ namespace Symfony\Component\EventDispatcher\Debug; +use Psr\EventDispatcher\StoppableEventInterface; use Symfony\Component\EventDispatcher\Event; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Stopwatch\Stopwatch; @@ -18,6 +19,8 @@ /** * @author Fabien Potencier + * + * @final since Symfony 4.3: the "Event" type-hint on __invoke() will be replaced by "object" in 5.0 */ class WrappedListener { @@ -120,7 +123,7 @@ public function __invoke(Event $event, $eventName, EventDispatcherInterface $dis $e->stop(); } - if ($event->isPropagationStopped()) { + if (($event instanceof Event || $event instanceof StoppableEventInterface) && $event->isPropagationStopped()) { $this->stoppedPropagation = true; } } diff --git a/src/Symfony/Component/EventDispatcher/EventDispatcher.php b/src/Symfony/Component/EventDispatcher/EventDispatcher.php index 80b3105e6a66..d6a78d1871cb 100644 --- a/src/Symfony/Component/EventDispatcher/EventDispatcher.php +++ b/src/Symfony/Component/EventDispatcher/EventDispatcher.php @@ -11,6 +11,8 @@ namespace Symfony\Component\EventDispatcher; +use Psr\EventDispatcher\StoppableEventInterface; + /** * The EventDispatcherInterface is the central point of Symfony's event listener system. * @@ -48,7 +50,7 @@ public function dispatch($event/*, string $eventName = null*/) { $eventName = 1 < \func_num_args() ? \func_get_arg(1) : null; - if ($event instanceof Event) { + if (\is_object($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); @@ -223,12 +225,22 @@ public function removeSubscriber(EventSubscriberInterface $subscriber) * * @param callable[] $listeners The event listeners * @param string $eventName The name of the event to dispatch - * @param Event $event The event object to pass to the event handlers/listeners + * @param object $event The event object to pass to the event handlers/listeners + */ + protected function callListeners(iterable $listeners, string $eventName, $event) + { + $this->doDispatch($listeners, $eventName, $event); + } + + /** + * @deprecated since Symfony 4.3, use callListeners() instead */ protected function doDispatch($listeners, $eventName, Event $event) { + $stoppable = $event instanceof Event || $event instanceof StoppableEventInterface; + foreach ($listeners as $listener) { - if ($event->isPropagationStopped()) { + if ($stoppable && $event->isPropagationStopped()) { break; } $listener($event, $eventName, $this); diff --git a/src/Symfony/Component/EventDispatcher/EventDispatcherInterface.php b/src/Symfony/Component/EventDispatcher/EventDispatcherInterface.php index 672f5044d720..ceaa62aeb047 100644 --- a/src/Symfony/Component/EventDispatcher/EventDispatcherInterface.php +++ b/src/Symfony/Component/EventDispatcher/EventDispatcherInterface.php @@ -11,6 +11,8 @@ namespace Symfony\Component\EventDispatcher; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface as ContractsEventDispatcherInterface; + /** * The EventDispatcherInterface is the central point of Symfony's event listener system. * Listeners are registered on the manager and events are dispatched through the @@ -18,19 +20,8 @@ * * @author Bernhard Schussek */ -interface EventDispatcherInterface +interface EventDispatcherInterface extends ContractsEventDispatcherInterface { - /** - * Dispatches an event to all registered listeners. - * - * @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($event/*, string $eventName = null*/); - /** * Adds an event listener that listens on the specified events. * diff --git a/src/Symfony/Component/EventDispatcher/LegacyEventDispatcherProxy.php b/src/Symfony/Component/EventDispatcher/LegacyEventDispatcherProxy.php index 8539376206bc..54de7a44386d 100644 --- a/src/Symfony/Component/EventDispatcher/LegacyEventDispatcherProxy.php +++ b/src/Symfony/Component/EventDispatcher/LegacyEventDispatcherProxy.php @@ -11,6 +11,9 @@ namespace Symfony\Component\EventDispatcher; +use Psr\EventDispatcher\StoppableEventInterface; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; + /** * An helper class to provide BC/FC with the legacy signature of EventDispatcherInterface::dispatch(). * @@ -51,7 +54,7 @@ public function dispatch($event/*, string $eventName = null*/) { $eventName = 1 < \func_num_args() ? \func_get_arg(1) : null; - if ($event instanceof Event) { + if (\is_object($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); @@ -65,9 +68,10 @@ public function dispatch($event/*, string $eventName = null*/) } $listeners = $this->getListeners($eventName); + $stoppable = $event instanceof Event || $event instanceof StoppableEventInterface; foreach ($listeners as $listener) { - if ($event->isPropagationStopped()) { + if ($stoppable && $event->isPropagationStopped()) { break; } $listener($event, $eventName, $this); diff --git a/src/Symfony/Component/EventDispatcher/composer.json b/src/Symfony/Component/EventDispatcher/composer.json index 6cdc762bc301..163149f412be 100644 --- a/src/Symfony/Component/EventDispatcher/composer.json +++ b/src/Symfony/Component/EventDispatcher/composer.json @@ -17,7 +17,7 @@ ], "require": { "php": "^7.1.3", - "symfony/contracts": "^1.0" + "symfony/contracts": "^1.1" }, "require-dev": { "symfony/dependency-injection": "~3.4|~4.0", @@ -29,6 +29,10 @@ "conflict": { "symfony/dependency-injection": "<3.4" }, + "provide": { + "psr/event-dispatcher-implementation": "1.0", + "symfony/event-dispatcher-implementation": "1.1" + }, "suggest": { "symfony/dependency-injection": "", "symfony/http-kernel": "" diff --git a/src/Symfony/Component/Form/Test/TypeTestCase.php b/src/Symfony/Component/Form/Test/TypeTestCase.php index 19fb5c32a073..76074d133fa6 100644 --- a/src/Symfony/Component/Form/Test/TypeTestCase.php +++ b/src/Symfony/Component/Form/Test/TypeTestCase.php @@ -11,7 +11,7 @@ namespace Symfony\Component\Form\Test; -use Symfony\Component\EventDispatcher\EventDispatcher; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Form\FormBuilder; use Symfony\Component\Form\Test\Traits\ValidatorExtensionTrait; @@ -25,7 +25,7 @@ abstract class TypeTestCase extends FormIntegrationTestCase protected $builder; /** - * @var EventDispatcher + * @var EventDispatcherInterface */ protected $dispatcher; @@ -33,7 +33,7 @@ private function doSetUp() { parent::setUp(); - $this->dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock(); + $this->dispatcher = $this->getMockBuilder(EventDispatcherInterface::class)->getMock(); $this->builder = new FormBuilder('', null, $this->dispatcher, $this->factory); } diff --git a/src/Symfony/Component/HttpKernel/DataCollector/EventDataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/EventDataCollector.php index c0de2509405e..8e84c6acf697 100644 --- a/src/Symfony/Component/HttpKernel/DataCollector/EventDataCollector.php +++ b/src/Symfony/Component/HttpKernel/DataCollector/EventDataCollector.php @@ -13,9 +13,9 @@ use Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher; use Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcherInterface; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; use Symfony\Contracts\Service\ResetInterface; /** diff --git a/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php b/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php index ddf4fa7cecf0..6bd45caa7a02 100644 --- a/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php +++ b/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php @@ -27,7 +27,7 @@ class TraceableEventDispatcher extends BaseTraceableEventDispatcher /** * {@inheritdoc} */ - protected function preDispatch($eventName, Event $event) + protected function beforeDispatch(string $eventName, $event) { switch ($eventName) { case KernelEvents::REQUEST: @@ -58,7 +58,7 @@ protected function preDispatch($eventName, Event $event) /** * {@inheritdoc} */ - protected function postDispatch($eventName, Event $event) + protected function afterDispatch(string $eventName, $event) { switch ($eventName) { case KernelEvents::CONTROLLER_ARGUMENTS: diff --git a/src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php b/src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php index 9d6d31ea96e6..8e31ecc944e3 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php @@ -54,6 +54,10 @@ public function logKernelException(GetResponseForExceptionEvent $event) $this->logException($event->getException(), sprintf('Uncaught PHP Exception %s: "%s" at %s line %s', $e->getClass(), $e->getMessage(), $e->getFile(), $e->getLine())); } + /** + * @param string $eventName + * @param EventDispatcherInterface $eventDispatcher + */ public function onKernelException(GetResponseForExceptionEvent $event) { if (null === $this->controller) { diff --git a/src/Symfony/Component/HttpKernel/Fragment/InlineFragmentRenderer.php b/src/Symfony/Component/HttpKernel/Fragment/InlineFragmentRenderer.php index bc397438d248..7d6243552a7b 100644 --- a/src/Symfony/Component/HttpKernel/Fragment/InlineFragmentRenderer.php +++ b/src/Symfony/Component/HttpKernel/Fragment/InlineFragmentRenderer.php @@ -11,7 +11,6 @@ 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; @@ -20,6 +19,7 @@ use Symfony\Component\HttpKernel\HttpCache\SubRequestHandler; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\KernelEvents; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; /** * Implements the inline rendering strategy where the Request is rendered by the current HTTP kernel. diff --git a/src/Symfony/Component/HttpKernel/HttpKernel.php b/src/Symfony/Component/HttpKernel/HttpKernel.php index 3de9b0202b53..64e931f2bd40 100644 --- a/src/Symfony/Component/HttpKernel/HttpKernel.php +++ b/src/Symfony/Component/HttpKernel/HttpKernel.php @@ -11,7 +11,6 @@ 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; @@ -32,6 +31,7 @@ use Symfony\Component\HttpKernel\Exception\ControllerDoesNotReturnResponseException; use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; /** * HttpKernel notifies events to convert a Request object to a Response one. diff --git a/src/Symfony/Component/HttpKernel/Tests/Fragment/InlineFragmentRendererTest.php b/src/Symfony/Component/HttpKernel/Tests/Fragment/InlineFragmentRendererTest.php index c8b79e8ff3c9..d6f0ff7771e2 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Fragment/InlineFragmentRendererTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Fragment/InlineFragmentRendererTest.php @@ -21,6 +21,7 @@ use Symfony\Component\HttpKernel\Fragment\InlineFragmentRenderer; use Symfony\Component\HttpKernel\HttpKernel; use Symfony\Component\HttpKernel\KernelEvents; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; class InlineFragmentRendererTest extends TestCase { @@ -73,7 +74,7 @@ public function testRenderWithTrustedHeaderDisabled() */ public function testRenderExceptionNoIgnoreErrors() { - $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock(); + $dispatcher = $this->getMockBuilder(EventDispatcherInterface::class)->getMock(); $dispatcher->expects($this->never())->method('dispatch'); $strategy = new InlineFragmentRenderer($this->getKernel($this->throwException(new \RuntimeException('foo'))), $dispatcher); @@ -87,7 +88,7 @@ public function testRenderExceptionIgnoreErrors() $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 = $this->getMockBuilder(EventDispatcherInterface::class)->getMock(); $dispatcher->expects($this->once())->method('dispatch')->with($expectedEvent, KernelEvents::EXCEPTION); $strategy = new InlineFragmentRenderer($kernel, $dispatcher); diff --git a/src/Symfony/Component/HttpKernel/composer.json b/src/Symfony/Component/HttpKernel/composer.json index b250dd30f702..ca818d16707a 100644 --- a/src/Symfony/Component/HttpKernel/composer.json +++ b/src/Symfony/Component/HttpKernel/composer.json @@ -17,7 +17,7 @@ ], "require": { "php": "^7.1.3", - "symfony/contracts": "^1.0.2", + "symfony/contracts": "^1.1", "symfony/event-dispatcher": "^4.3", "symfony/http-foundation": "^4.1.1", "symfony/debug": "~3.4|~4.0", diff --git a/src/Symfony/Component/Messenger/Command/ConsumeMessagesCommand.php b/src/Symfony/Component/Messenger/Command/ConsumeMessagesCommand.php index af916cb785c1..e49b28705c87 100644 --- a/src/Symfony/Component/Messenger/Command/ConsumeMessagesCommand.php +++ b/src/Symfony/Component/Messenger/Command/ConsumeMessagesCommand.php @@ -20,12 +20,12 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Messenger\RoutableMessageBus; use Symfony\Component\Messenger\Transport\Receiver\StopWhenMemoryUsageIsExceededReceiver; use Symfony\Component\Messenger\Transport\Receiver\StopWhenMessageCountIsExceededReceiver; use Symfony\Component\Messenger\Transport\Receiver\StopWhenTimeLimitIsReachedReceiver; use Symfony\Component\Messenger\Worker; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; /** * @author Samuel Roze diff --git a/src/Symfony/Component/Messenger/Event/AbstractWorkerMessageEvent.php b/src/Symfony/Component/Messenger/Event/AbstractWorkerMessageEvent.php index 0f2b64413939..237f244758ff 100644 --- a/src/Symfony/Component/Messenger/Event/AbstractWorkerMessageEvent.php +++ b/src/Symfony/Component/Messenger/Event/AbstractWorkerMessageEvent.php @@ -11,13 +11,12 @@ namespace Symfony\Component\Messenger\Event; -use Symfony\Component\EventDispatcher\Event; use Symfony\Component\Messenger\Envelope; /** * @experimental in 4.3 */ -abstract class AbstractWorkerMessageEvent extends Event +abstract class AbstractWorkerMessageEvent { private $envelope; private $receiverName; diff --git a/src/Symfony/Component/Messenger/Event/SendMessageToTransportsEvent.php b/src/Symfony/Component/Messenger/Event/SendMessageToTransportsEvent.php index a54622e83cf9..2e11a9209afe 100644 --- a/src/Symfony/Component/Messenger/Event/SendMessageToTransportsEvent.php +++ b/src/Symfony/Component/Messenger/Event/SendMessageToTransportsEvent.php @@ -11,7 +11,6 @@ namespace Symfony\Component\Messenger\Event; -use Symfony\Component\EventDispatcher\Event; use Symfony\Component\Messenger\Envelope; /** @@ -23,7 +22,7 @@ * * @author Ryan Weaver */ -class SendMessageToTransportsEvent extends Event +class SendMessageToTransportsEvent { private $envelope; diff --git a/src/Symfony/Component/Messenger/Middleware/SendMessageMiddleware.php b/src/Symfony/Component/Messenger/Middleware/SendMessageMiddleware.php index e389da910cbf..ba267ae7d2ca 100644 --- a/src/Symfony/Component/Messenger/Middleware/SendMessageMiddleware.php +++ b/src/Symfony/Component/Messenger/Middleware/SendMessageMiddleware.php @@ -13,13 +13,13 @@ use Psr\Log\LoggerAwareTrait; use Psr\Log\NullLogger; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Messenger\Envelope; use Symfony\Component\Messenger\Event\SendMessageToTransportsEvent; use Symfony\Component\Messenger\Stamp\ReceivedStamp; use Symfony\Component\Messenger\Stamp\RedeliveryStamp; use Symfony\Component\Messenger\Stamp\SentStamp; use Symfony\Component\Messenger\Transport\Sender\SendersLocatorInterface; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; /** * @author Samuel Roze diff --git a/src/Symfony/Component/Messenger/Tests/Middleware/SendMessageMiddlewareTest.php b/src/Symfony/Component/Messenger/Tests/Middleware/SendMessageMiddlewareTest.php index 8237838a3a0b..fa2ee76bd5b5 100644 --- a/src/Symfony/Component/Messenger/Tests/Middleware/SendMessageMiddlewareTest.php +++ b/src/Symfony/Component/Messenger/Tests/Middleware/SendMessageMiddlewareTest.php @@ -11,7 +11,6 @@ namespace Symfony\Component\Messenger\Tests\Middleware; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Messenger\Envelope; use Symfony\Component\Messenger\Event\SendMessageToTransportsEvent; use Symfony\Component\Messenger\Middleware\SendMessageMiddleware; @@ -24,6 +23,7 @@ use Symfony\Component\Messenger\Tests\Fixtures\DummyMessageInterface; use Symfony\Component\Messenger\Transport\Sender\SenderInterface; use Symfony\Component\Messenger\Transport\Sender\SendersLocator; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; class SendMessageMiddlewareTest extends MiddlewareTestCase { diff --git a/src/Symfony/Component/Messenger/Tests/WorkerTest.php b/src/Symfony/Component/Messenger/Tests/WorkerTest.php index cd833b223dce..4ecb7719cbae 100644 --- a/src/Symfony/Component/Messenger/Tests/WorkerTest.php +++ b/src/Symfony/Component/Messenger/Tests/WorkerTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\Messenger\Tests; use PHPUnit\Framework\TestCase; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Messenger\Envelope; use Symfony\Component\Messenger\Event\WorkerMessageFailedEvent; use Symfony\Component\Messenger\Event\WorkerMessageHandledEvent; @@ -26,6 +25,7 @@ use Symfony\Component\Messenger\Tests\Fixtures\CallbackReceiver; use Symfony\Component\Messenger\Tests\Fixtures\DummyMessage; use Symfony\Component\Messenger\Worker; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; class WorkerTest extends TestCase { diff --git a/src/Symfony/Component/Messenger/Worker.php b/src/Symfony/Component/Messenger/Worker.php index 19c5a4b0fafe..72319c014c9b 100644 --- a/src/Symfony/Component/Messenger/Worker.php +++ b/src/Symfony/Component/Messenger/Worker.php @@ -12,8 +12,6 @@ namespace Symfony\Component\Messenger; use Psr\Log\LoggerInterface; -use Symfony\Component\EventDispatcher\Event; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Messenger\Event\WorkerMessageFailedEvent; use Symfony\Component\Messenger\Event\WorkerMessageHandledEvent; use Symfony\Component\Messenger\Event\WorkerMessageReceivedEvent; @@ -25,6 +23,7 @@ use Symfony\Component\Messenger\Stamp\RedeliveryStamp; use Symfony\Component\Messenger\Stamp\SentStamp; use Symfony\Component\Messenger\Transport\Receiver\ReceiverInterface; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; /** * @author Samuel Roze @@ -141,7 +140,7 @@ public function run() }); } - private function dispatchEvent(Event $event) + private function dispatchEvent($event) { if (null === $this->eventDispatcher) { return; diff --git a/src/Symfony/Component/Security/Core/Authentication/AuthenticationProviderManager.php b/src/Symfony/Component/Security/Core/Authentication/AuthenticationProviderManager.php index fca4add09c3a..9a64565c523a 100644 --- a/src/Symfony/Component/Security/Core/Authentication/AuthenticationProviderManager.php +++ b/src/Symfony/Component/Security/Core/Authentication/AuthenticationProviderManager.php @@ -51,6 +51,9 @@ public function __construct(iterable $providers, bool $eraseCredentials = true) $this->eraseCredentials = $eraseCredentials; } + /** + * @final since Symfony 4.3, the type-hint will be updated to the interface from symfony/contracts in 5.0 + */ public function setEventDispatcher(EventDispatcherInterface $dispatcher) { $this->eventDispatcher = LegacyEventDispatcherProxy::decorate($dispatcher); diff --git a/src/Symfony/Component/Security/Core/Authorization/Voter/TraceableVoter.php b/src/Symfony/Component/Security/Core/Authorization/Voter/TraceableVoter.php index 6dbff4466a74..e5ce1f696be3 100644 --- a/src/Symfony/Component/Security/Core/Authorization/Voter/TraceableVoter.php +++ b/src/Symfony/Component/Security/Core/Authorization/Voter/TraceableVoter.php @@ -11,9 +11,10 @@ namespace Symfony\Component\Security\Core\Authorization\Voter; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\Event\VoteEvent; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; /** * Decorates voter classes to send result events. @@ -30,14 +31,14 @@ class TraceableVoter implements VoterInterface public function __construct(VoterInterface $voter, EventDispatcherInterface $eventDispatcher) { $this->voter = $voter; - $this->eventDispatcher = $eventDispatcher; + $this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher); } public function vote(TokenInterface $token, $subject, array $attributes) { $result = $this->voter->vote($token, $subject, $attributes); - $this->eventDispatcher->dispatch('debug.security.authorization.vote', new VoteEvent($this->voter, $subject, $attributes, $result)); + $this->eventDispatcher->dispatch(new VoteEvent($this->voter, $subject, $attributes, $result), 'debug.security.authorization.vote'); return $result; } diff --git a/src/Symfony/Component/Security/Core/Tests/Authorization/Voter/TraceableVoterTest.php b/src/Symfony/Component/Security/Core/Tests/Authorization/Voter/TraceableVoterTest.php index 99bf1f6eff90..53e6a277453f 100644 --- a/src/Symfony/Component/Security/Core/Tests/Authorization/Voter/TraceableVoterTest.php +++ b/src/Symfony/Component/Security/Core/Tests/Authorization/Voter/TraceableVoterTest.php @@ -12,11 +12,11 @@ namespace Symfony\Component\Security\Core\Tests\Authorization\Voter; use PHPUnit\Framework\TestCase; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\Authorization\Voter\TraceableVoter; use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface; use Symfony\Component\Security\Core\Event\VoteEvent; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; class TraceableVoterTest extends TestCase { @@ -44,7 +44,7 @@ public function testVote() $eventDispatcher ->expects($this->once()) ->method('dispatch') - ->with('debug.security.authorization.vote', new VoteEvent($voter, 'anysubject', ['attr1'], VoterInterface::ACCESS_DENIED)); + ->with(new VoteEvent($voter, 'anysubject', ['attr1'], VoterInterface::ACCESS_DENIED), 'debug.security.authorization.vote'); $sut = new TraceableVoter($voter, $eventDispatcher); $result = $sut->vote($token, 'anysubject', ['attr1']); diff --git a/src/Symfony/Component/Security/Core/composer.json b/src/Symfony/Component/Security/Core/composer.json index 42691b86c38a..05c1c3dbbe83 100644 --- a/src/Symfony/Component/Security/Core/composer.json +++ b/src/Symfony/Component/Security/Core/composer.json @@ -17,7 +17,7 @@ ], "require": { "php": "^7.1.3", - "symfony/contracts": "^1.0" + "symfony/contracts": "^1.1" }, "require-dev": { "psr/container": "^1.0", diff --git a/src/Symfony/Component/Security/Guard/GuardAuthenticatorHandler.php b/src/Symfony/Component/Security/Guard/GuardAuthenticatorHandler.php index 780dd93b4404..f146f59fd685 100644 --- a/src/Symfony/Component/Security/Guard/GuardAuthenticatorHandler.php +++ b/src/Symfony/Component/Security/Guard/GuardAuthenticatorHandler.php @@ -11,7 +11,6 @@ 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; @@ -22,6 +21,7 @@ use Symfony\Component\Security\Http\Event\InteractiveLoginEvent; use Symfony\Component\Security\Http\SecurityEvents; use Symfony\Component\Security\Http\Session\SessionAuthenticationStrategyInterface; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; /** * A utility class that does much of the *work* during the guard authentication process. diff --git a/src/Symfony/Component/Security/Guard/Tests/GuardAuthenticatorHandlerTest.php b/src/Symfony/Component/Security/Guard/Tests/GuardAuthenticatorHandlerTest.php index 9b513c42f941..8cca27f875fa 100644 --- a/src/Symfony/Component/Security/Guard/Tests/GuardAuthenticatorHandlerTest.php +++ b/src/Symfony/Component/Security/Guard/Tests/GuardAuthenticatorHandlerTest.php @@ -14,11 +14,15 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; +use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\Exception\AuthenticationException; use Symfony\Component\Security\Guard\AuthenticatorInterface; use Symfony\Component\Security\Guard\GuardAuthenticatorHandler; use Symfony\Component\Security\Http\Event\InteractiveLoginEvent; use Symfony\Component\Security\Http\SecurityEvents; +use Symfony\Component\Security\Http\Session\SessionAuthenticationStrategyInterface; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; class GuardAuthenticatorHandlerTest extends TestCase { @@ -158,11 +162,11 @@ public function testSessionStrategyIsNotCalledWhenStateless() protected function setUp() { - $this->tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock(); - $this->dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock(); - $this->token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock(); + $this->tokenStorage = $this->getMockBuilder(TokenStorageInterface::class)->getMock(); + $this->dispatcher = $this->getMockBuilder(EventDispatcherInterface::class)->getMock(); + $this->token = $this->getMockBuilder(TokenInterface::class)->getMock(); $this->request = new Request([], [], [], [], [], []); - $this->sessionStrategy = $this->getMockBuilder('Symfony\Component\Security\Http\Session\SessionAuthenticationStrategyInterface')->getMock(); + $this->sessionStrategy = $this->getMockBuilder(SessionAuthenticationStrategyInterface::class)->getMock(); $this->guardAuthenticator = $this->getMockBuilder(AuthenticatorInterface::class)->getMock(); } diff --git a/src/Symfony/Component/Security/Http/Firewall.php b/src/Symfony/Component/Security/Http/Firewall.php index bff8e3e884c4..7cd51ce21e87 100644 --- a/src/Symfony/Component/Security/Http/Firewall.php +++ b/src/Symfony/Component/Security/Http/Firewall.php @@ -38,6 +38,8 @@ class Firewall implements EventSubscriberInterface public function __construct(FirewallMapInterface $map, EventDispatcherInterface $dispatcher) { + // the type-hint will be updated to the "EventDispatcherInterface" from symfony/contracts in 5.0 + $this->map = $map; $this->dispatcher = $dispatcher; $this->exceptionListeners = new \SplObjectStorage(); diff --git a/src/Symfony/Component/Security/Http/Firewall/AbstractAuthenticationListener.php b/src/Symfony/Component/Security/Http/Firewall/AbstractAuthenticationListener.php index 06a3b2d2a7eb..58e188cc4c56 100644 --- a/src/Symfony/Component/Security/Http/Firewall/AbstractAuthenticationListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/AbstractAuthenticationListener.php @@ -12,7 +12,6 @@ namespace Symfony\Component\Security\Http\Firewall; use Psr\Log\LoggerInterface; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -31,6 +30,7 @@ use Symfony\Component\Security\Http\RememberMe\RememberMeServicesInterface; use Symfony\Component\Security\Http\SecurityEvents; use Symfony\Component\Security\Http\Session\SessionAuthenticationStrategyInterface; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; /** * The AbstractAuthenticationListener is the preferred base class for all diff --git a/src/Symfony/Component/Security/Http/Firewall/AbstractPreAuthenticatedListener.php b/src/Symfony/Component/Security/Http/Firewall/AbstractPreAuthenticatedListener.php index 60817ecd1c63..500ae43e498b 100644 --- a/src/Symfony/Component/Security/Http/Firewall/AbstractPreAuthenticatedListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/AbstractPreAuthenticatedListener.php @@ -12,7 +12,6 @@ namespace Symfony\Component\Security\Http\Firewall; use Psr\Log\LoggerInterface; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Event\RequestEvent; @@ -25,6 +24,7 @@ use Symfony\Component\Security\Http\Event\InteractiveLoginEvent; use Symfony\Component\Security\Http\SecurityEvents; use Symfony\Component\Security\Http\Session\SessionAuthenticationStrategyInterface; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; /** * AbstractPreAuthenticatedListener is the base class for all listener that diff --git a/src/Symfony/Component/Security/Http/Firewall/ExceptionListener.php b/src/Symfony/Component/Security/Http/Firewall/ExceptionListener.php index bfd4d5be298a..76a5a9107b4c 100644 --- a/src/Symfony/Component/Security/Http/Firewall/ExceptionListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/ExceptionListener.php @@ -39,7 +39,7 @@ * * @author Fabien Potencier * - * @final since Symfony 4.3 + * @final since Symfony 4.3, EventDispatcherInterface type-hints will be updated to the interface from symfony/contracts in 5.0 */ class ExceptionListener { diff --git a/src/Symfony/Component/Security/Http/Firewall/RememberMeListener.php b/src/Symfony/Component/Security/Http/Firewall/RememberMeListener.php index 16073859f85b..ebc03db86295 100644 --- a/src/Symfony/Component/Security/Http/Firewall/RememberMeListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/RememberMeListener.php @@ -12,7 +12,6 @@ namespace Symfony\Component\Security\Http\Firewall; use Psr\Log\LoggerInterface; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy; use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface; @@ -23,6 +22,7 @@ use Symfony\Component\Security\Http\SecurityEvents; use Symfony\Component\Security\Http\Session\SessionAuthenticationStrategy; use Symfony\Component\Security\Http\Session\SessionAuthenticationStrategyInterface; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; /** * RememberMeListener implements authentication capabilities via a cookie. diff --git a/src/Symfony/Component/Security/Http/Firewall/RemoteUserAuthenticationListener.php b/src/Symfony/Component/Security/Http/Firewall/RemoteUserAuthenticationListener.php index d384b2f28617..592e0127e512 100644 --- a/src/Symfony/Component/Security/Http/Firewall/RemoteUserAuthenticationListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/RemoteUserAuthenticationListener.php @@ -12,11 +12,11 @@ namespace Symfony\Component\Security\Http\Firewall; use Psr\Log\LoggerInterface; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Security\Core\Exception\BadCredentialsException; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; /** * REMOTE_USER authentication listener. diff --git a/src/Symfony/Component/Security/Http/Firewall/SwitchUserListener.php b/src/Symfony/Component/Security/Http/Firewall/SwitchUserListener.php index 092b334ae6ff..c94eb7e89b38 100644 --- a/src/Symfony/Component/Security/Http/Firewall/SwitchUserListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/SwitchUserListener.php @@ -12,7 +12,6 @@ namespace Symfony\Component\Security\Http\Firewall; use Psr\Log\LoggerInterface; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; @@ -30,6 +29,7 @@ use Symfony\Component\Security\Core\User\UserProviderInterface; use Symfony\Component\Security\Http\Event\SwitchUserEvent; use Symfony\Component\Security\Http\SecurityEvents; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; /** * SwitchUserListener allows a user to impersonate another one temporarily diff --git a/src/Symfony/Component/Security/Http/Firewall/UsernamePasswordFormAuthenticationListener.php b/src/Symfony/Component/Security/Http/Firewall/UsernamePasswordFormAuthenticationListener.php index 2b8ab8d09f57..4cc0677af86c 100644 --- a/src/Symfony/Component/Security/Http/Firewall/UsernamePasswordFormAuthenticationListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/UsernamePasswordFormAuthenticationListener.php @@ -12,7 +12,6 @@ namespace Symfony\Component\Security\Http\Firewall; use Psr\Log\LoggerInterface; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface; @@ -28,6 +27,7 @@ use Symfony\Component\Security\Http\HttpUtils; use Symfony\Component\Security\Http\ParameterBagUtils; use Symfony\Component\Security\Http\Session\SessionAuthenticationStrategyInterface; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; /** * UsernamePasswordFormAuthenticationListener is the default implementation of diff --git a/src/Symfony/Component/Security/Http/Firewall/UsernamePasswordJsonAuthenticationListener.php b/src/Symfony/Component/Security/Http/Firewall/UsernamePasswordJsonAuthenticationListener.php index 90a8225b35dc..ab991572f11c 100644 --- a/src/Symfony/Component/Security/Http/Firewall/UsernamePasswordJsonAuthenticationListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/UsernamePasswordJsonAuthenticationListener.php @@ -12,7 +12,6 @@ namespace Symfony\Component\Security\Http\Firewall; use Psr\Log\LoggerInterface; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; @@ -35,6 +34,7 @@ use Symfony\Component\Security\Http\HttpUtils; use Symfony\Component\Security\Http\SecurityEvents; use Symfony\Component\Security\Http\Session\SessionAuthenticationStrategyInterface; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; /** * UsernamePasswordJsonAuthenticationListener is a stateless implementation of diff --git a/src/Symfony/Component/Security/Http/Firewall/X509AuthenticationListener.php b/src/Symfony/Component/Security/Http/Firewall/X509AuthenticationListener.php index 2d3c26f28c3c..fc770ae936fb 100644 --- a/src/Symfony/Component/Security/Http/Firewall/X509AuthenticationListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/X509AuthenticationListener.php @@ -12,11 +12,11 @@ namespace Symfony\Component\Security\Http\Firewall; use Psr\Log\LoggerInterface; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Security\Core\Exception\BadCredentialsException; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; /** * X509 authentication listener. diff --git a/src/Symfony/Component/Security/Http/Tests/Firewall/RememberMeListenerTest.php b/src/Symfony/Component/Security/Http/Tests/Firewall/RememberMeListenerTest.php index fe237e3dbf04..1be9bf88e22f 100644 --- a/src/Symfony/Component/Security/Http/Tests/Firewall/RememberMeListenerTest.php +++ b/src/Symfony/Component/Security/Http/Tests/Firewall/RememberMeListenerTest.php @@ -18,6 +18,7 @@ use Symfony\Component\Security\Core\Exception\AuthenticationException; use Symfony\Component\Security\Http\Firewall\RememberMeListener; use Symfony\Component\Security\Http\SecurityEvents; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; class RememberMeListenerTest extends TestCase { @@ -447,7 +448,7 @@ protected function getTokenStorage() protected function getDispatcher() { - return $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock(); + return $this->getMockBuilder(EventDispatcherInterface::class)->getMock(); } private function getSessionStrategy() diff --git a/src/Symfony/Component/Security/Http/Tests/Firewall/SwitchUserListenerTest.php b/src/Symfony/Component/Security/Http/Tests/Firewall/SwitchUserListenerTest.php index c8b3ed245cb6..6fd60c0c02bb 100644 --- a/src/Symfony/Component/Security/Http/Tests/Firewall/SwitchUserListenerTest.php +++ b/src/Symfony/Component/Security/Http/Tests/Firewall/SwitchUserListenerTest.php @@ -23,6 +23,7 @@ use Symfony\Component\Security\Http\Event\SwitchUserEvent; use Symfony\Component\Security\Http\Firewall\SwitchUserListener; use Symfony\Component\Security\Http\SecurityEvents; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; class SwitchUserListenerTest extends TestCase { @@ -138,7 +139,7 @@ public function testExitUserDispatchesEventWithRefreshedUser() $this->tokenStorage->setToken(new SwitchUserToken('username', '', 'key', [new SwitchUserRole('ROLE_PREVIOUS', $originalToken, false)], $originalToken)); $this->request->query->set('_switch_user', SwitchUserListener::EXIT_VALUE); - $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock(); + $dispatcher = $this->getMockBuilder(EventDispatcherInterface::class)->getMock(); $dispatcher ->expects($this->once()) ->method('dispatch') @@ -165,7 +166,7 @@ public function testExitUserDoesNotDispatchEventWithStringUser() $this->tokenStorage->setToken(new SwitchUserToken('username', '', 'key', [new SwitchUserRole('ROLE_PREVIOUS', $originalToken, false)], $originalToken)); $this->request->query->set('_switch_user', SwitchUserListener::EXIT_VALUE); - $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock(); + $dispatcher = $this->getMockBuilder(EventDispatcherInterface::class)->getMock(); $dispatcher ->expects($this->never()) ->method('dispatch') @@ -267,7 +268,7 @@ public function testSwitchUserWithReplacedToken() ->method('loadUserByUsername')->with('kuba') ->will($this->returnValue($user)); - $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock(); + $dispatcher = $this->getMockBuilder(EventDispatcherInterface::class)->getMock(); $dispatcher ->expects($this->once()) ->method('dispatch') diff --git a/src/Symfony/Component/Security/composer.json b/src/Symfony/Component/Security/composer.json index fddc5165910f..7a0e0c23107c 100644 --- a/src/Symfony/Component/Security/composer.json +++ b/src/Symfony/Component/Security/composer.json @@ -17,7 +17,7 @@ ], "require": { "php": "^7.1.3", - "symfony/contracts": "^1.0", + "symfony/contracts": "^1.1", "symfony/http-foundation": "~3.4|~4.0", "symfony/http-kernel": "^4.3", "symfony/property-access": "~3.4|~4.0" diff --git a/src/Symfony/Component/Workflow/StateMachine.php b/src/Symfony/Component/Workflow/StateMachine.php index ad6a26c2d883..c9f88a022bfe 100644 --- a/src/Symfony/Component/Workflow/StateMachine.php +++ b/src/Symfony/Component/Workflow/StateMachine.php @@ -11,9 +11,9 @@ namespace Symfony\Component\Workflow; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Workflow\MarkingStore\MarkingStoreInterface; use Symfony\Component\Workflow\MarkingStore\SingleStateMarkingStore; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; /** * @author Tobias Nyholm diff --git a/src/Symfony/Component/Workflow/Tests/RegistryTest.php b/src/Symfony/Component/Workflow/Tests/RegistryTest.php index 867046f7c5db..a13c43549758 100644 --- a/src/Symfony/Component/Workflow/Tests/RegistryTest.php +++ b/src/Symfony/Component/Workflow/Tests/RegistryTest.php @@ -3,13 +3,13 @@ namespace Symfony\Component\Workflow\Tests; use PHPUnit\Framework\TestCase; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Workflow\Definition; use Symfony\Component\Workflow\MarkingStore\MarkingStoreInterface; use Symfony\Component\Workflow\Registry; use Symfony\Component\Workflow\SupportStrategy\SupportStrategyInterface; use Symfony\Component\Workflow\SupportStrategy\WorkflowSupportStrategyInterface; use Symfony\Component\Workflow\Workflow; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; class RegistryTest extends TestCase { diff --git a/src/Symfony/Component/Workflow/Workflow.php b/src/Symfony/Component/Workflow/Workflow.php index ca6b8f229115..188d69e7d3c2 100644 --- a/src/Symfony/Component/Workflow/Workflow.php +++ b/src/Symfony/Component/Workflow/Workflow.php @@ -11,7 +11,6 @@ namespace Symfony\Component\Workflow; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy; use Symfony\Component\Workflow\Event\AnnounceEvent; use Symfony\Component\Workflow\Event\CompletedEvent; @@ -26,6 +25,7 @@ use Symfony\Component\Workflow\MarkingStore\MarkingStoreInterface; use Symfony\Component\Workflow\MarkingStore\MultipleStateMarkingStore; use Symfony\Component\Workflow\Metadata\MetadataStoreInterface; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; /** * @author Fabien Potencier diff --git a/src/Symfony/Contracts/CHANGELOG.md b/src/Symfony/Contracts/CHANGELOG.md index b37bc2a70531..b5f1d76aecda 100644 --- a/src/Symfony/Contracts/CHANGELOG.md +++ b/src/Symfony/Contracts/CHANGELOG.md @@ -5,6 +5,7 @@ CHANGELOG ----- * added `HttpClient` namespace with contracts for implementing flexible HTTP clients + * added `EventDispatcher\EventDispatcherInterface` 1.0.0 ----- diff --git a/src/Symfony/Contracts/EventDispatcher/EventDispatcherInterface.php b/src/Symfony/Contracts/EventDispatcher/EventDispatcherInterface.php new file mode 100644 index 000000000000..9b1a69add233 --- /dev/null +++ b/src/Symfony/Contracts/EventDispatcher/EventDispatcherInterface.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\Contracts\EventDispatcher; + +use Psr\EventDispatcher\EventDispatcherInterface as PsrEventDispatcherInterface; + +if (interface_exists(PsrEventDispatcherInterface::class)) { + /** + * Allows providing hooks on domain-specific lifecycles by dispatching events. + */ + interface EventDispatcherInterface extends PsrEventDispatcherInterface + { + /** + * Dispatches an event to all registered listeners. + * + * For BC with Symfony 4, the $eventName argument is not declared explicitly on the + * signature of the method. Implementations that are not bound by this BC contraint + * MUST declare it explicitly, as allowed by PHP. + * + * @param object $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 object The passed $event MUST be returned + */ + public function dispatch($event/*, string $eventName = null*/); + } +} else { + /** + * Allows providing hooks on domain-specific lifecycles by dispatching events. + */ + interface EventDispatcherInterface + { + /** + * Dispatches an event to all registered listeners. + * + * For BC with Symfony 4, the $eventName argument is not declared explicitly on the + * signature of the method. Implementations that are not bound by this BC contraint + * MUST declare it explicitly, as allowed by PHP. + * + * @param object $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 object The passed $event MUST be returned + */ + public function dispatch($event/*, string $eventName = null*/); + } +} diff --git a/src/Symfony/Contracts/composer.json b/src/Symfony/Contracts/composer.json index f881258dc1a4..b83e7c0535cf 100644 --- a/src/Symfony/Contracts/composer.json +++ b/src/Symfony/Contracts/composer.json @@ -27,6 +27,7 @@ "psr/cache": "When using the Cache contracts", "psr/container": "When using the Service contracts", "symfony/cache-contracts-implementation": "", + "symfony/event-dispatcher-implementation": "", "symfony/http-client-contracts-implementation": "", "symfony/service-contracts-implementation": "", "symfony/translation-contracts-implementation": ""