[EventDispatcher] removed the possibility to remove one listener for an event
This commit is contained in:
parent
d9295058b1
commit
4e5c99dab0
@ -3,7 +3,6 @@
|
||||
namespace Symfony\Bundle\FrameworkBundle;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher as BaseEventDispatcher;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/*
|
||||
|
@ -41,37 +41,19 @@ class EventDispatcher
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnects a listener for a given event name.
|
||||
* Disconnects all listeners for the given event name.
|
||||
*
|
||||
* @param string $name An event name
|
||||
* @param mixed|null $listener A PHP callable or null to disconnect all listeners
|
||||
*
|
||||
* @return mixed false if listener does not exist, null otherwise
|
||||
* @param string $name An event name
|
||||
*/
|
||||
public function disconnect($name, $listener = null)
|
||||
public function disconnect($name)
|
||||
{
|
||||
if (!isset($this->listeners[$name])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (null === $listener) {
|
||||
unset($this->listeners[$name]);
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($this->listeners[$name] as $priority => $callables) {
|
||||
foreach ($callables as $i => $callable) {
|
||||
if ($listener === $callable) {
|
||||
unset($this->listeners[$name][$priority][$i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($this->listeners[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies all listeners of a given event.
|
||||
*
|
||||
* @param Event $event A Event instance
|
||||
* @param Event $event An Event instance
|
||||
*
|
||||
* @return Event The Event instance
|
||||
*/
|
||||
@ -87,7 +69,7 @@ class EventDispatcher
|
||||
/**
|
||||
* Notifies all listeners of a given event until one returns a non null value.
|
||||
*
|
||||
* @param Event $event A Event instance
|
||||
* @param Event $event An Event instance
|
||||
*
|
||||
* @return Event The Event instance
|
||||
*/
|
||||
@ -106,8 +88,8 @@ class EventDispatcher
|
||||
/**
|
||||
* Filters a value by calling all listeners of a given event.
|
||||
*
|
||||
* @param Event $event A Event instance
|
||||
* @param mixed $value The value to be filtered
|
||||
* @param Event $event An Event instance
|
||||
* @param mixed $value The value to be filtered
|
||||
*
|
||||
* @return Event The Event instance
|
||||
*/
|
||||
@ -125,7 +107,7 @@ class EventDispatcher
|
||||
/**
|
||||
* Returns true if the given event name has some listeners.
|
||||
*
|
||||
* @param string $name The event name
|
||||
* @param string $name The event name
|
||||
*
|
||||
* @return Boolean true if some listeners are connected, false otherwise
|
||||
*/
|
||||
@ -137,7 +119,7 @@ class EventDispatcher
|
||||
/**
|
||||
* Returns all listeners associated with a given event name.
|
||||
*
|
||||
* @param string $name The event name
|
||||
* @param string $name The event name
|
||||
*
|
||||
* @return array An array of listeners
|
||||
*/
|
||||
|
@ -25,11 +25,6 @@ class EventDispatcherTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals(array('listenToBar', 'listenToBarBar'), $dispatcher->getListeners('bar'), '->connect() can connect several listeners for the same event name');
|
||||
|
||||
$dispatcher->connect('barbar', 'listenToBarBar');
|
||||
$dispatcher->disconnect('bar', 'listenToBarBar');
|
||||
$this->assertEquals(array('listenToBar'), $dispatcher->getListeners('bar'), '->disconnect() disconnects a listener for an event name');
|
||||
$this->assertEquals(array('listenToBarBar'), $dispatcher->getListeners('barbar'), '->disconnect() disconnects a listener for an event name');
|
||||
|
||||
$this->assertFalse($dispatcher->disconnect('foobar', 'listen'), '->disconnect() returns false if the listener does not exist');
|
||||
|
||||
$dispatcher->disconnect('bar');
|
||||
$this->assertEquals(array(), $dispatcher->getListeners('bar'), '->disconnect() without a listener disconnects all listeners of for an event name');
|
||||
|
Reference in New Issue
Block a user