class EventsEmitter
Events emitter class. An instance of this class is used by Parser and Scanner to emit events and attach listeners to them
@author Marco Marchiò <marco.mm89@gmail.com>
Hierarchy
- class \Peast\Syntax\EventsEmitter
Expanded class hierarchy of EventsEmitter
File
-
vendor/
mck89/ peast/ lib/ Peast/ Syntax/ EventsEmitter.php, line 18
Namespace
Peast\SyntaxView source
class EventsEmitter {
/**
* Events registry array
*
* @var array
*/
protected $eventsRegistry = array();
/**
* Attaches a listener function to the given event
*
* @param string $event Event name
* @param callable $listener Listener function
*
* @return $this
*/
public function addListener($event, $listener) {
if (!isset($this->eventsRegistry[$event])) {
$this->eventsRegistry[$event] = array();
}
$this->eventsRegistry[$event][] = $listener;
return $this;
}
/**
* Fires an event
*
* @param string $event Event name
* @param array $args Arguments to pass to functions attached to the
* event
*
* @return $this
*/
public function fire($event, $args = array()) {
if (isset($this->eventsRegistry[$event])) {
foreach ($this->eventsRegistry[$event] as $listener) {
call_user_func_array($listener, $args);
}
}
return $this;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
EventsEmitter::$eventsRegistry | protected | property | Events registry array |
EventsEmitter::addListener | public | function | Attaches a listener function to the given event |
EventsEmitter::fire | public | function | Fires an event |