public static function register($name, Closure $handler) { if (!is_array(static::$handlers)) { static::$handlers = array(); } if (!isset(static::$handlers[$name]) || !is_array(static::$handlers[$name])) { static::$handlers[$name] = array(); } static::$handlers[$name][] = $handler; }
/** * Constructor. * * Instantiate shutdown handler object. * * @param callback $callback * Callback to call on shutdown. * @param array $arguments * Arguments for the callback. * @param string $key * (Optional) Key for singleton destructor. If provided, only one * registered handler per key will run. */ public function __construct($callback, array $arguments = array(), $key = null) { // Register a PHP shutdown handler first time around. if (!isset(static::$handlers)) { $this->registerShutdownFunction(array(get_class($this), 'shutdown')); static::$handlers = array(); } // Check validity of the callback. Note, this triggers autoload of classes // if necessary. We do this to avoid potential fatal errors during the // shutdown phase. if (!static::isCallable($callback, false, $callback_name)) { throw new \RuntimeException(sprintf("Callback: '%s' is not callable", $callback_name)); } // Setup object properties. $this->callback = $callback; $this->arguments = $arguments; // ID must be non-numerical, so that PHP array indices won't shift // unexpectedly. $this->handlerId = ":" . (string) static::$counter++; // Register this handler. $this->reRegister($key); }
public static function unregisterAll() { static::$handlers = array(); static::$handlerPriority = array(); }