Registry, ViewHelperHead added, Config now inherited from Registry, #16
git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/branches/evo@130 4cb57b5f-5bbd-dd11-951b-001d605cbbc5
This commit is contained in:
75
Registry.php
Normal file
75
Registry.php
Normal file
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright NetMonsters <team@netmonsters.ru>
|
||||
* @link http://netmonsters.ru
|
||||
* @package Majestic
|
||||
* @subpackage Model
|
||||
* @since 2010-02-17
|
||||
* @version SVN: $Id$
|
||||
* @filesource $URL$
|
||||
*/
|
||||
|
||||
class Registry extends ArrayObject
|
||||
{
|
||||
/**
|
||||
* Class name of the singleton registry object.
|
||||
* @var string
|
||||
*/
|
||||
private static $_class_name = 'Registry';
|
||||
|
||||
/**
|
||||
* Registry object provides storage for shared objects.
|
||||
* @var Registry
|
||||
*/
|
||||
private static $_registry = null;
|
||||
|
||||
/**
|
||||
* Constructs a parent ArrayObject with default
|
||||
* ARRAY_AS_PROPS to allow acces as an object
|
||||
*
|
||||
* @param array $array data array
|
||||
* @param integer $flags ArrayObject flags
|
||||
*/
|
||||
public function __construct($array = array(), $flags = parent::ARRAY_AS_PROPS)
|
||||
{
|
||||
parent::__construct($array, $flags);
|
||||
}
|
||||
|
||||
private function __clone(){}
|
||||
|
||||
/**
|
||||
* Retrieves the default registry instance.
|
||||
*
|
||||
* @return Registry
|
||||
*/
|
||||
public static function getInstance()
|
||||
{
|
||||
if (self::$_registry === null) {
|
||||
self::$_registry = new self::$_class_name();
|
||||
}
|
||||
return self::$_registry;
|
||||
}
|
||||
|
||||
static public function get($name, $default = null)
|
||||
{
|
||||
$instance = self::getInstance();
|
||||
if (!$instance->offsetExists($name)) {
|
||||
return $default;
|
||||
}
|
||||
return $instance->offsetGet($name);
|
||||
}
|
||||
|
||||
public static function set($index, $value)
|
||||
{
|
||||
$instance = self::getInstance();
|
||||
$instance->offsetSet($index, $value);
|
||||
}
|
||||
|
||||
public static function isRegistered($index)
|
||||
{
|
||||
if (self::$_registry === null) {
|
||||
return false;
|
||||
}
|
||||
return self::$_registry->offsetExists($index);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user