1
0
mirror of https://github.com/monstra-cms/monstra.git synced 2025-08-07 05:37:03 +02:00

Core Improvements: Next Round #79 #80

This commit is contained in:
Awilum
2013-01-08 18:29:30 +02:00
parent ef76f8befc
commit b7dcc5be49
34 changed files with 341 additions and 194 deletions

View 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];
}
}