Skip to content

Instantly share code, notes, and snippets.

@emir
Created May 31, 2017 00:24
Show Gist options
  • Select an option

  • Save emir/b52a382d932989ae6831932baf9914c3 to your computer and use it in GitHub Desktop.

Select an option

Save emir/b52a382d932989ae6831932baf9914c3 to your computer and use it in GitHub Desktop.
Without Visual Debts (Not my opinion)
<?php
class Event {
protected $events = [];
function listen($name, $handler)
{
$this->events[$name][] = $handler;
}
function fire($name)
{
if (! array_key_exists($name, $this->events)) {
return false;
}
foreach ($this->events[$name] as $event) {
$event();
}
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment