Skip to content

Instantly share code, notes, and snippets.

@guilhermeblanco
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guilhermeblanco/11227131 to your computer and use it in GitHub Desktop.
Save guilhermeblanco/11227131 to your computer and use it in GitHub Desktop.
<?php
class Event
{
public $type;
public $data = null;
public $stopPropagation = false;
}
<?php
class EventManager
{
private $listenerList = array();
public function addListener($listener)
{
$this->listenerList[] = $listener;
}
public function dispatch(Event $event)
{
$type = $event->type;
$result = null;
foreach ($this->listenerList as $listener) {
if ($event->stopPropagation) {
break;
}
if (method_exists($listener, $type)) {
$result = $listener->$type($event);
}
}
return $result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment