Browse Source
Registry, ViewHelperHead added, Config now inherited from Registry, #16
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-001d605cbbc5master
pzinovkin
15 years ago
3 changed files with 106 additions and 29 deletions
@ -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); |
|||
} |
|||
} |
@ -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"; |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue