From 7433dbd24cc6b5380e83b9cfb68966c8c440847b Mon Sep 17 00:00:00 2001 From: Awilum Date: Tue, 5 Mar 2013 23:15:28 +0200 Subject: [PATCH] Update Gelato to 1.0.1 --- libraries/Gelato/ClassLoader/ClassLoader.php | 13 ++++- .../Gelato/ErrorHandler/ErrorHandler.php | 44 ++++++++-------- .../Resources/Views/Errors/exception.php | 17 +++++++ libraries/Gelato/Gelato.php | 21 +++++--- libraries/Gelato/Log/Log.php | 51 +++++-------------- libraries/Gelato/changelog.txt | 8 +++ 6 files changed, 86 insertions(+), 68 deletions(-) diff --git a/libraries/Gelato/ClassLoader/ClassLoader.php b/libraries/Gelato/ClassLoader/ClassLoader.php index 1e336ba..5dd5e5e 100644 --- a/libraries/Gelato/ClassLoader/ClassLoader.php +++ b/libraries/Gelato/ClassLoader/ClassLoader.php @@ -124,7 +124,7 @@ class ClassLoader * Set an alias for a class. * * - * ClassLoader::registerNamespace('ClassNameAlias', 'ClassName'); + * ClassLoader::alias('ClassNameAlias', 'ClassName'); * * * @access public @@ -222,4 +222,15 @@ class ClassLoader return false; } + + /** + * Register the Gelato ClassLoader to the SPL autoload stack. + * + * @return void + */ + public static function register() + { + spl_autoload_register('ClassLoader::load', true, true); + } + } diff --git a/libraries/Gelato/ErrorHandler/ErrorHandler.php b/libraries/Gelato/ErrorHandler/ErrorHandler.php index 6a9ee60..f48d7f6 100644 --- a/libraries/Gelato/ErrorHandler/ErrorHandler.php +++ b/libraries/Gelato/ErrorHandler/ErrorHandler.php @@ -18,6 +18,25 @@ class ErrorHandler { + /** + * Error Levels + */ + public static $levels = 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_USER_NOTICE => 'Notice', + E_USER_WARNING => 'Warning', + E_USER_ERROR => 'Error', + /*E_DEPRECATED => 'Deprecated',*/ /* PHP 5.3 only */ + /*E_USER_DEPRECATED => 'Deprecated'*/ /* PHP 5.3 only */ + ); + /** * Protected constructor since this is a static class. * @@ -194,7 +213,7 @@ class ErrorHandler if (isset($entry['file'])) { $location['file'] = $entry['file']; $location['line'] = $entry['line']; - $location['code'] = static::highlightCode($entry['file'], $entry['line']); + $location['code'] = self::highlightCode($entry['file'], $entry['line']); } /** @@ -247,24 +266,7 @@ class ErrorHandler // 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'; + $error['type'] .= in_array($error['code'], array_keys(ErrorHandler::$levels)) ? ErrorHandler::$levels[$error['code']] : 'Unknown Error'; } else { $error['type'] = get_class($exception); } @@ -283,8 +285,8 @@ class ErrorHandler $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']); + $error['backtrace'] = self::formatBacktrace($error['backtrace']); + $error['highlighted'] = self::highlightCode($error['file'], $error['line']); Response::status(500); include 'Resources/Views/Errors/exception.php'; diff --git a/libraries/Gelato/ErrorHandler/Resources/Views/Errors/exception.php b/libraries/Gelato/ErrorHandler/Resources/Views/Errors/exception.php index 8f01ebd..3ac984d 100644 --- a/libraries/Gelato/ErrorHandler/Resources/Views/Errors/exception.php +++ b/libraries/Gelato/ErrorHandler/Resources/Views/Errors/exception.php @@ -11,6 +11,16 @@ font-size:14px; font-family:Verdana, Arial, Helvetica, "Nimbus Sans", FreeSans, Malayalam, sans-serif; margin:20px auto; + + -webkit-box-shadow: 1px 1px 18px rgba(50, 50, 50, 0.75); + -moz-box-shadow: 1px 1px 18px rgba(50, 50, 50, 0.75); + box-shadow: 1px 1px 18px rgba(50, 50, 50, 0.75); + + -webkit-border-radius: 5px; + -moz-border-radius: 5px; + border-radius: 5px; + + } #gelato-error pre { @@ -31,6 +41,13 @@ font-size:24px; font-weight:700; padding:10px; + + -moz-border-radius-topleft: 5px; + -webkit-border-top-left-radius: 5px; + border-top-left-radius: 5px; + -moz-border-radius-topright: 5px; + -webkit-border-top-right-radius: 5px; + border-top-right-radius: 5px; } #gelato-error .body { diff --git a/libraries/Gelato/Gelato.php b/libraries/Gelato/Gelato.php index 93ba911..0eef079 100644 --- a/libraries/Gelato/Gelato.php +++ b/libraries/Gelato/Gelato.php @@ -18,7 +18,14 @@ /** * The version of Gelato */ -define('GELATO_VERSION', '1.0.0'); +define('GELATO_VERSION', '1.0.1'); + +/** + * Define __DIR__ constant for PHP 5.2.x + */ +if ( ! defined('__DIR__')) { + define('__DIR__', dirname(__FILE__)); +} /** * Display Gelato Errors or not ? @@ -28,10 +35,10 @@ if ( ! defined('GELATO_DEVELOPMENT')) { } /** - * Use Gelato Autoloader or not ? + * Use Gelato Class Loader or not ? */ -if ( ! defined('GELATO_AUTOLOADER')) { - define('GELATO_AUTOLOADER', true); +if ( ! defined('GELATO_CLASS_LOADER')) { + define('GELATO_CLASS_LOADER', true); } /** @@ -110,8 +117,8 @@ ClassLoader::mapClasses(array( )); /** - * Register Gelato Autoloader + * Register Gelato Class Loader */ -if (GELATO_AUTOLOADER) { - spl_autoload_register('ClassLoader::load'); +if (GELATO_CLASS_LOADER) { + ClassLoader::register(); } diff --git a/libraries/Gelato/Log/Log.php b/libraries/Gelato/Log/Log.php index b80487e..4ec823e 100644 --- a/libraries/Gelato/Log/Log.php +++ b/libraries/Gelato/Log/Log.php @@ -24,38 +24,7 @@ class Log * @var string */ protected static $path = ''; - - /** - * Log levels. - * - * @var int - */ - const EMERGENCY = 1; - const ALERT = 2; - const CRITICAL = 3; - const ERROR = 4; - const WARNING = 5; - const NOTICE = 6; - const INFO = 7; - const DEBUG = 8; - - /** - * Log types. - * - * @var array - */ - protected static $types = array - ( - Log::EMERGENCY => 'emergency', - Log::ALERT => 'alert', - Log::CRITICAL => 'critical', - Log::ERROR => 'error', - Log::WARNING => 'warning', - Log::NOTICE => 'notice', - Log::INFO => 'info', - Log::DEBUG => 'debug', - ); - + /** * Protected constructor since this is a static class. * @@ -66,6 +35,13 @@ class Log // Nothing here } + /** + * Configure Log + * + * @access public + * @param string $setting The setting + * @param string $value The value + */ public static function configure($setting, $value) { if (property_exists("log", $setting)) Log::$$setting = $value; @@ -76,15 +52,12 @@ class Log * * @access public * @param string $message The message to write to the log - * @param int $type (optional) Message type * @return boolean */ - public static function write($message, $type = Log::ERROR) + public static function write($message) { - $file = rtrim(Log::$path, '/') . '/' . gmdate('Y_m_d') . '.log'; - - $message = '[' . gmdate('d-M-Y H:i:s') . '] ' . $message . PHP_EOL; - - return (bool) file_put_contents($file, $message, FILE_APPEND); + return (bool) file_put_contents(rtrim(Log::$path, '/') . '/' . gmdate('Y_m_d') . '.log', + '[' . gmdate('d-M-Y H:i:s') . '] ' . $message . PHP_EOL, + FILE_APPEND); } } diff --git a/libraries/Gelato/changelog.txt b/libraries/Gelato/changelog.txt index 976765a..9a78a9c 100644 --- a/libraries/Gelato/changelog.txt +++ b/libraries/Gelato/changelog.txt @@ -1,3 +1,11 @@ +Gelato 1.0.1, 2013-03-05 +------------------------ +- New constant GELATO_CLASS_LOADER instead of GELATO_AUTOLOADER +- ErrorHanler Class Improvements. +- Log Class Improvements. +- ClassLoader: new method register() added. +- Define __DIR__ constant for PHP 5.2.x + Gelato 1.0.0, 2013-02-26 ------------------------ - Initial release