diff --git a/Config.php b/Config.php index 45e0ca0..9608dba 100644 --- a/Config.php +++ b/Config.php @@ -9,37 +9,10 @@ * @filesource $URL$ */ -class Config extends ArrayObject +class Config extends Registry { - private static $_instance = null; - - public function __construct($config = array()) - { - parent::__construct($config, ArrayObject::ARRAY_AS_PROPS); - } - - private function __clone(){} - - /** - * @return Config - */ - static public function getInstance() - { - if (!isset(self::$_instance)) { - self::$_instance = new Config(); - } - return self::$_instance; - } - - static public function get($name, $default = null) - { - $instance = self::getInstance(); - if (!$instance->offsetExists($name)) { - return $default; - } - return $instance->offsetGet($name); - } + private static $_class_name = 'Config'; static public function set($name, $value) { diff --git a/Registry.php b/Registry.php new file mode 100644 index 0000000..6c4b853 --- /dev/null +++ b/Registry.php @@ -0,0 +1,75 @@ + + * @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); + } +} \ No newline at end of file diff --git a/view/helpers/ViewHelperHead.php b/view/helpers/ViewHelperHead.php new file mode 100644 index 0000000..c97bfa0 --- /dev/null +++ b/view/helpers/ViewHelperHead.php @@ -0,0 +1,29 @@ + + * @link http://netmonsters.ru + * @package Majestic + * @subpackage View + * @since 2010-03-16 + * @version SVN: $Id$ + * @filesource $URL$ + */ + +class ViewHelperHead extends ViewHelper +{ + + public function head($string = false) + { + if ($string) { + $data = Registry::get(__CLASS__, array()); + $data[] = $string; + Registry::set(__CLASS__, $data); + } + return $this; + } + + public function __toString() + { + return implode("\n ", Registry::get(__CLASS__, array())) . "\n"; + } +} \ No newline at end of file