LazyEventDispatcher.php 848 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. namespace JMS\SerializerBundle\EventDispatcher;
  3. use Symfony\Component\DependencyInjection\ContainerInterface;
  4. class LazyEventDispatcher extends EventDispatcher
  5. {
  6. private $container;
  7. public function __construct(ContainerInterface $container)
  8. {
  9. $this->container = $container;
  10. }
  11. protected function initializeListeners($eventName, $loweredClass, $format)
  12. {
  13. $listeners = parent::initializeListeners($eventName, $loweredClass, $format);
  14. foreach ($listeners as &$listener) {
  15. if ( ! is_array($listener) || ! is_string($listener[0])) {
  16. continue;
  17. }
  18. if ( ! $this->container->has($listener[0])) {
  19. continue;
  20. }
  21. $listener[0] = $this->container->get($listener[0]);
  22. }
  23. return $listeners;
  24. }
  25. }