Sequenzia/lib/Rails/SystemExit/SystemExit.php

33 lines
655 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])) {
2013-10-26 17:53:37 +02:00
unset($this->callbacks[$name]);
2013-10-02 18:14:53 +02:00
return true;
} else {
return false;
}
}
public function run()
{
foreach ($this->callbacks as $callback) {
call_user_func($callback);
}
}
2013-10-26 17:53:37 +02:00
}