* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Bundle\FrameworkBundle; use Symfony\Component\EventDispatcher\EventDispatcher as BaseEventDispatcher; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\EventDispatcher\EventInterface; /** * This EventDispatcher automatically gets the kernel listeners injected * * @author Fabien Potencier */ class EventDispatcher extends BaseEventDispatcher { protected $container; /** * Constructor. * * @param ContainerInterface $container A ContainerInterface instance */ public function __construct(ContainerInterface $container) { $this->container = $container; } public function registerKernelListeners(array $listeners) { $this->listeners = $listeners; } /** * {@inheritdoc} */ public function notify(EventInterface $event) { foreach ($this->getListeners($event->getName()) as $listener) { if (is_array($listener) && is_string($listener[0])) { $listener[0] = $this->container->get($listener[0]); } call_user_func($listener, $event); } } /** * {@inheritdoc} */ public function notifyUntil(EventInterface $event) { foreach ($this->getListeners($event->getName()) as $listener) { if (is_array($listener) && is_string($listener[0])) { $listener[0] = $this->container->get($listener[0]); } $ret = call_user_func($listener, $event); if ($event->isProcessed()) { return $ret; } } } /** * {@inheritdoc} */ public function filter(EventInterface $event, $value) { foreach ($this->getListeners($event->getName()) as $listener) { if (is_array($listener) && is_string($listener[0])) { $listener[0] = $this->container->get($listener[0]); } $value = call_user_func($listener, $event, $value); } return $value; } }