web/lib/Zend/Application/Resource/Db.php
changeset 807 877f952ae2bd
parent 207 621fa6caec0c
child 1230 68c69c656a2c
equal deleted inserted replaced
805:5e7a0fedabdf 807:877f952ae2bd
    13  * to license@zend.com so we can send you a copy immediately.
    13  * to license@zend.com so we can send you a copy immediately.
    14  *
    14  *
    15  * @category   Zend
    15  * @category   Zend
    16  * @package    Zend_Application
    16  * @package    Zend_Application
    17  * @subpackage Resource
    17  * @subpackage Resource
    18  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    18  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    20  * @version    $Id: Db.php 22544 2010-07-10 15:01:37Z freak $
    20  * @version    $Id: Db.php 25123 2012-11-14 18:27:44Z matthew $
    21  */
    21  */
    22 
    22 
    23 /**
    23 /**
    24  * @see Zend_Application_Resource_ResourceAbstract
    24  * @see Zend_Application_Resource_ResourceAbstract
    25  */
    25  */
    30  *
    30  *
    31  * @uses       Zend_Application_Resource_ResourceAbstract
    31  * @uses       Zend_Application_Resource_ResourceAbstract
    32  * @category   Zend
    32  * @category   Zend
    33  * @package    Zend_Application
    33  * @package    Zend_Application
    34  * @subpackage Resource
    34  * @subpackage Resource
    35  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    35  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    36  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    36  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    37  */
    37  */
    38 class Zend_Application_Resource_Db extends Zend_Application_Resource_ResourceAbstract
    38 class Zend_Application_Resource_Db extends Zend_Application_Resource_ResourceAbstract
    39 {
    39 {
    40     /**
    40     /**
    43      * @var string
    43      * @var string
    44      */
    44      */
    45     protected $_adapter = null;
    45     protected $_adapter = null;
    46 
    46 
    47     /**
    47     /**
    48      * @var Zend_Db_Adapter_Interface
    48      * @var Zend_Db_Adapter_Abstract
    49      */
    49      */
    50     protected $_db;
    50     protected $_db;
    51 
    51 
    52     /**
    52     /**
    53      * Parameters to use
    53      * Parameters to use
    64     protected $_isDefaultTableAdapter = true;
    64     protected $_isDefaultTableAdapter = true;
    65 
    65 
    66     /**
    66     /**
    67      * Set the adapter
    67      * Set the adapter
    68      *
    68      *
    69      * @param  $adapter string
    69      * @param  string $adapter
    70      * @return Zend_Application_Resource_Db
    70      * @return Zend_Application_Resource_Db
    71      */
    71      */
    72     public function setAdapter($adapter)
    72     public function setAdapter($adapter)
    73     {
    73     {
    74         $this->_adapter = $adapter;
    74         $this->_adapter = $adapter;
    86     }
    86     }
    87 
    87 
    88     /**
    88     /**
    89      * Set the adapter params
    89      * Set the adapter params
    90      *
    90      *
    91      * @param  $adapter string
    91      * @param  string $adapter
    92      * @return Zend_Application_Resource_Db
    92      * @return Zend_Application_Resource_Db
    93      */
    93      */
    94     public function setParams(array $params)
    94     public function setParams(array $params)
    95     {
    95     {
    96         $this->_params = $params;
    96         $this->_params = $params;
   130     }
   130     }
   131 
   131 
   132     /**
   132     /**
   133      * Retrieve initialized DB connection
   133      * Retrieve initialized DB connection
   134      *
   134      *
   135      * @return null|Zend_Db_Adapter_Interface
   135      * @return null|Zend_Db_Adapter_Abstract
   136      */
   136      */
   137     public function getDbAdapter()
   137     public function getDbAdapter()
   138     {
   138     {
   139         if ((null === $this->_db)
   139         if ((null === $this->_db)
   140             && (null !== ($adapter = $this->getAdapter()))
   140             && (null !== ($adapter = $this->getAdapter()))
   141         ) {
   141         ) {
   142             $this->_db = Zend_Db::factory($adapter, $this->getParams());
   142             $this->_db = Zend_Db::factory($adapter, $this->getParams());
       
   143 
       
   144             if ($this->_db instanceof Zend_Db_Adapter_Abstract 
       
   145                 && $this->isDefaultTableAdapter()
       
   146             ) {
       
   147                 Zend_Db_Table::setDefaultAdapter($this->_db);
       
   148             }
   143         }
   149         }
   144         return $this->_db;
   150         return $this->_db;
   145     }
   151     }
   146 
   152 
   147     /**
   153     /**
   150      * @return Zend_Db_Adapter_Abstract|null
   156      * @return Zend_Db_Adapter_Abstract|null
   151      */
   157      */
   152     public function init()
   158     public function init()
   153     {
   159     {
   154         if (null !== ($db = $this->getDbAdapter())) {
   160         if (null !== ($db = $this->getDbAdapter())) {
   155             if ($this->isDefaultTableAdapter()) {
       
   156                 Zend_Db_Table::setDefaultAdapter($db);
       
   157             }
       
   158             return $db;
   161             return $db;
   159         }
   162         }
   160     }
   163     }
   161 
   164 
   162     /**
   165     /**
   163      * Set the default metadata cache
   166      * Set the default metadata cache
   164      * 
   167      *
   165      * @param string|Zend_Cache_Core $cache
   168      * @param string|Zend_Cache_Core $cache
   166      * @return Zend_Application_Resource_Db
   169      * @return Zend_Application_Resource_Db
   167      */
   170      */
   168     public function setDefaultMetadataCache($cache)
   171     public function setDefaultMetadataCache($cache)
   169     {
   172     {