00001 <?php 00030 class Zend_Registry extends ArrayObject 00031 { 00036 private static $_registryClassName = 'Zend_Registry'; 00037 00042 private static $_registry = null; 00043 00049 public static function getInstance() 00050 { 00051 if (self::$_registry === null) { 00052 self::init(); 00053 } 00054 00055 return self::$_registry; 00056 } 00057 00066 public static function setInstance(Zend_Registry $registry) 00067 { 00068 if (self::$_registry !== null) { 00069 require_once 'Zend/Exception.php'; 00070 throw new Zend_Exception('Registry is already initialized'); 00071 } 00072 00073 self::setClassName(get_class($registry)); 00074 self::$_registry = $registry; 00075 } 00076 00082 protected static function init() 00083 { 00084 self::setInstance(new self::$_registryClassName()); 00085 } 00086 00097 public static function setClassName($registryClassName = 'Zend_Registry') 00098 { 00099 if (self::$_registry !== null) { 00100 require_once 'Zend/Exception.php'; 00101 throw new Zend_Exception('Registry is already initialized'); 00102 } 00103 00104 if (!is_string($registryClassName)) { 00105 require_once 'Zend/Exception.php'; 00106 throw new Zend_Exception("Argument is not a class name"); 00107 } 00108 00112 if (!class_exists($registryClassName)) { 00113 require_once 'Zend/Loader.php'; 00114 Zend_Loader::loadClass($registryClassName); 00115 } 00116 00117 self::$_registryClassName = $registryClassName; 00118 } 00119 00125 public static function _unsetInstance() 00126 { 00127 self::$_registry = null; 00128 } 00129 00141 public static function get($index) 00142 { 00143 $instance = self::getInstance(); 00144 00145 if (!$instance->offsetExists($index)) { 00146 require_once 'Zend/Exception.php'; 00147 throw new Zend_Exception("No entry is registered for key '$index'"); 00148 } 00149 00150 return $instance->offsetGet($index); 00151 } 00152 00165 public static function set($index, $value) 00166 { 00167 $instance = self::getInstance(); 00168 $instance->offsetSet($index, $value); 00169 } 00170 00178 public static function isRegistered($index) 00179 { 00180 if (self::$_registry === null) { 00181 return false; 00182 } 00183 return self::$_registry->offsetExists($index); 00184 } 00185 00193 public function __construct($array = array(), $flags = parent::ARRAY_AS_PROPS) 00194 { 00195 parent::__construct($array, $flags); 00196 } 00197 00204 public function offsetExists($index) 00205 { 00206 return array_key_exists($index, $this); 00207 } 00208 00209 }