From c4a6a8a47c84ead836f09945f26975512e529118 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 15 Dec 2016 16:32:21 +0100 Subject: [PATCH] [EventDispatcher] Deprecate ContainerAwareEventDispatcher --- UPGRADE-3.3.md | 6 ++++++ UPGRADE-4.0.md | 6 ++++++ .../Component/EventDispatcher/CHANGELOG.md | 5 +++++ .../ContainerAwareEventDispatcher.php | 16 ++++++++++++++++ .../Tests/ContainerAwareEventDispatcherTest.php | 3 +++ 5 files changed, 36 insertions(+) diff --git a/UPGRADE-3.3.md b/UPGRADE-3.3.md index dcfc81bb30daf..adef6db1cf5ed 100644 --- a/UPGRADE-3.3.md +++ b/UPGRADE-3.3.md @@ -16,6 +16,12 @@ DependencyInjection * The `DefinitionDecorator` class is deprecated and will be removed in 4.0, use the `ChildDefinition` class instead. +EventDispatcher +--------------- + + * The `ContainerAwareEventDispatcher` class has been deprecated. + Use `EventDispatcher` with closure-proxy injection instead. + Finder ------ diff --git a/UPGRADE-4.0.md b/UPGRADE-4.0.md index 26c01963ba3d2..851e2ae8b9171 100644 --- a/UPGRADE-4.0.md +++ b/UPGRADE-4.0.md @@ -42,6 +42,12 @@ DependencyInjection * Requesting a private service with the `Container::get()` method is no longer supported. +EventDispatcher +--------------- + + * The `ContainerAwareEventDispatcher` class has been removed. + Use `EventDispatcher` with closure-proxy injection instead. + ExpressionLanguage ---------- diff --git a/src/Symfony/Component/EventDispatcher/CHANGELOG.md b/src/Symfony/Component/EventDispatcher/CHANGELOG.md index 8feda35d57e10..51c1d919bb4df 100644 --- a/src/Symfony/Component/EventDispatcher/CHANGELOG.md +++ b/src/Symfony/Component/EventDispatcher/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +3.3.0 +----- + + * The ContainerAwareEventDispatcher class has been deprecated. Use EventDispatcher with closure-proxy injection instead. + 3.0.0 ----- diff --git a/src/Symfony/Component/EventDispatcher/ContainerAwareEventDispatcher.php b/src/Symfony/Component/EventDispatcher/ContainerAwareEventDispatcher.php index 5982b85f3021d..195acf2e0b6e6 100644 --- a/src/Symfony/Component/EventDispatcher/ContainerAwareEventDispatcher.php +++ b/src/Symfony/Component/EventDispatcher/ContainerAwareEventDispatcher.php @@ -20,6 +20,8 @@ * @author Fabien Potencier * @author Bernhard Schussek * @author Jordan Alliot + * + * @deprecated since 3.3, to be removed in 4.0. Use EventDispatcher with closure-proxy injection instead. */ class ContainerAwareEventDispatcher extends EventDispatcher { @@ -52,6 +54,14 @@ class ContainerAwareEventDispatcher extends EventDispatcher public function __construct(ContainerInterface $container) { $this->container = $container; + + $class = get_class($this); + if ($this instanceof \PHPUnit_Framework_MockObject_MockObject || $this instanceof \Prophecy\Doubler\DoubleInterface) { + $class = get_parent_class($class); + } + if (__CLASS__ !== $class) { + @trigger_error(sprintf('The %s class is deprecated since version 3.3 and will be removed in 4.0. Use EventDispatcher with closure-proxy injection instead.', __CLASS__), E_USER_DEPRECATED); + } } /** @@ -68,6 +78,8 @@ public function __construct(ContainerInterface $container) */ public function addListenerService($eventName, $callback, $priority = 0) { + @trigger_error(sprintf('The %s class is deprecated since version 3.3 and will be removed in 4.0. Use EventDispatcher with closure-proxy injection instead.', __CLASS__), E_USER_DEPRECATED); + if (!is_array($callback) || 2 !== count($callback)) { throw new \InvalidArgumentException('Expected an array("service", "method") argument'); } @@ -148,6 +160,8 @@ public function getListenerPriority($eventName, $listener) */ public function addSubscriberService($serviceId, $class) { + @trigger_error(sprintf('The %s class is deprecated since version 3.3 and will be removed in 4.0. Use EventDispatcher with closure-proxy injection instead.', __CLASS__), E_USER_DEPRECATED); + foreach ($class::getSubscribedEvents() as $eventName => $params) { if (is_string($params)) { $this->listenerIds[$eventName][] = array($serviceId, $params, 0); @@ -163,6 +177,8 @@ public function addSubscriberService($serviceId, $class) public function getContainer() { + @trigger_error('The '.__METHOD__.'() method is deprecated since version 3.3 as its class will be removed in 4.0. Inject the container or the services you need in your listeners/subscribers instead.', E_USER_DEPRECATED); + return $this->container; } diff --git a/src/Symfony/Component/EventDispatcher/Tests/ContainerAwareEventDispatcherTest.php b/src/Symfony/Component/EventDispatcher/Tests/ContainerAwareEventDispatcherTest.php index 2a0da9ca67c3a..180556149268c 100644 --- a/src/Symfony/Component/EventDispatcher/Tests/ContainerAwareEventDispatcherTest.php +++ b/src/Symfony/Component/EventDispatcher/Tests/ContainerAwareEventDispatcherTest.php @@ -16,6 +16,9 @@ use Symfony\Component\EventDispatcher\Event; use Symfony\Component\EventDispatcher\EventSubscriberInterface; +/** + * @group legacy + */ class ContainerAwareEventDispatcherTest extends AbstractEventDispatcherTest { protected function createEventDispatcher()