mirror of
https://github.com/monstra-cms/monstra.git
synced 2025-08-03 11:47:51 +02:00
246
engine/Core.php
246
engine/Core.php
@@ -1,7 +1,7 @@
|
||||
<?php defined('MONSTRA_ACCESS') or die('No direct script access.');
|
||||
|
||||
/**
|
||||
* Main Monstra engine module. Core module.
|
||||
* Main Monstra Engine module.
|
||||
*
|
||||
* Monstra - Content Management System.
|
||||
* Site: mostra.org
|
||||
@@ -96,19 +96,18 @@ class Core
|
||||
array_walk_recursive($_REQUEST, 'stripslashesGPC');
|
||||
}
|
||||
|
||||
// Error handling for Developers only.
|
||||
if (Core::$environment != Core::PRODUCTION) {
|
||||
|
||||
// Set error handler
|
||||
set_error_handler('Core::errorHandler');
|
||||
|
||||
// Set fatal error handler
|
||||
register_shutdown_function('Core::fatalErrorHandler');
|
||||
|
||||
// Set exception handler
|
||||
set_exception_handler('Core::exceptionHandler');
|
||||
/**
|
||||
* Set Gelato Display Errors to False for Production environment.
|
||||
*/
|
||||
if (Core::$environment == Core::PRODUCTION) {
|
||||
define('GELATO_DISPLAY_ERRORS', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Include Gelato Library
|
||||
*/
|
||||
include ROOT . '/libraries/Gelato/Gelato.php';
|
||||
|
||||
// Start session
|
||||
Session::start();
|
||||
|
||||
@@ -253,228 +252,7 @@ class Core
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception Handler
|
||||
*
|
||||
* @param object $exception An exception object
|
||||
*/
|
||||
public static function exceptionHandler($exception)
|
||||
{
|
||||
// Empty output buffers
|
||||
while (ob_get_level() > 0) ob_end_clean();
|
||||
|
||||
// Send headers and output
|
||||
@header('Content-Type: text/html; charset=UTF-8');
|
||||
@header('HTTP/1.1 500 Internal Server Error');
|
||||
|
||||
// Get highlighted code
|
||||
$code = Core::highlightCode($exception->getFile(), $exception->getLine());
|
||||
|
||||
// Determine error type
|
||||
if ($exception instanceof ErrorException) {
|
||||
|
||||
$error_type = 'ErrorException: ';
|
||||
|
||||
$codes = array (
|
||||
E_ERROR => 'Fatal Error',
|
||||
E_PARSE => 'Parse Error',
|
||||
E_COMPILE_ERROR => 'Compile Error',
|
||||
E_COMPILE_WARNING => 'Compile Warning',
|
||||
E_STRICT => 'Strict Mode Error',
|
||||
E_NOTICE => 'Notice',
|
||||
E_WARNING => 'Warning',
|
||||
E_RECOVERABLE_ERROR => 'Recoverable Error',
|
||||
/*E_DEPRECATED => 'Deprecated',*/ /* PHP 5.3 */
|
||||
E_USER_NOTICE => 'Notice',
|
||||
E_USER_WARNING => 'Warning',
|
||||
E_USER_ERROR => 'Error',
|
||||
/*E_USER_DEPRECATED => 'Deprecated'*/ /* PHP 5.3 */
|
||||
);
|
||||
|
||||
$error_type .= in_array($exception->getCode(), array_keys($codes)) ? $codes[$exception->getCode()] : 'Unknown Error';
|
||||
} else {
|
||||
$error_type = get_class($exception);
|
||||
}
|
||||
|
||||
// Show exception if core environment is DEVELOPMENT
|
||||
if (Core::$environment == Core::DEVELOPMENT) {
|
||||
|
||||
// Development
|
||||
echo ("
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset='utf-8'>
|
||||
<title>Monstra</title>
|
||||
<style>
|
||||
* { margin: 0; padding: 0; }
|
||||
body { background-color: #EEE; }
|
||||
h1,h2,h3,p{font-family:Verdana;font-weight:lighter;margin:10px;}
|
||||
.exception {border: 1px solid #CCC; padding: 10px; background-color: #FFF; color: #333; margin:10px;}
|
||||
pre, .code {font-family: Courier, monospace; font-size:12px;margin:0px;padding:0px;}
|
||||
.highlighted {background-color: #f0eb96; font-weight: bold; border-top: 1px solid #ccc; border-bottom: 1px solid #ccc;}
|
||||
.code {background:#fff;border:1px solid #ccc;overflow:auto;}
|
||||
.line {display: inline-block; background-color: #EFEFEF; padding: 4px 8px 4px 8px; margin-right:10px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class='exception'>
|
||||
<h1>Monstra - ".$error_type."</h1>
|
||||
<p>".$exception->getMessage()."</p>
|
||||
<h2>Location</h2>
|
||||
<p>Exception thrown on line <code>".$exception->getLine()."</code> in <code>".$exception->getFile()."</code></p>
|
||||
");
|
||||
|
||||
if ( ! empty($code)) {
|
||||
echo '<div class="code">';
|
||||
foreach ($code as $line) {
|
||||
echo '<pre '; if ($line['highlighted']) { echo 'class="highlighted"'; } echo '><span class="line">' . $line['number'] . '</span>' . $line['code'] . '</pre>';
|
||||
}
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
echo '</div></body></html>';
|
||||
|
||||
} else {
|
||||
|
||||
// Production
|
||||
echo ("
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset='utf-8'>
|
||||
<title>Monstra</title>
|
||||
<style>
|
||||
* { margin: 0; padding: 0; }
|
||||
.exception {border: 1px solid #CCC; padding: 10px; background-color: #FFF; color: #333; margin:10px;}
|
||||
body { background-color: #EEE; font-family: sans-serif; font-size: 16px; line-height: 20px; margin: 40px; }
|
||||
h1,h2,h3,p{font-family:Verdana;font-weight:lighter;margin:10px;}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class='exception'>
|
||||
<h1>Oops!</h1>
|
||||
<p>An unexpected error has occurred.</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
");
|
||||
}
|
||||
|
||||
// Writes message to log
|
||||
@file_put_contents(LOGS . DS . gmdate('Y_m_d') . '.log',
|
||||
gmdate('Y/m/d H:i:s') . ' --- ' . '['.$error_type.']' . ' --- ' . $exception->getMessage() . ' --- ' . 'Exception thrown on line '.$exception->getLine().' in '.$exception->getFile() . "\n",
|
||||
FILE_APPEND);
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts errors to ErrorExceptions.
|
||||
*
|
||||
* @param integer $code The error code
|
||||
* @param string $message The error message
|
||||
* @param string $file The filename where the error occurred
|
||||
* @param integer $line The line number where the error occurred
|
||||
* @return boolean
|
||||
*/
|
||||
public static function errorHandler($code, $message, $file, $line)
|
||||
{
|
||||
// If isset error_reporting and $code then throw new error exception
|
||||
if ((error_reporting() & $code) !== 0) {
|
||||
throw new ErrorException($message, $code, 0, $file, $line);
|
||||
}
|
||||
|
||||
// Don't execute PHP internal error handler
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns an array of lines from a file.
|
||||
*
|
||||
* @param string $file File in which you want to highlight a line
|
||||
* @param integer $line Line number to highlight
|
||||
* @param integer $padding Number of padding lines
|
||||
* @return array
|
||||
*/
|
||||
protected static function highlightCode($file, $line, $padding = 5)
|
||||
{
|
||||
// Is file readable ?
|
||||
if ( ! is_readable($file)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Init vars
|
||||
$lines = array();
|
||||
$current_line = 0;
|
||||
|
||||
// Open file
|
||||
$handle = fopen($file, 'r');
|
||||
|
||||
// Read file
|
||||
while ( ! feof($handle)) {
|
||||
|
||||
$current_line++;
|
||||
|
||||
$temp = fgets($handle);
|
||||
|
||||
if ($current_line > $line + $padding) {
|
||||
break; // Exit loop after we have found what we were looking for
|
||||
}
|
||||
|
||||
if ($current_line >= ($line - $padding) && $current_line <= ($line + $padding)) {
|
||||
|
||||
$lines[] = array (
|
||||
'number' => str_pad($current_line, 4, ' ', STR_PAD_LEFT),
|
||||
'highlighted' => ($current_line === $line),
|
||||
'code' => Core::highlightString($temp),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Close
|
||||
fclose($handle);
|
||||
|
||||
// Return lines
|
||||
return $lines;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Highlight string
|
||||
*
|
||||
* @param string $string String
|
||||
* @return string
|
||||
*/
|
||||
protected static function highlightString($string)
|
||||
{
|
||||
return str_replace(array("\n", '<code>', '</code>', '<span style="color: #0000BB"><?php ', '#$@r4!/*'),
|
||||
array('', '', '', '<span style="color: #0000BB">', '/*'),
|
||||
highlight_string('<?php ' . str_replace('/*', '#$@r4!/*', $string), true));
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert errors not caught by the errorHandler to ErrorExceptions.
|
||||
*/
|
||||
public static function fatalErrorHandler()
|
||||
{
|
||||
// Get last error
|
||||
$error = error_get_last();
|
||||
|
||||
// If isset error then throw new error exception
|
||||
if (isset($error) && ($error['type'] === E_ERROR)) {
|
||||
|
||||
Core::exceptionHandler(new ErrorException($error['message'], $error['type'], 0, $error['file'], $error['line']));
|
||||
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize Monstra engine
|
||||
* Initialize Monstra Engine
|
||||
*
|
||||
* @return Core
|
||||
*/
|
||||
|
@@ -1,16 +1,21 @@
|
||||
<?php defined('MONSTRA_ACCESS') or die('No direct script access.');
|
||||
|
||||
/**
|
||||
* Monstra Library
|
||||
* Monstra Security module
|
||||
*
|
||||
* This source file is part of the Monstra Library. More information,
|
||||
* documentation and tutorials can be found at http://library.monstra.org
|
||||
*
|
||||
* @package Monstra
|
||||
*
|
||||
* @author Romanenko Sergey / Awilum
|
||||
* @copyright (c) 2012 - 2013 Romanenko Sergey / Awilum
|
||||
* @since 1.0.0
|
||||
* @package Monstra
|
||||
* @subpackage Engine
|
||||
* @author Romanenko Sergey / Awilum
|
||||
* @copyright 2012 Romanenko Sergey / Awilum
|
||||
* @version $Id$
|
||||
* @since 1.0.0
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||
* Monstra is free software. This version may have been modified pursuant
|
||||
* to the GNU General Public License, and as distributed it includes or
|
||||
* is derivative of works licensed under the GNU General Public License or
|
||||
* other free or open source software licenses.
|
||||
* See COPYING.txt for copyright notices and details.
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
class Security
|
||||
|
@@ -1,16 +1,21 @@
|
||||
<?php defined('MONSTRA_ACCESS') or die('No direct script access.');
|
||||
|
||||
/**
|
||||
* Monstra URI Module
|
||||
* Monstra Uri module
|
||||
*
|
||||
* This source file is part of the Monstra Library. More information,
|
||||
* documentation and tutorials can be found at http://library.monstra.org
|
||||
*
|
||||
* @package Monstra
|
||||
*
|
||||
* @author Romanenko Sergey / Awilum
|
||||
* @copyright (c) 2012 - 2013 Romanenko Sergey / Awilum
|
||||
* @since 1.0.0
|
||||
* @package Monstra
|
||||
* @subpackage Engine
|
||||
* @author Romanenko Sergey / Awilum
|
||||
* @copyright 2012 Romanenko Sergey / Awilum
|
||||
* @version $Id$
|
||||
* @since 1.0.0
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||
* Monstra is free software. This version may have been modified pursuant
|
||||
* to the GNU General Public License, and as distributed it includes or
|
||||
* is derivative of works licensed under the GNU General Public License or
|
||||
* other free or open source software licenses.
|
||||
* See COPYING.txt for copyright notices and details.
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
class Uri
|
||||
|
@@ -1,13 +1,28 @@
|
||||
<?php defined('MONSTRA_ACCESS') or die('No direct script access.');
|
||||
|
||||
/**
|
||||
* Include engine core
|
||||
* Report All Errors
|
||||
*
|
||||
* By setting error reporting to -1, we essentially force PHP to report
|
||||
* every error, and this is guranteed to show every error on future
|
||||
* releases of PHP. This allows everything to be fixed early!
|
||||
*/
|
||||
include ROOT . '/libraries/Gelato/Gelato.php';
|
||||
include ROOT . '/engine/Core.php';
|
||||
error_reporting(-1);
|
||||
|
||||
/**
|
||||
* Set core environment
|
||||
* Monstra requires PHP 5.2.0 or greater
|
||||
*/
|
||||
if (version_compare(PHP_VERSION, "5.2.0", "<")) {
|
||||
exit("Monstra requires PHP 5.2.0 or greater.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Include Monstra Engine Core
|
||||
*/
|
||||
include ROOT . DS .'engine'. DS .'Core.php';
|
||||
|
||||
/**
|
||||
* Set Monstra Core Environment
|
||||
*
|
||||
* Monstra has four predefined environments:
|
||||
* Core::DEVELOPMENT - The development environment.
|
||||
@@ -18,36 +33,6 @@ include ROOT . '/engine/Core.php';
|
||||
Core::$environment = Core::DEVELOPMENT;
|
||||
|
||||
/**
|
||||
* Monstra requires PHP 5.2.0 or greater
|
||||
*/
|
||||
if (version_compare(PHP_VERSION, "5.2.0", "<")) {
|
||||
exit("Monstra requires PHP 5.2.0 or greater.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Report Errors
|
||||
*/
|
||||
if (Core::$environment == Core::PRODUCTION) {
|
||||
|
||||
/**
|
||||
* Report All Errors
|
||||
*
|
||||
* By setting error reporting to -1, we essentially force PHP to report
|
||||
* every error, and this is guranteed to show every error on future
|
||||
* releases of PHP. This allows everything to be fixed early!
|
||||
*/
|
||||
error_reporting(0);
|
||||
|
||||
} else {
|
||||
|
||||
/**
|
||||
* Production environment
|
||||
*/
|
||||
error_reporting(-1);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize core
|
||||
* Initialize Core
|
||||
*/
|
||||
Core::init();
|
||||
|
@@ -36,8 +36,8 @@ if (file_exists('install.php')) {
|
||||
}
|
||||
} else {
|
||||
|
||||
// Load bootstrap file
|
||||
require_once(ROOT.'/engine/_init.php');
|
||||
// Load Engine init file
|
||||
require_once(ROOT. DS . 'engine'. DS . '_init.php');
|
||||
|
||||
// Check for maintenance mod
|
||||
if ('on' == Option::get('maintenance_status')) {
|
||||
|
276
libraries/Gelato/ErrorHandler.php
Normal file
276
libraries/Gelato/ErrorHandler.php
Normal file
@@ -0,0 +1,276 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Gelato Library
|
||||
*
|
||||
* This source file is part of the Gelato Library. More information,
|
||||
* documentation and tutorials can be found at http://gelato.monstra.org
|
||||
*
|
||||
* @package Gelato
|
||||
*
|
||||
* @author Romanenko Sergey / Awilum
|
||||
* @copyright (c) 2013 Romanenko Sergey / Awilum
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
class ErrorHandler
|
||||
{
|
||||
|
||||
/**
|
||||
* Protected constructor since this is a static class.
|
||||
*
|
||||
* @access protected
|
||||
*/
|
||||
protected function __construct()
|
||||
{
|
||||
// Nothing here
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of lines from a file.
|
||||
*
|
||||
* @access public
|
||||
* @param string $file File in which you want to highlight a line
|
||||
* @param int $line Line number to highlight
|
||||
* @param int $padding (optional) Number of padding lines
|
||||
* @return array
|
||||
*/
|
||||
protected static function highlightCode($file, $line, $padding = 6)
|
||||
{
|
||||
if (!is_readable($file)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$handle = fopen($file, 'r');
|
||||
$lines = array();
|
||||
$currentLine = 0;
|
||||
|
||||
while (!feof($handle)) {
|
||||
$currentLine++;
|
||||
|
||||
$temp = fgets($handle);
|
||||
|
||||
if ($currentLine > $line + $padding) {
|
||||
break; // Exit loop after we have found what we were looking for
|
||||
}
|
||||
|
||||
if ($currentLine >= ($line - $padding) && $currentLine <= ($line + $padding)) {
|
||||
$lines[] = array
|
||||
(
|
||||
'number' => str_pad($currentLine, 4, ' ', STR_PAD_LEFT),
|
||||
'highlighted' => ($currentLine === $line),
|
||||
'code' => ErrorHandler::highlightString($temp),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fclose($handle);
|
||||
|
||||
return $lines;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts errors to ErrorExceptions.
|
||||
*
|
||||
* @param integer $code The error code
|
||||
* @param string $message The error message
|
||||
* @param string $file The filename where the error occurred
|
||||
* @param integer $line The line number where the error occurred
|
||||
* @return boolean
|
||||
*/
|
||||
public static function errorHandler($code, $message, $file, $line)
|
||||
{
|
||||
// If isset error_reporting and $code then throw new error exception
|
||||
if ((error_reporting() & $code) !== 0) {
|
||||
throw new ErrorException($message, $code, 0, $file, $line);
|
||||
}
|
||||
|
||||
// Don't execute PHP internal error handler
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Highlight string
|
||||
*
|
||||
* @param string $string String
|
||||
* @return string
|
||||
*/
|
||||
protected static function highlightString($string)
|
||||
{
|
||||
$search = array("\r\n", "\n\r", "\r", "\n", '<code>', '</code>', '<span style="color: #0000BB"><?php ', '#$@r4!/*');
|
||||
$replace = array('', '', '', '', '', '', '<span style="color: #0000BB">', '/*');
|
||||
|
||||
return str_replace($search, $replace, highlight_string('<?php ' . str_replace('/*', '#$@r4!/*', $string), true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifies the backtrace array.
|
||||
*
|
||||
* @access protected
|
||||
* @param array $backtrace Array returned by the getTrace() method of an exception object
|
||||
* @return array
|
||||
*/
|
||||
protected static function formatBacktrace($backtrace)
|
||||
{
|
||||
if (is_array($backtrace) === false || count($backtrace) === 0) {
|
||||
return $backtrace;
|
||||
}
|
||||
|
||||
// Remove unnecessary info from backtrace
|
||||
|
||||
if ($backtrace[0]['function'] == '{closure}') {
|
||||
unset($backtrace[0]);
|
||||
}
|
||||
|
||||
// Format backtrace
|
||||
|
||||
$trace = array();
|
||||
|
||||
foreach ($backtrace as $entry) {
|
||||
|
||||
// Function
|
||||
|
||||
$function = '';
|
||||
|
||||
if (isset($entry['class'])) {
|
||||
$function .= $entry['class'] . $entry['type'];
|
||||
}
|
||||
|
||||
$function .= $entry['function'] . '()';
|
||||
|
||||
// Arguments
|
||||
|
||||
$arguments = array();
|
||||
|
||||
if (isset($entry['args']) && count($entry['args']) > 0) {
|
||||
foreach ($entry['args'] as $arg) {
|
||||
ob_start();
|
||||
|
||||
var_dump($arg);
|
||||
|
||||
$arg = htmlspecialchars(ob_get_contents());
|
||||
|
||||
ob_end_clean();
|
||||
|
||||
$arguments[] = $arg;
|
||||
}
|
||||
}
|
||||
|
||||
// Location
|
||||
|
||||
$location = array();
|
||||
|
||||
if (isset($entry['file'])) {
|
||||
$location['file'] = $entry['file'];
|
||||
$location['line'] = $entry['line'];
|
||||
$location['code'] = static::highlightCode($entry['file'], $entry['line']);
|
||||
}
|
||||
|
||||
// Compile into array
|
||||
|
||||
$trace[] = array
|
||||
(
|
||||
'function' => $function,
|
||||
'arguments' => $arguments,
|
||||
'location' => $location,
|
||||
);
|
||||
}
|
||||
|
||||
return $trace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert errors not caught by the errorHandler to ErrorExceptions.
|
||||
*/
|
||||
public static function fatalErrorHandler()
|
||||
{
|
||||
$e = error_get_last();
|
||||
|
||||
if ($e !== null && (error_reporting() & $e['type']) !== 0) {
|
||||
ErrorHandler::exception(new ErrorException($e['message'], $e['type'], 0, $e['file'], $e['line']));
|
||||
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles uncaught exceptions and returns a pretty error screen.
|
||||
*
|
||||
* @access public
|
||||
* @param Exception $exception An exception object
|
||||
*/
|
||||
public static function exception($exception)
|
||||
{
|
||||
try {
|
||||
// Empty output buffers
|
||||
|
||||
while(ob_get_level() > 0) ob_end_clean();
|
||||
|
||||
// Get exception info
|
||||
|
||||
$error['code'] = $exception->getCode();
|
||||
$error['message'] = $exception->getMessage();
|
||||
$error['file'] = $exception->getFile();
|
||||
$error['line'] = $exception->getLine();
|
||||
|
||||
// Determine error type
|
||||
|
||||
if ($exception instanceof ErrorException) {
|
||||
$error['type'] = 'ErrorException: ';
|
||||
|
||||
$codes = array
|
||||
(
|
||||
E_ERROR => 'Fatal Error',
|
||||
E_PARSE => 'Parse Error',
|
||||
E_COMPILE_ERROR => 'Compile Error',
|
||||
E_COMPILE_WARNING => 'Compile Warning',
|
||||
E_STRICT => 'Strict Mode Error',
|
||||
E_NOTICE => 'Notice',
|
||||
E_WARNING => 'Warning',
|
||||
E_RECOVERABLE_ERROR => 'Recoverable Error',
|
||||
/*E_DEPRECATED => 'Deprecated',*/
|
||||
E_USER_NOTICE => 'Notice',
|
||||
E_USER_WARNING => 'Warning',
|
||||
E_USER_ERROR => 'Error',
|
||||
/*E_USER_DEPRECATED => 'Deprecated'*/
|
||||
);
|
||||
|
||||
$error['type'] .= in_array($error['code'], array_keys($codes)) ? $codes[$error['code']] : 'Unknown Error';
|
||||
} else {
|
||||
$error['type'] = get_class($exception);
|
||||
}
|
||||
|
||||
// Write to error log
|
||||
|
||||
/*if () {
|
||||
Write here
|
||||
}*/
|
||||
|
||||
// Send headers and output
|
||||
@header('Content-Type: text/html; charset=UTF-8');
|
||||
|
||||
if (GELATO_DISPLAY_ERRORS) {
|
||||
$error['backtrace'] = $exception->getTrace();
|
||||
|
||||
if ($exception instanceof ErrorException) {
|
||||
$error['backtrace'] = array_slice($error['backtrace'], 1); //Remove call to error handler from backtrace
|
||||
}
|
||||
|
||||
$error['backtrace'] = static::formatBacktrace($error['backtrace']);
|
||||
$error['highlighted'] = static::highlightCode($error['file'], $error['line']);
|
||||
|
||||
Response::status(500);
|
||||
include 'Resources/Templates/exception.php';
|
||||
} else {
|
||||
Response::status(500);
|
||||
include 'Resources/Templates/error.php';
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
while(ob_get_level() > 0) ob_end_clean();
|
||||
|
||||
echo $e->getMessage() . ' in ' . $e->getFile() . ' (line ' . $e->getLine() . ').';
|
||||
}
|
||||
|
||||
exit(1);
|
||||
}
|
||||
}
|
@@ -13,6 +13,18 @@
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* The version of Gelato
|
||||
*/
|
||||
define('GELATO_VERSION', '1.0.0');
|
||||
|
||||
/**
|
||||
* Display Gelato Errors or not ?
|
||||
*/
|
||||
if ( ! defined('GELATO_DISPLAY_ERRORS')) {
|
||||
define('GELATO_DISPLAY_ERRORS', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Should we use the Gelato Autoloader to ensure the dependancies are automatically
|
||||
* loaded?
|
||||
@@ -22,7 +34,27 @@ if ( ! defined('GELATO_AUTOLOADER')) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Register autoload function
|
||||
* Load Gelato Error Handler
|
||||
*/
|
||||
require_once __DIR__ . '/ErrorHandler.php';
|
||||
|
||||
/**
|
||||
* Set Error Handler
|
||||
*/
|
||||
set_error_handler('ErrorHandler::errorHandler');
|
||||
|
||||
/**
|
||||
* Set Fatal Error Handler
|
||||
*/
|
||||
register_shutdown_function('ErrorHandler::fatalErrorHandler');
|
||||
|
||||
/**
|
||||
* Set Exception Handler
|
||||
*/
|
||||
set_exception_handler('ErrorHandler::exception');
|
||||
|
||||
/**
|
||||
* Register Gelato Autoloader
|
||||
*/
|
||||
if (GELATO_AUTOLOADER) {
|
||||
spl_autoload_register(array('Gelato', 'autoload'));
|
||||
@@ -33,12 +65,6 @@ if (GELATO_AUTOLOADER) {
|
||||
*/
|
||||
class Gelato
|
||||
{
|
||||
|
||||
/**
|
||||
* The version of Gelato
|
||||
*/
|
||||
const VERSION = '1.0.0';
|
||||
|
||||
/**
|
||||
* Registry of variables
|
||||
*
|
||||
|
225
libraries/Gelato/Resources/Views/Errors/exception.php
Normal file
225
libraries/Gelato/Resources/Views/Errors/exception.php
Normal file
@@ -0,0 +1,225 @@
|
||||
<style type="text/css">
|
||||
* { margin: 0; padding: 0; }
|
||||
#gelato-error
|
||||
{
|
||||
background:#eee;
|
||||
color:333;
|
||||
width:95%;
|
||||
margin:20px auto;
|
||||
font-size: 14px;
|
||||
font-family:Verdana, Arial, Helvetica, "Nimbus Sans", FreeSans, Malayalam, sans-serif;
|
||||
}
|
||||
#gelato-error pre {font-family:"Andale Mono", "Courier New", Courier;font-size:12px;margin:0px;padding:0px;}
|
||||
#gelato-error a {color:#cc0a0a;text-decoration:none;}
|
||||
#gelato-error .error {background:#cc0a0a;padding:10px;color:#fff;font-size:24px;font-weight:bold;}
|
||||
#gelato-error .body {border:0px solid #ccc;padding:10px;}
|
||||
#gelato-error .code {background:#fff;border:1px solid #ccc;overflow:auto;}
|
||||
#gelato-error .heading {background:#444;padding:10px;color:#fff;font-size:18px;font-weight:bold;}
|
||||
#gelato-error .line {background:#777;color:#fff;padding-left:4px;padding-right:4px;}
|
||||
#gelato-error .highlighted {background:#fceb71;border-top: 1px solid #ccc; border-bottom: 1px solid #ccc;}
|
||||
#gelato-error .backtrace {background:#fff;padding:10px;margin-bottom:10px;border:1px solid #ccc;}
|
||||
#gelato-error .backtrace ol {padding-left: 40px;}
|
||||
#gelato-error table {border-spacing:0;border-collapse: collapse;border-color: #ddd;border-width: 0 0 1px 1px;border-style: solid;}
|
||||
#gelato-error td {font-size:14px;background:#fff;border-color: #ddd;border-width: 1px 1px 0 0;border-style: solid;margin: 0;padding: 4px;}
|
||||
.pull-right {float: right;}
|
||||
</style>
|
||||
|
||||
<div id="gelato-error">
|
||||
|
||||
<div class="error">
|
||||
<?php echo $error['type']; ?><?php if(isset($error['code'])): ?> <span style="color:#e1e1e1;padding:0px">[<?php echo $error['code']; ?>]</span><?php endif; ?>
|
||||
<span class="pull-right">Gelato</span>
|
||||
</div>
|
||||
<div class="body">
|
||||
<strong>Message:</strong> <?php echo htmlspecialchars($error['message'], ENT_COMPAT, 'UTF-8', false); ?>
|
||||
|
||||
<?php if(!empty($error['file'])): ?>
|
||||
<br><br>
|
||||
<strong>Location:</strong> <?php echo $error['file']; ?> (line <?php echo $error['line']; ?>)
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if(!empty($error['highlighted'])): ?>
|
||||
<br><br>
|
||||
<div class="code">
|
||||
<?php foreach($error['highlighted'] as $line): ?>
|
||||
<pre<?php if($line['highlighted']): ?> class="highlighted"<?php endif; ?>><span class="line"><?php echo $line['number']; ?></span> <?php echo $line['code']; ?></pre>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<?php if(!empty($error['backtrace'])): ?>
|
||||
<div class="heading">
|
||||
Backtrace <a href="#" onclick="return toggle('backtrace', this);" style="float:right">+</a>
|
||||
</div>
|
||||
<div class="body" style="display:none;" id="backtrace">
|
||||
<?php foreach($error['backtrace'] as $trace): ?>
|
||||
<div class="backtrace">
|
||||
<p><strong>Function:</strong> <?php echo $trace['function']; ?></p>
|
||||
<?php if(!empty($trace['arguments'])): $id = md5(uniqid('', true)); ?>
|
||||
<p><strong>Arguments: [<a href="#" onclick="return toggle('<?php echo $id; ?>', this);">+</a>]</strong></p>
|
||||
<div style="display:none" id="<?php echo $id; ?>">
|
||||
<ol>
|
||||
<?php foreach($trace['arguments'] as $arg): ?>
|
||||
<li><pre><?php echo $arg; ?></pre></li>
|
||||
<?php endforeach; ?>
|
||||
</ol>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if(!empty($trace['location'])): $id = md5(uniqid('', true)); ?>
|
||||
<p><strong>Location:</strong> <?php echo $trace['location']['file']; ?> (<a href="#" onclick="return toggle('<?php echo $id; ?>');">line <?php echo $trace['location']['line']; ?></a>)</p>
|
||||
<div class="code" style="display:none" id="<?php echo $id; ?>">
|
||||
<?php foreach($trace['location']['code'] as $line): ?>
|
||||
<pre<?php if($line['highlighted']): ?> class="highlighted"<?php endif; ?>><span class="line"><?php echo $line['number']; ?></span> <?php echo $line['code']; ?></pre>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="heading">
|
||||
Superglobals <a href="#" onclick="return toggle('superglobals', this);" style="float:right">+</a>
|
||||
</div>
|
||||
<div class="body" style="display:none;" id="superglobals">
|
||||
|
||||
<?php if(!empty($_SERVER)): ?>
|
||||
<p><b>$_SERVER [<a href="#" onclick="return toggle('_server', this);">+</a>]</b></p>
|
||||
<div id="_server" style="display:none">
|
||||
<table width="100%">
|
||||
<?php foreach($_SERVER as $k => $v): ?>
|
||||
<tr>
|
||||
<td width="15%"><?php echo htmlspecialchars($k); ?></td>
|
||||
<td width="85%"><pre><?php ob_start(); var_dump($v); echo htmlspecialchars(ob_get_clean()); ?></pre></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if(!empty($_GET)): ?>
|
||||
<p><b>$_GET [<a href="#" onclick="return toggle('_get', this);">+</a>]</b></p>
|
||||
<div id="_get" style="display:none">
|
||||
<table width="100%">
|
||||
<?php foreach($_GET as $k => $v): ?>
|
||||
<tr>
|
||||
<td width="15%"><?php echo htmlspecialchars($k); ?></td>
|
||||
<td width="85%"><pre><?php ob_start(); var_dump($v); echo htmlspecialchars(ob_get_clean()); ?></pre></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if(!empty($_POST)): ?>
|
||||
<p><b>$_POST [<a href="#" onclick="return toggle('_post', this);">+</a>]</b></p>
|
||||
<div id="_post" style="display:none">
|
||||
<table width="100%">
|
||||
<?php foreach($_POST as $k => $v): ?>
|
||||
<tr>
|
||||
<td width="15%"><?php echo htmlspecialchars($k); ?></td>
|
||||
<td width="85%"><pre><?php ob_start(); var_dump($v); echo htmlspecialchars(ob_get_clean()); ?></pre></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if(!empty($_FILES)): ?>
|
||||
<p><b>$_FILES [<a href="#" onclick="return toggle('_files', this);">+</a>]</b></p>
|
||||
<div id="_files" style="display:none">
|
||||
<table width="100%">
|
||||
<?php foreach($_FILES as $k => $v): ?>
|
||||
<tr>
|
||||
<td width="15%"><?php echo htmlspecialchars($k); ?></td>
|
||||
<td width="85%"><pre><?php ob_start(); var_dump($v); echo htmlspecialchars(ob_get_clean()); ?></pre></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if(!empty($_COOKIE)): ?>
|
||||
<p><b>$_COOKIE [<a href="#" onclick="return toggle('_cookie', this);">+</a>]</b></p>
|
||||
<div id="_cookie" style="display:none">
|
||||
<table width="100%">
|
||||
<?php foreach($_COOKIE as $k => $v): ?>
|
||||
<tr>
|
||||
<td width="15%"><?php echo htmlspecialchars($k); ?></td>
|
||||
<td width="85%"><?php ob_start(); var_dump($v); echo htmlspecialchars(ob_get_clean()); ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if(!empty($_SESSION)): ?>
|
||||
<p><b>$_SESSION [<a href="#" onclick="return toggle('_session', this);">+</a>]</b></p>
|
||||
<div id="_session" style="display:none">
|
||||
<table width="100%">
|
||||
<?php foreach($_SESSION as $k => $v): ?>
|
||||
<tr>
|
||||
<td width="15%"><?php echo htmlspecialchars($k); ?></td>
|
||||
<td width="85%"><pre><?php ob_start(); var_dump($v); echo htmlspecialchars(ob_get_clean()); ?></pre></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if(!empty($_ENV)): ?>
|
||||
<p><b>$_ENV [<a href="#" onclick="return toggle('_env', this);">+</a>]</b></p>
|
||||
<div id="_env" style="display:none">
|
||||
<table width="100%">
|
||||
<?php foreach($_ENV as $k => $v): ?>
|
||||
<tr>
|
||||
<td width="15%"><?php echo htmlspecialchars($k); ?></td>
|
||||
<td width="85%"><pre><?php ob_start(); var_dump($v); echo htmlspecialchars(ob_get_clean()); ?></pre></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<div class="heading">
|
||||
Included Files <a href="#" onclick="return toggle('files', this);" style="float:right">+</a>
|
||||
</div>
|
||||
<div class="body" style="display:none;" id="files">
|
||||
<table width="100%">
|
||||
<?php foreach(get_included_files() as $k => $v): ?>
|
||||
<tr>
|
||||
<td width="5%"><?php echo $k + 1; ?></td>
|
||||
<td width="95%"><?php echo $v; ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div style="padding-top:20px;padding-bottom:20px; padding-left:10px;"><a href="http://gelato.monstra.org">Gelato Library</a></div>
|
||||
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
function toggle(id, link)
|
||||
{
|
||||
var div = document.getElementById(id);
|
||||
|
||||
if (div.style.display == "none") {
|
||||
if (link != null) {
|
||||
link.innerHTML = '-';
|
||||
}
|
||||
|
||||
div.style.display = "block";
|
||||
} else {
|
||||
if (link != null) {
|
||||
link.innerHTML = '+';
|
||||
}
|
||||
|
||||
div.style.display = "none";
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
</script>
|
69
libraries/Gelato/Resources/Views/Errors/production.php
Normal file
69
libraries/Gelato/Resources/Views/Errors/production.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="">
|
||||
<title>Error</title>
|
||||
|
||||
<style type="text/css">
|
||||
|
||||
body
|
||||
{
|
||||
height:100%;
|
||||
background:#eee;
|
||||
padding:0px;
|
||||
margin:0px;
|
||||
height: 100%;
|
||||
font-size: 100%;
|
||||
color:#333;
|
||||
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
|
||||
line-height: 100%;
|
||||
}
|
||||
a
|
||||
{
|
||||
color:#0088cc;
|
||||
text-decoration:none;
|
||||
}
|
||||
a:hover
|
||||
{
|
||||
color:#005580;
|
||||
text-decoration:underline;
|
||||
}
|
||||
h1
|
||||
{
|
||||
font-size: 4em;
|
||||
}
|
||||
small
|
||||
{
|
||||
font-size: 0.7em;
|
||||
color: #999;
|
||||
font-weight: normal;
|
||||
}
|
||||
hr
|
||||
{
|
||||
border:0px;
|
||||
border-bottom:1px #ddd solid;
|
||||
}
|
||||
#message
|
||||
{
|
||||
width: 700px;
|
||||
margin: 15% auto;
|
||||
}
|
||||
#back-home
|
||||
{
|
||||
bottom:0px;
|
||||
right:0px;
|
||||
position:absolute;
|
||||
padding:10px;
|
||||
}
|
||||
</style>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="message">
|
||||
<h1>Error</h1>
|
||||
<hr>
|
||||
<p>Aw, snap! An error has occurred while processing your request.</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user