Sequenzia/lib/Rails/SystemExit/SystemExit.php

32 lines
653 B
PHP
Raw Normal View History

2013-10-02 18:14:53 +02:00
<?php
namespace Rails\SystemExit;
class SystemExit
{
protected $callbacks = [];
public function register(callable $callback, $name = '')
{
if ($name)
$this->callbacks[$name] = $callback;
else
$this->callbacks[] = $callback;
}
public function unregister($name)
{
if (isset($this->callbacks[$name])) {
unset($this->callbacks[$name];
return true;
} else {
return false;
}
}
public function run()
{
foreach ($this->callbacks as $callback) {
call_user_func($callback);
}
}
}