Example #1
0
    /**
     * Default exception handler
     *
     * When this handler is used, input_manager and output_manager singleton instances already
     * exist in the memory and can be used.
     *
     * @param Exception $e uncaught exception
     */
    public static function default_exception_handler(Exception $e)
    {
        $worker = worker::instance();
        $worker->log_exception($e);
        $output = output_manager::instance();
        $output->exception($e);
    }
}
////////////////////////////////////////////////////////////////////////////////
// Check if the script is actually executed or if it was just included by someone
// else - typically by the PHPUnit. This is a PHP alternative to the Python's
// if __name__ == '__main__'
if (!debug_backtrace()) {
    // We are executed by the SAPI.
    exception_handlers::set_handler('bootstrap');
    // Initialize the worker class to actually make the job.
    $worker = worker::instance();
    exception_handlers::set_handler('default');
    // Lights, Camera, Action!
    $worker->execute();
} else {
    // We are included - probably by some unit testing framework. Do nothing.
}