Guest User

Igor Hlina

a guest
Feb 1st, 2009
478
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /**
  3.  * Registry.php
  4.  * this file is contains Registry class definition
  5.  *
  6.  * @copyright Copyright (c) 2009 Igor Hlina
  7.  * @license read LICENCE.txt
  8.  *
  9.  */
  10.  
  11.  
  12. /**
  13.  * Registry class definition
  14.  * Registry is a special object for global data
  15.  *
  16.  */
  17. class Registry Implements ArrayAccess
  18. {
  19.  
  20.     /**
  21.      * data holder
  22.      *
  23.      * @var array
  24.      */
  25.     private $vars = array();
  26.  
  27.  
  28.     public function set($key, $var)
  29.     {
  30.         if (isset($this->vars[$key]) == true) {
  31.             throw new Exception('Unable to set var `' . $key . '`. Already set.');
  32.         }
  33.  
  34.         $this->vars[$key] = $var;
  35.         return true;
  36.     }
  37.  
  38.  
  39.     public function get($key)
  40.     {
  41.         if (isset($this->vars[$key]) == false) {
  42.             return null;
  43.         }
  44.  
  45.         return $this->vars[$key];
  46.     }
  47.  
  48.  
  49.     public function remove($key)
  50.     {
  51.         unset($this->vars[$key]);
  52.     }
  53.  
  54.     public function offsetExists($offset)
  55.     {
  56.         return isset($this->vars[$offset]);
  57.     }
  58.  
  59.     public function offsetGet($offset)
  60.     {
  61.         return $this->get($offset);
  62.     }
  63.  
  64.     public function offsetSet($offset, $value)
  65.     {
  66.         $this->set($offset, $value);
  67.     }
  68.  
  69.     public function offsetUnset($offset)
  70.     {
  71.         unset($this->vars[$offset]);
  72.     }
  73. }
  74.  
RAW Paste Data