diff --git a/libraries/Gelato/Agent.php b/libraries/Gelato/Agent/Agent.php similarity index 100% rename from libraries/Gelato/Agent.php rename to libraries/Gelato/Agent/Agent.php diff --git a/libraries/Gelato/Alert.php b/libraries/Gelato/Alert.php deleted file mode 100644 index 5d683c0..0000000 --- a/libraries/Gelato/Alert.php +++ /dev/null @@ -1,88 +0,0 @@ - - * Alert::success('Message here...'); - * - * - * @param string $message Message - * @param integer $time Time - */ - public static function success($message, $time = 3000) - { - // Redefine vars - $message = (string) $message; - $time = (int) $time; - - echo '
'.$message.'
- '; - } - - /** - * Show warning message - * - * - * Alert::warning('Message here...'); - * - * - * @param string $message Message - * @param integer $time Time - */ - public static function warning($message, $time = 3000) - { - // Redefine vars - $message = (string) $message; - $time = (int) $time; - - echo '
'.$message.'
- '; - } - - /** - * Show error message - * - * - * Alert::error('Message here...'); - * - * - * @param string $message Message - * @param integer $time Time - */ - public static function error($message, $time = 3000) - { - // Redefine vars - $message = (string) $message; - $time = (int) $time; - - echo '
'.$message.'
- '; - } - -} diff --git a/libraries/Gelato/Arr.php b/libraries/Gelato/Arr/Arr.php similarity index 100% rename from libraries/Gelato/Arr.php rename to libraries/Gelato/Arr/Arr.php diff --git a/libraries/Gelato/Cache.php b/libraries/Gelato/Cache/Cache.php similarity index 100% rename from libraries/Gelato/Cache.php rename to libraries/Gelato/Cache/Cache.php diff --git a/libraries/Gelato/ClassLoader/ClassLoader.php b/libraries/Gelato/ClassLoader/ClassLoader.php new file mode 100644 index 0000000..2bdd903 --- /dev/null +++ b/libraries/Gelato/ClassLoader/ClassLoader.php @@ -0,0 +1,205 @@ + $path) + { + static::$classes[$name] = $path; + } + } + + /** + * Adds a PSR-0 directory path. + * + * @access public + * @param string $path Path to PSR-0 directory + */ + public static function directory($path) + { + static::$directories[] = rtrim($path, '/'); + echo rtrim($path, '/'); + } + + /** + * Registers a namespace. + * + * @access public + * @param string $namespace Namespace + * @param string $path Path + */ + public static function registerNamespace($namespace, $path) + { + static::$namespaces[trim($namespace, '\\') . '\\'] = rtrim($path, '/'); + } + + /** + * Set an alias for a class. + * + * @access public + * @param string $alias Class alias + * @param string $className Class name + */ + public static function alias($alias, $className) + { + static::$aliases[$alias] = $className; + } + + /** + * Try to load a PSR-0 compatible class. + * + * @access protected + * @param string $className Class name + * @param string $directory (Optional) Overrides the array of PSR-0 paths + * @return boolean + */ + protected static function loadPSR0($className, $directory = null) + { + $classPath = ''; + + if(($pos = strripos($className, '\\')) !== false) + { + $namespace = substr($className, 0, $pos); + $className = substr($className, $pos + 1); + $classPath = str_replace('\\', '/', $namespace) . '/'; + } + + $classPath .= str_replace('_', '/', $className) . '.php'; + + $directories = ($directory === null) ? static::$directories : array($directory); + + foreach($directories as $directory) + { + if(file_exists($directory . '/' . $classPath)) + { + include($directory . '/' . $classPath); + + return true; + } + } + + return false; + } + + + /** + * Autoloader. + * + * @access public + * @param string $className Class name + * @return boolean + */ + public static function load($className) + { + $className = ltrim($className, '\\'); + + // Try to autoload an aliased class + + if(isset(static::$aliases[$className])) + { + return class_alias(static::$aliases[$className], $className); + } + + // Try to load a mapped class + + if(isset(static::$classes[$className]) && file_exists(static::$classes[$className])) + { + include static::$classes[$className]; + + return true; + } + + // Try to load class from a registered namespace + + foreach(static::$namespaces as $namespace => $path) + { + if(strpos($className, $namespace) === 0) + { + if(static::loadPSR0(substr($className, strlen($namespace)), $path)) + { + return true; + } + } + } + + // Try to load a PSR-0 compatible class + // The second call to the loadPSR0 method is used to autoload legacy code + if (static::loadPSR0($className) || static::loadPSR0(strtolower($className))) + { + return true; + } + + return false; + } +} \ No newline at end of file diff --git a/libraries/Gelato/Cookie.php b/libraries/Gelato/Cookie/Cookie.php similarity index 100% rename from libraries/Gelato/Cookie.php rename to libraries/Gelato/Cookie/Cookie.php diff --git a/libraries/Gelato/Curl.php b/libraries/Gelato/Curl/Curl.php similarity index 100% rename from libraries/Gelato/Curl.php rename to libraries/Gelato/Curl/Curl.php diff --git a/libraries/Gelato/Date.php b/libraries/Gelato/Date/Date.php similarity index 100% rename from libraries/Gelato/Date.php rename to libraries/Gelato/Date/Date.php diff --git a/libraries/Gelato/Debug.php b/libraries/Gelato/Debug/Debug.php similarity index 100% rename from libraries/Gelato/Debug.php rename to libraries/Gelato/Debug/Debug.php diff --git a/libraries/Gelato/ErrorHandler.php b/libraries/Gelato/ErrorHandler/ErrorHandler.php similarity index 98% rename from libraries/Gelato/ErrorHandler.php rename to libraries/Gelato/ErrorHandler/ErrorHandler.php index 874e1cd..5f6e21b 100644 --- a/libraries/Gelato/ErrorHandler.php +++ b/libraries/Gelato/ErrorHandler/ErrorHandler.php @@ -260,10 +260,10 @@ class ErrorHandler $error['highlighted'] = static::highlightCode($error['file'], $error['line']); Response::status(500); - include 'Resources/Templates/exception.php'; + include 'Resources/Views/Errors/exception.php'; } else { Response::status(500); - include 'Resources/Templates/error.php'; + include 'Resources/Views/Errors/error.php'; } } catch (Exception $e) { while(ob_get_level() > 0) ob_end_clean(); diff --git a/libraries/Gelato/Resources/Views/Errors/exception.php b/libraries/Gelato/ErrorHandler/Resources/Views/Errors/exception.php similarity index 100% rename from libraries/Gelato/Resources/Views/Errors/exception.php rename to libraries/Gelato/ErrorHandler/Resources/Views/Errors/exception.php diff --git a/libraries/Gelato/Resources/Views/Errors/production.php b/libraries/Gelato/ErrorHandler/Resources/Views/Errors/production.php similarity index 100% rename from libraries/Gelato/Resources/Views/Errors/production.php rename to libraries/Gelato/ErrorHandler/Resources/Views/Errors/production.php diff --git a/libraries/Gelato/Dir.php b/libraries/Gelato/FileSystem/Dir.php similarity index 100% rename from libraries/Gelato/Dir.php rename to libraries/Gelato/FileSystem/Dir.php diff --git a/libraries/Gelato/File.php b/libraries/Gelato/FileSystem/File.php similarity index 100% rename from libraries/Gelato/File.php rename to libraries/Gelato/FileSystem/File.php diff --git a/libraries/Gelato/Form.php b/libraries/Gelato/Form/Form.php similarity index 100% rename from libraries/Gelato/Form.php rename to libraries/Gelato/Form/Form.php diff --git a/libraries/Gelato/Gelato.php b/libraries/Gelato/Gelato.php index 4e80e45..0ceb401 100644 --- a/libraries/Gelato/Gelato.php +++ b/libraries/Gelato/Gelato.php @@ -25,18 +25,10 @@ if ( ! defined('GELATO_DISPLAY_ERRORS')) { define('GELATO_DISPLAY_ERRORS', true); } -/** - * Should we use the Gelato Autoloader to ensure the dependancies are automatically - * loaded? - */ -if ( ! defined('GELATO_AUTOLOADER')) { - define('GELATO_AUTOLOADER', true); -} - /** * Load Gelato Error Handler */ -require_once __DIR__ . '/ErrorHandler.php'; +require_once __DIR__ . '/ErrorHandler/ErrorHandler.php'; /** * Set Error Handler @@ -54,90 +46,42 @@ register_shutdown_function('ErrorHandler::fatalErrorHandler'); set_exception_handler('ErrorHandler::exception'); /** - * Register Gelato Autoloader - */ -if (GELATO_AUTOLOADER) { - spl_autoload_register(array('Gelato', 'autoload')); -} + * Gelato Class Loader + */ +require_once __DIR__ . '/ClassLoader/ClassLoader.php'; /** - * Gelato + * Map all Gelato Classes */ -class Gelato -{ - /** - * Registry of variables - * - * @var array - */ - private static $registry = array(); +ClassLoader::mapClasses(array( + 'Agent' => __DIR__.'/Agent/Agent.php', + 'Arr' => __DIR__.'/Arr/Arr.php', + 'Cache' => __DIR__.'/Cache/Cache.php', + 'Cookie' => __DIR__.'/Cookie/Cookie.php', + 'Curl' => __DIR__.'/Curl/Curl.php', + 'Date' => __DIR__.'/Date/Date.php', + 'Debug' => __DIR__.'/Debug/Debug.php', + 'File' => __DIR__.'/FileSystem/File.php', + 'Dir' => __DIR__.'/FileSystem/Dir.php', + 'Form' => __DIR__.'/Form/Form.php', + 'Html' => __DIR__.'/Html/Html.php', + 'Image' => __DIR__.'/Image/Image.php', + 'Inflector' => __DIR__.'/Inflector/Inflector.php', + 'Minify' => __DIR__.'/Minify/Minify.php', + 'Notification' => __DIR__.'/Notification/Notification.php', + 'Number' => __DIR__.'/Number/Number.php', + 'Registry' => __DIR__.'/Registry/Registry.php', + 'Request' => __DIR__.'/Http/Request.php', + 'Response' => __DIR__.'/Http/Response.php', + 'Token' => __DIR__.'/Security/Token.php', + 'Text' => __DIR__.'/Text/Text.php', + 'Session' => __DIR__.'/Session/Session.php', + 'Url' => __DIR__.'/Url/Url.php', + 'Valid' => __DIR__.'/Validation/Valid.php', + 'Zip' => __DIR__.'/Zip/Zip.php', +)); - /** - * Gelato Autload - */ - public static function autoload($className) - { - $path = dirname(realpath(__FILE__)); - - $className = ltrim($className, '\\'); - $fileName = ''; - $namespace = ''; - if ($lastNsPos = strrpos($className, '\\')) { - $namespace = substr($className, 0, $lastNsPos); - $className = substr($className, $lastNsPos + 1); - $fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR; - } - $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; - - require $path.DIRECTORY_SEPARATOR.$fileName; - } - - /** - * Checks if an object with this name is in the registry. - * - * @return bool - * @param string $name The name of the registry item to check for existence. - */ - public static function exists($name) - { - return isset(Gelato::$registry[(string) $name]); - } - - /** - * Registers a given value under a given name. - * - * @param string $name The name of the value to store. - * @param mixed[optional] $value The value that needs to be stored. - */ - public static function set($name, $value = null) - { - // redefine name - $name = (string) $name; - - // delete item - if ($value === null) { - unset(Gelato::$registry[$name]); - } else { - Gelato::$registry[$name] = $value; - - return Gelato::get($name); - } - } - - /** - * Fetch an item from the registry. - * - * @return mixed - * @param string $name The name of the item to fetch. - */ - public static function get($name) - { - $name = (string) $name; - - if ( ! isset(Gelato::$registry[$name])) { - throw new RuntimeException('No item "' . $name . '" exists in the registry.'); - } - - return Gelato::$registry[$name]; - } -} +/** + * Register Gelato Autoloader + */ +spl_autoload_register('ClassLoader::load'); \ No newline at end of file diff --git a/libraries/Gelato/Html.php b/libraries/Gelato/Html/Html.php similarity index 100% rename from libraries/Gelato/Html.php rename to libraries/Gelato/Html/Html.php diff --git a/libraries/Gelato/Request.php b/libraries/Gelato/Http/Request.php similarity index 100% rename from libraries/Gelato/Request.php rename to libraries/Gelato/Http/Request.php diff --git a/libraries/Gelato/Response.php b/libraries/Gelato/Http/Response.php similarity index 59% rename from libraries/Gelato/Response.php rename to libraries/Gelato/Http/Response.php index 547d221..8bc0a77 100644 --- a/libraries/Gelato/Response.php +++ b/libraries/Gelato/Http/Response.php @@ -21,11 +21,9 @@ class Response * @var array */ public static $messages = array( - // Informational 1xx 100 => 'Continue', 101 => 'Switching Protocols', - - // Success 2xx + 102 => 'Processing', // RFC2518 200 => 'OK', 201 => 'Created', 202 => 'Accepted', @@ -33,18 +31,18 @@ class Response 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content', - - // Redirection 3xx + 207 => 'Multi-Status', // RFC4918 + 208 => 'Already Reported', // RFC5842 + 226 => 'IM Used', // RFC3229 300 => 'Multiple Choices', 301 => 'Moved Permanently', - 302 => 'Found', // 1.1 + 302 => 'Found', 303 => 'See Other', 304 => 'Not Modified', 305 => 'Use Proxy', - // 306 is deprecated but reserved + 306 => 'Reserved', 307 => 'Temporary Redirect', - - // Client Error 4xx + 308 => 'Permanent Redirect', // RFC-reschke-http-status-308-07 400 => 'Bad Request', 401 => 'Unauthorized', 402 => 'Payment Required', @@ -63,15 +61,26 @@ class Response 415 => 'Unsupported Media Type', 416 => 'Requested Range Not Satisfiable', 417 => 'Expectation Failed', - - // Server Error 5xx + 418 => 'I\'m a teapot', // RFC2324 + 422 => 'Unprocessable Entity', // RFC4918 + 423 => 'Locked', // RFC4918 + 424 => 'Failed Dependency', // RFC4918 + 425 => 'Reserved for WebDAV advanced collections expired proposal', // RFC2817 + 426 => 'Upgrade Required', // RFC2817 + 428 => 'Precondition Required', // RFC6585 + 429 => 'Too Many Requests', // RFC6585 + 431 => 'Request Header Fields Too Large', // RFC6585 500 => 'Internal Server Error', 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Timeout', 505 => 'HTTP Version Not Supported', - 509 => 'Bandwidth Limit Exceeded' + 506 => 'Variant Also Negotiates (Experimental)', // RFC2295 + 507 => 'Insufficient Storage', // RFC4918 + 508 => 'Loop Detected', // RFC5842 + 510 => 'Not Extended', // RFC2774 + 511 => 'Network Authentication Required', // RFC6585 ); /** diff --git a/libraries/Gelato/Image.php b/libraries/Gelato/Image/Image.php similarity index 100% rename from libraries/Gelato/Image.php rename to libraries/Gelato/Image/Image.php diff --git a/libraries/Gelato/Inflector.php b/libraries/Gelato/Inflector/Inflector.php similarity index 100% rename from libraries/Gelato/Inflector.php rename to libraries/Gelato/Inflector/Inflector.php diff --git a/libraries/Gelato/Minify.php b/libraries/Gelato/Minify/Minify.php similarity index 100% rename from libraries/Gelato/Minify.php rename to libraries/Gelato/Minify/Minify.php diff --git a/libraries/Gelato/Notification.php b/libraries/Gelato/Notification/Notification.php similarity index 100% rename from libraries/Gelato/Notification.php rename to libraries/Gelato/Notification/Notification.php diff --git a/libraries/Gelato/Number.php b/libraries/Gelato/Number/Number.php similarity index 100% rename from libraries/Gelato/Number.php rename to libraries/Gelato/Number/Number.php diff --git a/libraries/Gelato/Resources/Docs/README.md b/libraries/Gelato/README.md similarity index 100% rename from libraries/Gelato/Resources/Docs/README.md rename to libraries/Gelato/README.md diff --git a/libraries/Gelato/Registry/Registry.php b/libraries/Gelato/Registry/Registry.php new file mode 100644 index 0000000..fc92ddc --- /dev/null +++ b/libraries/Gelato/Registry/Registry.php @@ -0,0 +1,77 @@ +