Skip to content

[EventDispatcher] Deprecate ContainerAwareEventDispatcher #20937

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions UPGRADE-3.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
------

Expand Down
6 changes: 6 additions & 0 deletions UPGRADE-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------

Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/EventDispatcher/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

3.3.0
-----

* The ContainerAwareEventDispatcher class has been deprecated. Use EventDispatcher with closure-proxy injection instead.

3.0.0
-----

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
* @author Fabien Potencier <fabien@symfony.com>
* @author Bernhard Schussek <bschussek@gmail.com>
* @author Jordan Alliot <jordan.alliot@gmail.com>
*
* @deprecated since 3.3, to be removed in 4.0. Use EventDispatcher with closure-proxy injection instead.
*/
class ContainerAwareEventDispatcher extends EventDispatcher
{
Expand Down Expand Up @@ -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);
}
}

/**
Expand All @@ -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');
}
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
* @group legacy
*/
class ContainerAwareEventDispatcherTest extends AbstractEventDispatcherTest
{
protected function createEventDispatcher()
Expand Down