2010-02-17 13:54:36 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2010-04-07 01:51:29 +01:00
|
|
|
* This file is part of the Symfony package.
|
2010-02-17 13:54:36 +00:00
|
|
|
*
|
|
|
|
* (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.
|
|
|
|
*/
|
|
|
|
|
2011-01-15 13:29:43 +00:00
|
|
|
namespace Symfony\Bundle\FrameworkBundle;
|
|
|
|
|
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcher as BaseEventDispatcher;
|
2011-01-23 17:02:16 +00:00
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
2011-01-24 15:46:04 +00:00
|
|
|
use Symfony\Component\EventDispatcher\Event;
|
2011-01-15 13:29:43 +00:00
|
|
|
|
2010-02-17 13:54:36 +00:00
|
|
|
/**
|
2011-01-05 11:13:27 +00:00
|
|
|
* This EventDispatcher automatically gets the kernel listeners injected
|
2010-02-17 13:54:36 +00:00
|
|
|
*
|
2010-10-17 12:45:15 +01:00
|
|
|
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
2010-02-17 13:54:36 +00:00
|
|
|
*/
|
|
|
|
class EventDispatcher extends BaseEventDispatcher
|
|
|
|
{
|
2011-01-23 17:02:16 +00:00
|
|
|
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-23 17:02:16 +00:00
|
|
|
{
|
2011-01-24 15:46:04 +00:00
|
|
|
$this->listeners = $listeners;
|
2011-01-23 17:02:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2011-01-24 15:46:04 +00:00
|
|
|
public function notify(Event $event)
|
2010-02-17 13:54:36 +00:00
|
|
|
{
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $event;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function notifyUntil(Event $event)
|
|
|
|
{
|
|
|
|
foreach ($this->getListeners($event->getName()) as $listener) {
|
|
|
|
if (is_array($listener) && is_string($listener[0])) {
|
|
|
|
$listener[0] = $this->container->get($listener[0]);
|
|
|
|
}
|
|
|
|
if (call_user_func($listener, $event)) {
|
|
|
|
$event->setProcessed(true);
|
|
|
|
break;
|
|
|
|
}
|
2011-01-23 17:02:16 +00:00
|
|
|
}
|
|
|
|
|
2011-01-24 15:46:04 +00:00
|
|
|
return $event;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function filter(Event $event, $value)
|
|
|
|
{
|
|
|
|
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);
|
2010-02-17 13:54:36 +00:00
|
|
|
}
|
2011-01-23 17:02:16 +00:00
|
|
|
|
2011-01-24 15:46:04 +00:00
|
|
|
$event->setReturnValue($value);
|
|
|
|
|
|
|
|
return $event;
|
2010-02-17 13:54:36 +00:00
|
|
|
}
|
|
|
|
}
|