Skip to content

Instantly share code, notes, and snippets.

@ivan1911
Created July 12, 2015 07:40
Show Gist options
  • Save ivan1911/88a10a4a3181a07015d0 to your computer and use it in GitHub Desktop.
Save ivan1911/88a10a4a3181a07015d0 to your computer and use it in GitHub Desktop.
PHP EventManager template class
<?php
class EventManager
{
public $listeners = [];
public function register($eventName, $listener)
{
$this->listeners[$eventName][] = $listener;
}
public function fire($eventName, $data)
{
if (!empty($this->listeners[$eventName])) {
foreach ($this->listeners[$eventName] as $listener) {
call_user_func([$listener, $eventName], $data);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment