EventEmitter::listeners() returns "[" when no listeners available. #6

Closed
wants to merge 3 commits into
from
Jump to file or symbol
Failed to load files and symbols.
+11 −11
Split
@@ -28,19 +28,19 @@
class EventEmitter
{
- protected $listeners = array();
+ protected $_listeners = array();
public function on($event, $listener)
{
if (!is_callable($listener)) {
throw new \InvalidArgumentException('The provided listener was not a valid callable.');
}
- if (!isset($this->listeners[$event])) {
- $this->listeners[$event] = array();
+ if (!isset($this->_listeners[$event])) {
+ $this->_listeners[$event] = array();
}
- $this->listeners[$event][] = $listener;
+ $this->_listeners[$event][] = $listener;
}
public function once($event, $listener)
@@ -58,25 +58,25 @@ public function once($event, $listener)
public function removeListener($event, $listener)
{
- if (isset($this->listeners[$event])) {
- if (false !== $index = array_search($listener, $this->listeners[$event], true)) {
- unset($this->listeners[$event][$index]);
+ if (isset($this->_listeners[$event])) {
+ if (false !== $index = array_search($listener, $this->_listeners[$event], true)) {
+ unset($this->_listeners[$event][$index]);
}
}
}
public function removeAllListeners($event = null)
{
if ($event !== null) {
- unset($this->listeners[$event]);
+ unset($this->_listeners[$event]);
} else {
- $this->listeners = array();
+ $this->_listeners = array();
}
}
public function listeners($event)
{
- return isset($this->listeners[$event]) ? $this->listeners[$event] : array();
+ return isset($this->_listeners[$event]) ? $this->_listeners[$event] : array();
}
public function emit($event, array $arguments = array())
@@ -88,7 +88,7 @@ public function listeners($event)
{
$matchedListeners = array();
- foreach ($this->listeners as $name => $listeners) {
+ foreach ($this->_listeners as $name => $listeners) {
foreach ($listeners as $listener) {
if ($this->matchEventName($event, $name)) {
$matchedListeners[] = $listener;