109 lines
1.6 KiB
PHP
109 lines
1.6 KiB
PHP
<?php
|
|
|
|
/**
|
|
*
|
|
* Singleton rejestru
|
|
*
|
|
*/
|
|
class Registry {
|
|
/**
|
|
* Index wszystkich wartosci
|
|
*
|
|
* @var unknown_type
|
|
*/
|
|
static private $index = array();
|
|
|
|
/**
|
|
* Konstruktor klasy
|
|
*
|
|
*/
|
|
public function __construct() {}
|
|
|
|
/**
|
|
* Zapobiegacz klonowania
|
|
*
|
|
*/
|
|
private function __clone() {}
|
|
|
|
|
|
/**
|
|
* Dodawanie wartosci do rejestru np. Registry::Set('zmienna', 'wartosc');
|
|
*
|
|
* @param string $name
|
|
* @param unknown_type $item
|
|
* @return unknown
|
|
*/
|
|
public static function Set($name, &$item)
|
|
{
|
|
if (!self::Exists($name)) {
|
|
self::$index[$name] = $item;
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* Weryfikacja czy zmienna o podanej nazwie istnieje
|
|
*
|
|
* @param string $name
|
|
* @return unknown
|
|
*/
|
|
public static function Exists($name)
|
|
{
|
|
if (is_string($name)) {
|
|
return array_key_exists($name, self::$index);
|
|
} else {
|
|
throw new Exception('Musi byc stringiem');
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* Zwraca wartosc podanej zmiennej
|
|
*
|
|
* @param string $name
|
|
* @return misc
|
|
*/
|
|
public static function &Get($name)
|
|
{
|
|
if (self::Exists($name)) {
|
|
$return = self::$index[$name];
|
|
} else {
|
|
$return = null;
|
|
}
|
|
return $return;
|
|
}
|
|
|
|
|
|
/**
|
|
* Czysci zmienna
|
|
*
|
|
* @param string $name
|
|
* @return unknown
|
|
*/
|
|
public static function Remove($name)
|
|
{
|
|
if (self::Exists($name)) {
|
|
unset(self::$index[$name]);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* UWAGA! Czysci caly rejestr
|
|
* @access public
|
|
* @return boolean
|
|
*/
|
|
public static function Clear()
|
|
{
|
|
self::$index = array();
|
|
}
|
|
|
|
public static function SetIndex($index) {
|
|
self::$index = $index;
|
|
}
|
|
}
|
|
|
|
?>
|