Classes

File core/error/RawExceptionHandler.class.php

File core/error/RawExceptionHandler.class.php

 1:  2:  3:  4:  5:  6:  7:  8:  9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 
<?php
/**
 * @package     Core
 * @subpackage  Error
 * @copyright   &copy; 2005-2019 PHPBoost
 * @license     https://www.gnu.org/licenses/gpl-3.0.html GNU/GPL-3.0
 * @author      Loic ROUCHON <horn@phpboost.com>
 * @version     PHPBoost 5.2 - last update: 2014 12 22
 * @since       PHPBoost 3.0 - 2009 12 15
*/

class RawExceptionHandler
{
    /**
     * @var Exception
     */
    private $exception;

    /**
     * The user function needs to accept two parameters: the error code, and a string
     * describing the error.
     * @param Exception $exception contains the level of the error raised, as an integer
     * @return bool always true because we don't want the php default error handler to process the
     * error again
     */
    public function handle($exception)
    {
        $this->exception = $exception;
        $this->clean_output_buffer();
        $this->log();
        $this->raw_display();
    }

    private function clean_output_buffer()
    {
        AppContext::get_response()->clean_output();
    }

    private function log()
    {
        $information_to_log = $this->exception->getMessage() .
            "\n" . $this->exception->getTraceAsString();
        ErrorHandler::add_error_in_log($information_to_log, $this->exception->getFile(), $this->exception->getLine());
    }

    private function raw_display()
    {
        if (Debug::is_debug_mode_enabled())
        {
            Debug::fatal($this->exception);
        }
        else
        {
            die(ErrorHandler::FATAL_MESSAGE);
        }
    }
}
?>