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:
31
Config.php
31
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)
|
||||
{
|
||||
|
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);
|
||||
}
|
||||
}
|
29
view/helpers/ViewHelperHead.php
Normal file
29
view/helpers/ViewHelperHead.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright NetMonsters <team@netmonsters.ru>
|
||||
* @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";
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user