mirror of
https://github.com/monstra-cms/monstra.git
synced 2025-07-10 08:06:45 +02:00
@ -1,88 +0,0 @@
|
|||||||
<?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 Alert
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Protected constructor since this is a static class.
|
|
||||||
*
|
|
||||||
* @access protected
|
|
||||||
*/
|
|
||||||
protected function __construct()
|
|
||||||
{
|
|
||||||
// Nothing here
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Show success message
|
|
||||||
*
|
|
||||||
* <code>
|
|
||||||
* Alert::success('Message here...');
|
|
||||||
* </code>
|
|
||||||
*
|
|
||||||
* @param string $message Message
|
|
||||||
* @param integer $time Time
|
|
||||||
*/
|
|
||||||
public static function success($message, $time = 3000)
|
|
||||||
{
|
|
||||||
// Redefine vars
|
|
||||||
$message = (string) $message;
|
|
||||||
$time = (int) $time;
|
|
||||||
|
|
||||||
echo '<div class="alert alert-info">'.$message.'</div>
|
|
||||||
<script type="text/javascript">setTimeout(\'$(".alert").slideUp("slow")\', '.$time.'); </script>';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Show warning message
|
|
||||||
*
|
|
||||||
* <code>
|
|
||||||
* Alert::warning('Message here...');
|
|
||||||
* </code>
|
|
||||||
*
|
|
||||||
* @param string $message Message
|
|
||||||
* @param integer $time Time
|
|
||||||
*/
|
|
||||||
public static function warning($message, $time = 3000)
|
|
||||||
{
|
|
||||||
// Redefine vars
|
|
||||||
$message = (string) $message;
|
|
||||||
$time = (int) $time;
|
|
||||||
|
|
||||||
echo '<div class="alert alert-warning">'.$message.'</div>
|
|
||||||
<script type="text/javascript">setTimeout(\'$(".alert").slideUp("slow")\', '.$time.'); </script>';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Show error message
|
|
||||||
*
|
|
||||||
* <code>
|
|
||||||
* Alert::error('Message here...');
|
|
||||||
* </code>
|
|
||||||
*
|
|
||||||
* @param string $message Message
|
|
||||||
* @param integer $time Time
|
|
||||||
*/
|
|
||||||
public static function error($message, $time = 3000)
|
|
||||||
{
|
|
||||||
// Redefine vars
|
|
||||||
$message = (string) $message;
|
|
||||||
$time = (int) $time;
|
|
||||||
|
|
||||||
echo '<div class="alert alert-error">'.$message.'</div>
|
|
||||||
<script type="text/javascript">setTimeout(\'$(".alert").slideUp("slow")\', '.$time.'); </script>';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
205
libraries/Gelato/ClassLoader/ClassLoader.php
Normal file
205
libraries/Gelato/ClassLoader/ClassLoader.php
Normal file
@ -0,0 +1,205 @@
|
|||||||
|
<?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 ClassLoader
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mapping from class names to paths.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected static $classes = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PSR-0 directories.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected static $directories = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registered namespaces.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected static $namespaces = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class aliases.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected static $aliases = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Protected constructor since this is a static class.
|
||||||
|
*
|
||||||
|
* @access protected
|
||||||
|
*/
|
||||||
|
protected function __construct()
|
||||||
|
{
|
||||||
|
// Nothing here
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add class to mapping.
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param string $className Class name
|
||||||
|
* @param string $classPath Full path to class
|
||||||
|
*/
|
||||||
|
public static function mapClass($className, $classPath)
|
||||||
|
{
|
||||||
|
static::$classes[$className] = $classPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add multiple classes to mapping.
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param array $classes Array of classes to map (key = class name and value = class path)
|
||||||
|
*/
|
||||||
|
public static function mapClasses(array $classes)
|
||||||
|
{
|
||||||
|
foreach($classes as $name => $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;
|
||||||
|
}
|
||||||
|
}
|
@ -260,10 +260,10 @@ class ErrorHandler
|
|||||||
$error['highlighted'] = static::highlightCode($error['file'], $error['line']);
|
$error['highlighted'] = static::highlightCode($error['file'], $error['line']);
|
||||||
|
|
||||||
Response::status(500);
|
Response::status(500);
|
||||||
include 'Resources/Templates/exception.php';
|
include 'Resources/Views/Errors/exception.php';
|
||||||
} else {
|
} else {
|
||||||
Response::status(500);
|
Response::status(500);
|
||||||
include 'Resources/Templates/error.php';
|
include 'Resources/Views/Errors/error.php';
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
while(ob_get_level() > 0) ob_end_clean();
|
while(ob_get_level() > 0) ob_end_clean();
|
@ -25,18 +25,10 @@ if ( ! defined('GELATO_DISPLAY_ERRORS')) {
|
|||||||
define('GELATO_DISPLAY_ERRORS', true);
|
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
|
* Load Gelato Error Handler
|
||||||
*/
|
*/
|
||||||
require_once __DIR__ . '/ErrorHandler.php';
|
require_once __DIR__ . '/ErrorHandler/ErrorHandler.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set Error Handler
|
* Set Error Handler
|
||||||
@ -54,90 +46,42 @@ register_shutdown_function('ErrorHandler::fatalErrorHandler');
|
|||||||
set_exception_handler('ErrorHandler::exception');
|
set_exception_handler('ErrorHandler::exception');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register Gelato Autoloader
|
* Gelato Class Loader
|
||||||
*/
|
*/
|
||||||
if (GELATO_AUTOLOADER) {
|
require_once __DIR__ . '/ClassLoader/ClassLoader.php';
|
||||||
spl_autoload_register(array('Gelato', 'autoload'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gelato
|
* Map all Gelato Classes
|
||||||
*/
|
*/
|
||||||
class Gelato
|
ClassLoader::mapClasses(array(
|
||||||
{
|
'Agent' => __DIR__.'/Agent/Agent.php',
|
||||||
/**
|
'Arr' => __DIR__.'/Arr/Arr.php',
|
||||||
* Registry of variables
|
'Cache' => __DIR__.'/Cache/Cache.php',
|
||||||
*
|
'Cookie' => __DIR__.'/Cookie/Cookie.php',
|
||||||
* @var array
|
'Curl' => __DIR__.'/Curl/Curl.php',
|
||||||
*/
|
'Date' => __DIR__.'/Date/Date.php',
|
||||||
private static $registry = array();
|
'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
|
* Register Gelato Autoloader
|
||||||
*/
|
*/
|
||||||
public static function autoload($className)
|
spl_autoload_register('ClassLoader::load');
|
||||||
{
|
|
||||||
$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];
|
|
||||||
}
|
|
||||||
}
|
|
@ -21,11 +21,9 @@ class Response
|
|||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public static $messages = array(
|
public static $messages = array(
|
||||||
// Informational 1xx
|
|
||||||
100 => 'Continue',
|
100 => 'Continue',
|
||||||
101 => 'Switching Protocols',
|
101 => 'Switching Protocols',
|
||||||
|
102 => 'Processing', // RFC2518
|
||||||
// Success 2xx
|
|
||||||
200 => 'OK',
|
200 => 'OK',
|
||||||
201 => 'Created',
|
201 => 'Created',
|
||||||
202 => 'Accepted',
|
202 => 'Accepted',
|
||||||
@ -33,18 +31,18 @@ class Response
|
|||||||
204 => 'No Content',
|
204 => 'No Content',
|
||||||
205 => 'Reset Content',
|
205 => 'Reset Content',
|
||||||
206 => 'Partial Content',
|
206 => 'Partial Content',
|
||||||
|
207 => 'Multi-Status', // RFC4918
|
||||||
// Redirection 3xx
|
208 => 'Already Reported', // RFC5842
|
||||||
|
226 => 'IM Used', // RFC3229
|
||||||
300 => 'Multiple Choices',
|
300 => 'Multiple Choices',
|
||||||
301 => 'Moved Permanently',
|
301 => 'Moved Permanently',
|
||||||
302 => 'Found', // 1.1
|
302 => 'Found',
|
||||||
303 => 'See Other',
|
303 => 'See Other',
|
||||||
304 => 'Not Modified',
|
304 => 'Not Modified',
|
||||||
305 => 'Use Proxy',
|
305 => 'Use Proxy',
|
||||||
// 306 is deprecated but reserved
|
306 => 'Reserved',
|
||||||
307 => 'Temporary Redirect',
|
307 => 'Temporary Redirect',
|
||||||
|
308 => 'Permanent Redirect', // RFC-reschke-http-status-308-07
|
||||||
// Client Error 4xx
|
|
||||||
400 => 'Bad Request',
|
400 => 'Bad Request',
|
||||||
401 => 'Unauthorized',
|
401 => 'Unauthorized',
|
||||||
402 => 'Payment Required',
|
402 => 'Payment Required',
|
||||||
@ -63,15 +61,26 @@ class Response
|
|||||||
415 => 'Unsupported Media Type',
|
415 => 'Unsupported Media Type',
|
||||||
416 => 'Requested Range Not Satisfiable',
|
416 => 'Requested Range Not Satisfiable',
|
||||||
417 => 'Expectation Failed',
|
417 => 'Expectation Failed',
|
||||||
|
418 => 'I\'m a teapot', // RFC2324
|
||||||
// Server Error 5xx
|
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',
|
500 => 'Internal Server Error',
|
||||||
501 => 'Not Implemented',
|
501 => 'Not Implemented',
|
||||||
502 => 'Bad Gateway',
|
502 => 'Bad Gateway',
|
||||||
503 => 'Service Unavailable',
|
503 => 'Service Unavailable',
|
||||||
504 => 'Gateway Timeout',
|
504 => 'Gateway Timeout',
|
||||||
505 => 'HTTP Version Not Supported',
|
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
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
77
libraries/Gelato/Registry/Registry.php
Normal file
77
libraries/Gelato/Registry/Registry.php
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
<?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 Registry
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registry of variables
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private static $registry = array();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user