Created
August 31, 2012 01:58
-
-
Save jonathaningram/3547750 to your computer and use it in GitHub Desktop.
Doctrine MasterSlaveConnection connect sets $this->_conn to the master one
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class MasterSlaveConnection | |
{ | |
public function connect($connectionName = 'slave') | |
{ | |
if ( $connectionName !== 'slave' && $connectionName !== 'master' ) { | |
throw new \InvalidArgumentException("Invalid option to connect(), only master or slave allowed."); | |
} | |
$forceMasterAsSlave = false; | |
if ($this->getTransactionNestingLevel() > 0) { | |
$connectionName = 'master'; | |
$forceMasterAsSlave = true; | |
} | |
if ($this->connections[$connectionName]) { | |
if ($forceMasterAsSlave) { | |
$this->connections['slave'] = $this->_conn = $this->connections['master']; | |
} else { | |
// **** this is the connection that is set up *** | |
$this->_conn = $this->connections[$connectionName]; | |
} | |
return false; | |
} | |
if ($connectionName === 'master') { | |
/** Set slave connection to master to avoid invalid reads */ | |
if ($this->connections['slave'] && ! $this->keepSlave) { | |
unset($this->connections['slave']); | |
} | |
$this->connections['master'] = $this->_conn = $this->connectTo($connectionName); | |
if ( ! $this->keepSlave) { | |
$this->connections['slave'] = $this->connections['master']; | |
} | |
} else { | |
$this->connections['slave'] = $this->_conn = $this->connectTo($connectionName); | |
} | |
if ($this->_eventManager->hasListeners(Events::postConnect)) { | |
$eventArgs = new ConnectionEventArgs($this); | |
$this->_eventManager->dispatchEvent(Events::postConnect, $eventArgs); | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment