Source of file MasterSlaveFeature.php
Size: 2,021 Bytes - Last Modified: 2014-03-12T23:21:18+01:00
/home/theseer/Downloads/ZendFramework-2.3.0/library/Zend/Db/TableGateway/Feature/MasterSlaveFeature.php
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 | <?php /** * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Db\TableGateway\Feature; use Zend\Db\Adapter\AdapterInterface; use Zend\Db\Sql\Sql; class MasterSlaveFeature extends AbstractFeature { /** * @var AdapterInterface */ protected $slaveAdapter = null; /** * @var Sql */ protected $masterSql = null; /** * @var Sql */ protected $slaveSql = null; /** * Constructor * * @param AdapterInterface $slaveAdapter * @param Sql|null $slaveSql */ public function __construct(AdapterInterface $slaveAdapter, Sql $slaveSql = null) { $this->slaveAdapter = $slaveAdapter; if ($slaveSql) { $this->slaveSql = $slaveSql; } } public function getSlaveAdapter() { return $this->slaveAdapter; } /** * @return Sql */ public function getSlaveSql() { return $this->slaveSql; } /** * after initialization, retrieve the original adapter as "master" */ public function postInitialize() { $this->masterSql = $this->tableGateway->sql; if ($this->slaveSql == null) { $this->slaveSql = new Sql( $this->slaveAdapter, $this->tableGateway->sql->getTable(), $this->tableGateway->sql->getSqlPlatform() ); } } /** * preSelect() * Replace adapter with slave temporarily */ public function preSelect() { $this->tableGateway->sql = $this->slaveSql; } /** * postSelect() * Ensure to return to the master adapter */ public function postSelect() { $this->tableGateway->sql = $this->masterSql; } } |