/** * Exception manager * It manages exceptions and decides what to do based on rules defined in the config file * * @param Exception $exception Instance of Exception * * This function is not invoked by the app. Instead of that, PHP interpreter invokes it * each time an exception occurs */ public static function PokelioExceptionHandler(Exception $exception) { //Get the error handling rules from configuration array $exceptionRule = Pokelio_Global::getConfig('EXCEPTION_HANDLING_RULE', 'Pokelio'); //Should we Inform to user? if ($exceptionRule->I == true) { $text = self::getExceptionPage($exception); if (SESSION_TYPE == 'WEB') { ob_clean(); echo "<pre>" . htmlentities($text) . "</pre>"; } else { echo $text; } } //Should we write to log file? if ($exceptionRule->L == true) { Pokelio_Log::write("Exception: " . $exception->getMessage() . " - " . $exception->getFile() . " (" . $exception->getLine() . ")", "Excep"); } }
/** * Error manager for fatal errors * It manages fatal errors * * This function is not invoked by the app. Instead of that, PHP interpreter invokes it * each time a fatal error occurs */ public static function PokelioFatalErrorHandler() { //Get the error handling rules from configuration array $errorRules = Pokelio_Global::getConfig('ERROR_HANDLING_RULES', 'Pokelio'); $error = null; $error = error_get_last(); //Handle error only in case it exists if ($error !== NULL) { $errno = $error["type"]; $errfile = $error["file"]; $errline = $error["line"]; $errstr = $error["message"]; //Inform to user if ($errorRules->{1}->I && $errorRules->all->I) { $text = self::getFatalErrorPage($errno, $errstr, $errfile, $errline); if (SESSION_TYPE == 'WEB') { ob_clean(); echo "<pre>" . htmlentities($text) . "</pre>"; } else { echo $text; } } if ($errorRules->{1}->I && $errorRules->all->L) { //Write to log file Pokelio_Log::write($errno . " " . $errstr . " " . $errfile . " " . $errline, $errno); } if ($errorRules->{1}->I && $errorRules->all->S) { //Stop execution? Pokelio_Application::abort(); } } }