Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/event-dispatcher/ContainerAwareEventDispatcher.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | 7a779792577d |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
13:5fb285c0d0e3 | 14:1fec387a4317 |
---|---|
18 * container. | 18 * container. |
19 * | 19 * |
20 * @author Fabien Potencier <fabien@symfony.com> | 20 * @author Fabien Potencier <fabien@symfony.com> |
21 * @author Bernhard Schussek <bschussek@gmail.com> | 21 * @author Bernhard Schussek <bschussek@gmail.com> |
22 * @author Jordan Alliot <jordan.alliot@gmail.com> | 22 * @author Jordan Alliot <jordan.alliot@gmail.com> |
23 * | |
24 * @deprecated since 3.3, to be removed in 4.0. Use EventDispatcher with closure factories instead. | |
23 */ | 25 */ |
24 class ContainerAwareEventDispatcher extends EventDispatcher | 26 class ContainerAwareEventDispatcher extends EventDispatcher |
25 { | 27 { |
26 /** | |
27 * The container from where services are loaded. | |
28 * | |
29 * @var ContainerInterface | |
30 */ | |
31 private $container; | 28 private $container; |
32 | 29 |
33 /** | 30 /** |
34 * The service IDs of the event listeners and subscribers. | 31 * The service IDs of the event listeners and subscribers. |
35 * | |
36 * @var array | |
37 */ | 32 */ |
38 private $listenerIds = array(); | 33 private $listenerIds = array(); |
39 | 34 |
40 /** | 35 /** |
41 * The services registered as listeners. | 36 * The services registered as listeners. |
42 * | |
43 * @var array | |
44 */ | 37 */ |
45 private $listeners = array(); | 38 private $listeners = array(); |
46 | 39 |
47 /** | |
48 * Constructor. | |
49 * | |
50 * @param ContainerInterface $container A ContainerInterface instance | |
51 */ | |
52 public function __construct(ContainerInterface $container) | 40 public function __construct(ContainerInterface $container) |
53 { | 41 { |
54 $this->container = $container; | 42 $this->container = $container; |
43 | |
44 $class = get_class($this); | |
45 if ($this instanceof \PHPUnit_Framework_MockObject_MockObject || $this instanceof \Prophecy\Doubler\DoubleInterface) { | |
46 $class = get_parent_class($class); | |
47 } | |
48 if (__CLASS__ !== $class) { | |
49 @trigger_error(sprintf('The %s class is deprecated since Symfony 3.3 and will be removed in 4.0. Use EventDispatcher with closure factories instead.', __CLASS__), E_USER_DEPRECATED); | |
50 } | |
55 } | 51 } |
56 | 52 |
57 /** | 53 /** |
58 * Adds a service as event listener. | 54 * Adds a service as event listener. |
59 * | 55 * |
66 * | 62 * |
67 * @throws \InvalidArgumentException | 63 * @throws \InvalidArgumentException |
68 */ | 64 */ |
69 public function addListenerService($eventName, $callback, $priority = 0) | 65 public function addListenerService($eventName, $callback, $priority = 0) |
70 { | 66 { |
67 @trigger_error(sprintf('The %s class is deprecated since Symfony 3.3 and will be removed in 4.0. Use EventDispatcher with closure factories instead.', __CLASS__), E_USER_DEPRECATED); | |
68 | |
71 if (!is_array($callback) || 2 !== count($callback)) { | 69 if (!is_array($callback) || 2 !== count($callback)) { |
72 throw new \InvalidArgumentException('Expected an array("service", "method") argument'); | 70 throw new \InvalidArgumentException('Expected an array("service", "method") argument'); |
73 } | 71 } |
74 | 72 |
75 $this->listenerIds[$eventName][] = array($callback[0], $callback[1], $priority); | 73 $this->listenerIds[$eventName][] = array($callback[0], $callback[1], $priority); |
78 public function removeListener($eventName, $listener) | 76 public function removeListener($eventName, $listener) |
79 { | 77 { |
80 $this->lazyLoad($eventName); | 78 $this->lazyLoad($eventName); |
81 | 79 |
82 if (isset($this->listenerIds[$eventName])) { | 80 if (isset($this->listenerIds[$eventName])) { |
83 foreach ($this->listenerIds[$eventName] as $i => list($serviceId, $method, $priority)) { | 81 foreach ($this->listenerIds[$eventName] as $i => list($serviceId, $method)) { |
84 $key = $serviceId.'.'.$method; | 82 $key = $serviceId.'.'.$method; |
85 if (isset($this->listeners[$eventName][$key]) && $listener === array($this->listeners[$eventName][$key], $method)) { | 83 if (isset($this->listeners[$eventName][$key]) && $listener === array($this->listeners[$eventName][$key], $method)) { |
86 unset($this->listeners[$eventName][$key]); | 84 unset($this->listeners[$eventName][$key]); |
87 if (empty($this->listeners[$eventName])) { | 85 if (empty($this->listeners[$eventName])) { |
88 unset($this->listeners[$eventName]); | 86 unset($this->listeners[$eventName]); |
146 * @param string $serviceId The service ID of the subscriber service | 144 * @param string $serviceId The service ID of the subscriber service |
147 * @param string $class The service's class name (which must implement EventSubscriberInterface) | 145 * @param string $class The service's class name (which must implement EventSubscriberInterface) |
148 */ | 146 */ |
149 public function addSubscriberService($serviceId, $class) | 147 public function addSubscriberService($serviceId, $class) |
150 { | 148 { |
149 @trigger_error(sprintf('The %s class is deprecated since Symfony 3.3 and will be removed in 4.0. Use EventDispatcher with closure factories instead.', __CLASS__), E_USER_DEPRECATED); | |
150 | |
151 foreach ($class::getSubscribedEvents() as $eventName => $params) { | 151 foreach ($class::getSubscribedEvents() as $eventName => $params) { |
152 if (is_string($params)) { | 152 if (is_string($params)) { |
153 $this->listenerIds[$eventName][] = array($serviceId, $params, 0); | 153 $this->listenerIds[$eventName][] = array($serviceId, $params, 0); |
154 } elseif (is_string($params[0])) { | 154 } elseif (is_string($params[0])) { |
155 $this->listenerIds[$eventName][] = array($serviceId, $params[0], isset($params[1]) ? $params[1] : 0); | 155 $this->listenerIds[$eventName][] = array($serviceId, $params[0], isset($params[1]) ? $params[1] : 0); |
161 } | 161 } |
162 } | 162 } |
163 | 163 |
164 public function getContainer() | 164 public function getContainer() |
165 { | 165 { |
166 @trigger_error('The '.__METHOD__.'() method is deprecated since Symfony 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); | |
167 | |
166 return $this->container; | 168 return $this->container; |
167 } | 169 } |
168 | 170 |
169 /** | 171 /** |
170 * Lazily loads listeners for this event from the dependency injection | 172 * Lazily loads listeners for this event from the dependency injection |
181 $listener = $this->container->get($serviceId); | 183 $listener = $this->container->get($serviceId); |
182 | 184 |
183 $key = $serviceId.'.'.$method; | 185 $key = $serviceId.'.'.$method; |
184 if (!isset($this->listeners[$eventName][$key])) { | 186 if (!isset($this->listeners[$eventName][$key])) { |
185 $this->addListener($eventName, array($listener, $method), $priority); | 187 $this->addListener($eventName, array($listener, $method), $priority); |
186 } elseif ($listener !== $this->listeners[$eventName][$key]) { | 188 } elseif ($this->listeners[$eventName][$key] !== $listener) { |
187 parent::removeListener($eventName, array($this->listeners[$eventName][$key], $method)); | 189 parent::removeListener($eventName, array($this->listeners[$eventName][$key], $method)); |
188 $this->addListener($eventName, array($listener, $method), $priority); | 190 $this->addListener($eventName, array($listener, $method), $priority); |
189 } | 191 } |
190 | 192 |
191 $this->listeners[$eventName][$key] = $listener; | 193 $this->listeners[$eventName][$key] = $listener; |