00001 <?php 00024 require_once 'Zend/Registry.php'; 00025 00027 require_once 'Zend/View/Helper/Placeholder/Container/Abstract.php'; 00028 00030 require_once 'Zend/View/Helper/Placeholder/Container.php'; 00031 00040 class Zend_View_Helper_Placeholder_Registry 00041 { 00046 const REGISTRY_KEY = 'Zend_View_Helper_Placeholder_Registry'; 00047 00052 protected $_containerClass = 'Zend_View_Helper_Placeholder_Container'; 00053 00058 protected $_items = array(); 00059 00065 public static function getRegistry() 00066 { 00067 if (Zend_Registry::isRegistered(self::REGISTRY_KEY)) { 00068 $registry = Zend_Registry::get(self::REGISTRY_KEY); 00069 } else { 00070 $registry = new self(); 00071 Zend_Registry::set(self::REGISTRY_KEY, $registry); 00072 } 00073 00074 return $registry; 00075 } 00076 00084 public function createContainer($key, array $value = array()) 00085 { 00086 $key = (string) $key; 00087 00088 $this->_items[$key] = new $this->_containerClass(array()); 00089 return $this->_items[$key]; 00090 } 00091 00098 public function getContainer($key) 00099 { 00100 $key = (string) $key; 00101 if (isset($this->_items[$key])) { 00102 return $this->_items[$key]; 00103 } 00104 00105 $container = $this->createContainer($key); 00106 00107 return $container; 00108 } 00109 00116 public function containerExists($key) 00117 { 00118 $key = (string) $key; 00119 $return = array_key_exists($key, $this->_items); 00120 return $return; 00121 } 00122 00130 public function setContainer($key, Zend_View_Helper_Placeholder_Container_Abstract $container) 00131 { 00132 $key = (string) $key; 00133 $this->_items[$key] = $container; 00134 return $this; 00135 } 00136 00143 public function deleteContainer($key) 00144 { 00145 $key = (string) $key; 00146 if (isset($this->_items[$key])) { 00147 unset($this->_items[$key]); 00148 return true; 00149 } 00150 00151 return false; 00152 } 00153 00160 public function setContainerClass($name) 00161 { 00162 if (!class_exists($name)) { 00163 require_once 'Zend/Loader.php'; 00164 Zend_Loader::loadClass($name); 00165 } 00166 00167 $reflection = new ReflectionClass($name); 00168 if (!$reflection->isSubclassOf(new ReflectionClass('Zend_View_Helper_Placeholder_Container_Abstract'))) { 00169 require_once 'Zend/View/Helper/Placeholder/Registry/Exception.php'; 00170 throw new Zend_View_Helper_Placeholder_Registry_Exception('Invalid Container class specified'); 00171 } 00172 00173 $this->_containerClass = $name; 00174 return $this; 00175 } 00176 00182 public function getContainerClass() 00183 { 00184 return $this->_containerClass; 00185 } 00186 }