Poznaje PHP i w ramach nauki napisalem swoja 1 klase do obslugi rejestru. Bede wdzieczny za wszelka krytyke.
final class Registry { private $name; private $registry; /** * Disables object cloning * * @return void does not return any value */ private function __clone() { throw new Exception('Cloning Registry object is not allowed!'); } /** * Class constructor * * @param string instance name * @return void does not return any value */ private function __construct($name) { $this->name = $name; } /** * Adds an element to the registry * * @param string location in the registry, in which to store the value * @param mixed value to be stored in the registry * @param boolean specifies whether the existing element should be overwritten or not * @return boolean TRUE on success, FALSE otherwise */ public function addValue($index, $value, $overwrite = false) { if($this->isRegistered($index) && !$overwrite) { return false; } $this->registry[$index] = $value; return true; } /** * Adds multiple elements to the registry * * @param array associative array containing elements to add to the registry * @param boolean specified whether the existing elements should be overwritten or not * @return boolean TRUE on success, FALSE otherwise */ public function addValues($values, $overwrite = false) { return false; } foreach($values as $index => $value) { if(!$this->addValue($index, $value, $overwrite)) { return false; } } return true; } /** * Flushes (removes all elements from) the registry * * @return void does not return any value */ public function flushRegistry() { } /** * Returns the global Registry object, creating it only if it does not exist already * * @param string instance name * @return object the QRegistry object */ $instance[$name] = new Registry(); } return $instance[$name]; } /** * Returns all elements stored in registry * * @return array associative array containing all registered values */ public function getRegistry() { return $this->registry; } /** * Returns the Registry instance name * * @return string instance name */ public function getRegistryName() { return $this->name; } /** * Retrieves a value from the registry * * @param string location in the registry, in which the value is stored * @param mixed the default value to return when element is not found * @return mixed the value of requested item */ public function getValue($index, $default = NULL) { if(!$this->isRegistered($index)) { return $default; } return $this->registry[$index]; } /** * Retrieves multiple values from the registry * * @param array array containing the names of the requested elements * @param mixed the default value to return when element is not found * @return array associative array containing values of the requested items */ public function getValues($indexes, $default = NULL) { return $results; } foreach($indexes as $index) { $results[$index] = $this->getValue($index, $default); } return $results; } /** * Checks if container contains an item with the specified index * * @param string location in the registry * @return boolean TRUE if index is a named value in the registry, FALSE otherwise */ public function isRegistered($index) { } /** * Removes given registered element * * @param string location in the registry * @return boolean TRUE on success, FALSE otherwise */ public function removeValue($index) { if(!$this->isRegistered($index)) { return false; } return true; } /** * Removes multiple given registered elements * * @param array array containing the names of the requested elements * @return boolean TRUE on success, FALSE otherwise */ public function removeValues($indexes) { return false; } foreach($indexes as $index) { if(!$this->removeValue($index)) { return false; } } return true; } }