This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Bundle/FrameworkBundle/EventDispatcher.php

87 lines
2.3 KiB
PHP
Raw Normal View History

<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* 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;
/**
2011-01-05 11:13:27 +00:00
* This EventDispatcher automatically gets the kernel listeners injected
*
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
class EventDispatcher extends BaseEventDispatcher
{
protected $container;
/**
* Constructor.
*
* @param ContainerInterface $container A ContainerInterface instance
*/
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
2011-01-24 15:46:04 +00:00
public function registerKernelListeners(array $listeners)
{
2011-01-24 15:46:04 +00:00
$this->listeners = $listeners;
}
/**
* {@inheritdoc}
*/
public function notify(EventInterface $event)
{
2011-01-24 15:46:04 +00:00
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)
2011-01-24 15:46:04 +00:00
{
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;
2011-01-24 15:46:04 +00:00
}
}
2011-01-24 15:46:04 +00:00
}
/**
* {@inheritdoc}
*/
public function filter(EventInterface $event, $value)
2011-01-24 15:46:04 +00:00
{
foreach ($this->getListeners($event->getName()) as $listener) {
if (is_array($listener) && is_string($listener[0])) {
$listener[0] = $this->container->get($listener[0]);
2011-01-05 11:13:27 +00:00
}
2011-01-24 15:46:04 +00:00
$value = call_user_func($listener, $event, $value);
}
return $value;
}
}