1
0
mirror of https://github.com/e107inc/e107.git synced 2025-05-03 18:59:45 +02:00
php-e107/lib/PriorityCallbacks.php
Nick Liu 952c6e5890
PriorityCallbacks: Execute callbacks before Codeception's
GitPreparer now registers a "priority" register_shutdown_function
callback in order to clean up in case of a fatal error.
2018-11-01 06:57:38 -05:00

46 lines
797 B
PHP

<?php
/**
* Execute callbacks before Codeception does
*/
class PriorityCallbacks
{
/** @var array */
private $shutdown_functions = [];
private function __construct()
{
register_shutdown_function([$this, 'call_shutdown_functions']);
}
public static function instance()
{
static $instance = null;
if (!$instance instanceof self)
{
$instance = new static();
}
return $instance;
}
public function call_shutdown_functions()
{
foreach ($this->shutdown_functions as $shutdown_function)
{
call_user_func($shutdown_function);
}
}
public function register_shutdown_function($callable)
{
$this->shutdown_functions[] = $callable;
}
private function __clone() {}
private function __sleep() {}
private function __wakeup() {}
}
PriorityCallbacks::instance();