diff options
Diffstat (limited to 'vendor/symfony/event-dispatcher/ContainerAwareEventDispatcher.php')
-rw-r--r-- | vendor/symfony/event-dispatcher/ContainerAwareEventDispatcher.php | 50 |
1 files changed, 30 insertions, 20 deletions
diff --git a/vendor/symfony/event-dispatcher/ContainerAwareEventDispatcher.php b/vendor/symfony/event-dispatcher/ContainerAwareEventDispatcher.php index b92defe6..7a2b68be 100644 --- a/vendor/symfony/event-dispatcher/ContainerAwareEventDispatcher.php +++ b/vendor/symfony/event-dispatcher/ContainerAwareEventDispatcher.php @@ -20,38 +20,34 @@ use Symfony\Component\DependencyInjection\ContainerInterface; * @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 factories instead. */ class ContainerAwareEventDispatcher extends EventDispatcher { - /** - * The container from where services are loaded. - * - * @var ContainerInterface - */ private $container; /** * The service IDs of the event listeners and subscribers. - * - * @var array */ private $listenerIds = array(); /** * The services registered as listeners. - * - * @var array */ private $listeners = array(); - /** - * Constructor. - * - * @param ContainerInterface $container A ContainerInterface instance - */ 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 factories instead.', __CLASS__), E_USER_DEPRECATED); + } } /** @@ -68,6 +64,8 @@ class ContainerAwareEventDispatcher extends EventDispatcher */ 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 factories instead.', __CLASS__), E_USER_DEPRECATED); + if (!is_array($callback) || 2 !== count($callback)) { throw new \InvalidArgumentException('Expected an array("service", "method") argument'); } @@ -80,8 +78,7 @@ class ContainerAwareEventDispatcher extends EventDispatcher $this->lazyLoad($eventName); if (isset($this->listenerIds[$eventName])) { - foreach ($this->listenerIds[$eventName] as $i => $args) { - list($serviceId, $method, $priority) = $args; + foreach ($this->listenerIds[$eventName] as $i => list($serviceId, $method)) { $key = $serviceId.'.'.$method; if (isset($this->listeners[$eventName][$key]) && $listener === array($this->listeners[$eventName][$key], $method)) { unset($this->listeners[$eventName][$key]); @@ -105,7 +102,7 @@ class ContainerAwareEventDispatcher extends EventDispatcher public function hasListeners($eventName = null) { if (null === $eventName) { - return (bool) count($this->listenerIds) || (bool) count($this->listeners); + return $this->listenerIds || $this->listeners || parent::hasListeners(); } if (isset($this->listenerIds[$eventName])) { @@ -132,6 +129,16 @@ class ContainerAwareEventDispatcher extends EventDispatcher } /** + * {@inheritdoc} + */ + public function getListenerPriority($eventName, $listener) + { + $this->lazyLoad($eventName); + + return parent::getListenerPriority($eventName, $listener); + } + + /** * Adds a service as event subscriber. * * @param string $serviceId The service ID of the subscriber service @@ -139,6 +146,8 @@ class ContainerAwareEventDispatcher extends EventDispatcher */ 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 factories instead.', __CLASS__), E_USER_DEPRECATED); + foreach ($class::getSubscribedEvents() as $eventName => $params) { if (is_string($params)) { $this->listenerIds[$eventName][] = array($serviceId, $params, 0); @@ -154,6 +163,8 @@ class ContainerAwareEventDispatcher extends EventDispatcher 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; } @@ -168,14 +179,13 @@ class ContainerAwareEventDispatcher extends EventDispatcher protected function lazyLoad($eventName) { if (isset($this->listenerIds[$eventName])) { - foreach ($this->listenerIds[$eventName] as $args) { - list($serviceId, $method, $priority) = $args; + foreach ($this->listenerIds[$eventName] as list($serviceId, $method, $priority)) { $listener = $this->container->get($serviceId); $key = $serviceId.'.'.$method; if (!isset($this->listeners[$eventName][$key])) { $this->addListener($eventName, array($listener, $method), $priority); - } elseif ($listener !== $this->listeners[$eventName][$key]) { + } elseif ($this->listeners[$eventName][$key] !== $listener) { parent::removeListener($eventName, array($this->listeners[$eventName][$key], $method)); $this->addListener($eventName, array($listener, $method), $priority); } |