first commit
This commit is contained in:
109
_rejestracja/core/class/Registry.class.php
Normal file
109
_rejestracja/core/class/Registry.class.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?
|
||||
|
||||
/**
|
||||
* $Id: Registry.class.php 395 2008-05-28 19:41:06Z dakl $
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user