/** * Disable Eight PHP error handling. * * @return void */ public static function disable() { if (Eight_Exception_PHP::$enabled) { restore_error_handler(); Event::clear('system.shutdown', array('Eight_Exception_PHP', 'shutdown_handler')); Eight_Exception_PHP::$enabled = FALSE; } }
/** * Catches errors that are not caught by the error handler, such as E_PARSE. * * @uses Eight_Exception::handle() * @return void */ public static function shutdown_handler() { if (!Eight::$instance) { // Do not execute when not active return; } if (Eight::$errors and $error = error_get_last() and in_array($error['type'], Eight::$shutdown_errors)) { // Clean the output buffer ob_get_level() && ob_clean(); // Fake an exception for nice debugging Eight_Exception_PHP::handle(new Eight_Exception_PHP(0, $error['message'], $error['file'], $error['line'])); // Shutdown now to avoid a "death loop" exit(1); } }
/** * Eight output handler. * * @param string current output buffer * @return string */ public static function output_buffer($output) { if (!Event::has_run('system.send_headers')) { // Run the send_headers event, specifically for cookies being set Event::run('system.send_headers'); } // Set final output self::$output = $output; // Look for errors in the output buffer if (!self::$configuration['core']['display_errors'] && self::$configuration['core']['catch_all_errors']) { if (preg_match('#<phperror>.*</phperror>#is', self::$output, $matches)) { // We only care about the first error $match = $matches[0]; // Pull some info out of the error preg_match('#error:(.*)\\ in\\ (.*)\\ on\\ line ([0-9]+)#i', strip_tags($match), $matches); $error = new Eight_Exception_PHP(E_ERROR, trim($matches[1]), trim($matches[2]), trim($matches[3])); // Log the error self::log('error', Eight_Exception_PHP::text($error)); self::log_save(); // Show the pretty error page self::$output = file_get_contents(self::find_file('views', 'eight/error_disabled', TRUE)); } } // Set and return the final output return self::$output; }
/** * Cleans up the PHP environment. Disables error/exception handling and the * auto-loading method and closes the output buffer. * * This method does not need to be called during normal system execution, * however in some advanced situations it can be helpful. */ public static function cleanup() { static $run; // Only run this function once if ($run === TRUE) { return; } $run = TRUE; // Using Eight Errors? Disable them since we're finished. if (Eight::$errors === TRUE) { Eight_Exception::disable(); Eight_Exception_PHP::disable(); } spl_autoload_unregister(array('Eight', 'auto_load')); Eight::close_buffers(); }