8000 [EventDispatcher] Deprecate ContainerAwareEventDispatcher::getContain… · symfony/symfony@0b8ac03 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0b8ac03

Browse files
[EventDispatcher] Deprecate ContainerAwareEventDispatcher::getContainer() && ::lazyLoad()
1 parent 9f95654 commit 0b8ac03

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/Symfony/Component/EventDispatcher/ContainerAwareEventDispatcher.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@ class ContainerAwareEventDispatcher extends EventDispatcher
5252
public function __construct(ContainerInterface $container)
5353
{
5454
$this->container = $container;
55+
56+
$class = get_class($this);
57+
if ($this instanceof \PHPUnit_Framework_MockObject_MockObject || $this instanceof \Prophecy\Doubler\DoubleInterface) {
58+
$class = get_parent_class($class);
59+
}
60+
if (__CLASS__ === $class) {
61+
return;
62+
}
63+
$r = new \ReflectionMethod($class, 'lazyLoad');
64+
if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
65+
@trigger_error(sprintf('Extending %s::lazyLoad() in %s is deprecated since version 3.3 and won\'t be supported anymore in 4.0 as it will be private.', __CLASS__, $class), E_USER_DEPRECATED);
66+
}
5567
}
5668

5769
/**
@@ -161,8 +173,13 @@ public function addSubscriberService($serviceId, $class)
161173
}
162174
}
163175

176+
/**
177+
* @deprecated since version 3.3, to be removed in 4.0. Inject the container or the services you need in your listeners/subscribers instead.
178+
*/
164179
public function getContainer()
165180
{
181+
@trigger_error('The '.__METHOD__.'() method is deprecated since version 3.3 and will be removed in 4.0. Inject the container or the services you need in your listeners/subscribers instead.', E_USER_DEPRECATED);
182+
166183
return $this->container;
167184
}
168185

@@ -173,6 +190,8 @@ public function getContainer()
173190
* @param string $eventName The name of the event to dispatch. The name of
174191
* the event is the name of the method that is
175192
* invoked on listeners.
193+
*
194+
* @deprecated since version 3.3, will be private in 4.0.
176195
*/
177196
protected function lazyLoad($eventName)
178197
{

0 commit comments

Comments
 (0)
0