diff -r 5b37998e522e -r 162c1de6545a web/lib/Zend/Application/Resource/Db.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/lib/Zend/Application/Resource/Db.php Fri Mar 11 15:05:35 2011 +0100 @@ -0,0 +1,193 @@ +_adapter = $adapter; + return $this; + } + + /** + * Adapter type to use + * + * @return string + */ + public function getAdapter() + { + return $this->_adapter; + } + + /** + * Set the adapter params + * + * @param $adapter string + * @return Zend_Application_Resource_Db + */ + public function setParams(array $params) + { + $this->_params = $params; + return $this; + } + + /** + * Adapter parameters + * + * @return array + */ + public function getParams() + { + return $this->_params; + } + + /** + * Set whether to use this as default table adapter + * + * @param boolean $defaultTableAdapter + * @return Zend_Application_Resource_Db + */ + public function setIsDefaultTableAdapter($isDefaultTableAdapter) + { + $this->_isDefaultTableAdapter = $isDefaultTableAdapter; + return $this; + } + + /** + * Is this adapter the default table adapter? + * + * @return void + */ + public function isDefaultTableAdapter() + { + return $this->_isDefaultTableAdapter; + } + + /** + * Retrieve initialized DB connection + * + * @return null|Zend_Db_Adapter_Interface + */ + public function getDbAdapter() + { + if ((null === $this->_db) + && (null !== ($adapter = $this->getAdapter())) + ) { + $this->_db = Zend_Db::factory($adapter, $this->getParams()); + } + return $this->_db; + } + + /** + * Defined by Zend_Application_Resource_Resource + * + * @return Zend_Db_Adapter_Abstract|null + */ + public function init() + { + if (null !== ($db = $this->getDbAdapter())) { + if ($this->isDefaultTableAdapter()) { + Zend_Db_Table::setDefaultAdapter($db); + } + return $db; + } + } + + /** + * Set the default metadata cache + * + * @param string|Zend_Cache_Core $cache + * @return Zend_Application_Resource_Db + */ + public function setDefaultMetadataCache($cache) + { + $metadataCache = null; + + if (is_string($cache)) { + $bootstrap = $this->getBootstrap(); + if ($bootstrap instanceof Zend_Application_Bootstrap_ResourceBootstrapper + && $bootstrap->hasPluginResource('CacheManager') + ) { + $cacheManager = $bootstrap->bootstrap('CacheManager') + ->getResource('CacheManager'); + if (null !== $cacheManager && $cacheManager->hasCache($cache)) { + $metadataCache = $cacheManager->getCache($cache); + } + } + } else if ($cache instanceof Zend_Cache_Core) { + $metadataCache = $cache; + } + + if ($metadataCache instanceof Zend_Cache_Core) { + Zend_Db_Table::setDefaultMetadataCache($metadataCache); + } + + return $this; + } +}