Commit 2d24e9ad authored by lsmith's avatar lsmith

- lazy load the _tableFactory and record listener in order to reduce the...

- lazy load the _tableFactory and record listener in order to reduce the dependencies for a to be created DBAL package
parent 3a5bd47f
...@@ -50,7 +50,7 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable ...@@ -50,7 +50,7 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable
* implementation classes * implementation classes
*/ */
protected $_impl = array(); protected $_impl = array();
/** /**
* @var array $_params an array of user defined parameters * @var array $_params an array of user defined parameters
*/ */
...@@ -175,36 +175,36 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable ...@@ -175,36 +175,36 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable
if ($namespace == null) { if ($namespace == null) {
$namespace = $this->getAttribute(Doctrine::ATTR_DEFAULT_PARAM_NAMESPACE); $namespace = $this->getAttribute(Doctrine::ATTR_DEFAULT_PARAM_NAMESPACE);
} }
if ( ! isset($this->_params[$namespace])) { if ( ! isset($this->_params[$namespace])) {
return null; return null;
} }
return $this->_params[$namespace]; return $this->_params[$namespace];
} }
public function getParamNamespaces() public function getParamNamespaces()
{ {
return array_keys($this->_params); return array_keys($this->_params);
} }
public function setParam($name, $value, $namespace = null) public function setParam($name, $value, $namespace = null)
{ {
if ($namespace == null) { if ($namespace == null) {
$namespace = $this->getAttribute(Doctrine::ATTR_DEFAULT_PARAM_NAMESPACE); $namespace = $this->getAttribute(Doctrine::ATTR_DEFAULT_PARAM_NAMESPACE);
} }
$this->_params[$namespace][$name] = $value; $this->_params[$namespace][$name] = $value;
return $this; return $this;
} }
public function getParam($name, $value, $namespace) public function getParam($name, $value, $namespace)
{ {
if ($namespace == null) { if ($namespace == null) {
$namespace = $this->getAttribute(Doctrine::ATTR_DEFAULT_PARAM_NAMESPACE); $namespace = $this->getAttribute(Doctrine::ATTR_DEFAULT_PARAM_NAMESPACE);
} }
if ( ! isset($this->_params[$name])) { if ( ! isset($this->_params[$name])) {
if (isset($this->parent)) { if (isset($this->parent)) {
return $this->parent->getParam($name); return $this->parent->getParam($name);
...@@ -213,7 +213,7 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable ...@@ -213,7 +213,7 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable
} }
return $this->_params[$name]; return $this->_params[$name];
} }
/** /**
* setImpl * setImpl
* binds given class to given template name * binds given class to given template name
...@@ -247,8 +247,8 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable ...@@ -247,8 +247,8 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable
} }
return $this->_impl[$template]; return $this->_impl[$template];
} }
public function hasImpl($template) public function hasImpl($template)
{ {
if ( ! isset($this->_impl[$template])) { if ( ! isset($this->_impl[$template])) {
...@@ -298,7 +298,7 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable ...@@ -298,7 +298,7 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable
if (isset($this->parent)) { if (isset($this->parent)) {
return $this->parent->getRecordListener(); return $this->parent->getRecordListener();
} }
return null; $this->attributes[Doctrine::ATTR_RECORD_LISTENER] = new Doctrine_Record_Listener();
} }
return $this->attributes[Doctrine::ATTR_RECORD_LISTENER]; return $this->attributes[Doctrine::ATTR_RECORD_LISTENER];
} }
...@@ -390,7 +390,7 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable ...@@ -390,7 +390,7 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable
if (isset($this->attributes[$attribute])) { if (isset($this->attributes[$attribute])) {
return $this->attributes[$attribute]; return $this->attributes[$attribute];
} }
if (isset($this->parent)) { if (isset($this->parent)) {
return $this->parent->getAttribute($attribute); return $this->parent->getAttribute($attribute);
} }
......
...@@ -34,14 +34,14 @@ Doctrine::autoload('Doctrine_Configurable'); ...@@ -34,14 +34,14 @@ Doctrine::autoload('Doctrine_Configurable');
* 2. Lazy-connecting * 2. Lazy-connecting
* Creating an instance of Doctrine_Connection does not connect * Creating an instance of Doctrine_Connection does not connect
* to database. Connecting to database is only invoked when actually needed * to database. Connecting to database is only invoked when actually needed
* (for example when query() is being called) * (for example when query() is being called)
* *
* 3. Convenience methods * 3. Convenience methods
* Doctrine_Connection provides many convenience methods such as fetchAll(), fetchOne() etc. * Doctrine_Connection provides many convenience methods such as fetchAll(), fetchOne() etc.
* *
* 4. Modular structure * 4. Modular structure
* Higher level functionality such as schema importing, exporting, sequence handling etc. * Higher level functionality such as schema importing, exporting, sequence handling etc.
* is divided into modules. For a full list of connection modules see * is divided into modules. For a full list of connection modules see
* Doctrine_Connection::$_modules * Doctrine_Connection::$_modules
* *
* @package Doctrine * @package Doctrine
...@@ -61,7 +61,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -61,7 +61,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
protected $dbh; protected $dbh;
/** /**
* *
*/ */
protected $_tableFactory; protected $_tableFactory;
...@@ -70,12 +70,12 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -70,12 +70,12 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* keys representing component names and values as Doctrine_Table objects * keys representing component names and values as Doctrine_Table objects
*/ */
protected $tables = array(); protected $tables = array();
/** /**
* @var array An array of mapper objects currently maintained by this connection. * @var array An array of mapper objects currently maintained by this connection.
*/ */
protected $_mappers = array(); protected $_mappers = array();
/** /**
* $_name * $_name
* *
...@@ -166,7 +166,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -166,7 +166,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @var array $serverInfo * @var array $serverInfo
*/ */
protected $serverInfo = array(); protected $serverInfo = array();
protected $options = array(); protected $options = array();
/** /**
...@@ -181,7 +181,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -181,7 +181,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
'Sqlite', 'Sqlite',
'Firebird' 'Firebird'
); );
/** /**
* The query count. Represents the number of executed database queries by the connection. * The query count. Represents the number of executed database queries by the connection.
* *
...@@ -209,8 +209,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -209,8 +209,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
$this->options['dsn'] = $adapter['dsn']; $this->options['dsn'] = $adapter['dsn'];
$this->options['username'] = $adapter['user']; $this->options['username'] = $adapter['user'];
$this->options['password'] = $adapter['pass']; $this->options['password'] = $adapter['pass'];
$this->options['other'] = array(); $this->options['other'] = array();
if (isset($adapter['other'])) { if (isset($adapter['other'])) {
$this->options['other'] = array(Doctrine::ATTR_PERSISTENT => $adapter['persistent']); $this->options['other'] = array(Doctrine::ATTR_PERSISTENT => $adapter['persistent']);
} }
...@@ -218,8 +218,6 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -218,8 +218,6 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
} }
$this->setParent($manager); $this->setParent($manager);
$this->_tableFactory = new Doctrine_Table_Factory($this);
$this->setAttribute(Doctrine::ATTR_CASE, Doctrine::CASE_NATURAL); $this->setAttribute(Doctrine::ATTR_CASE, Doctrine::CASE_NATURAL);
$this->setAttribute(Doctrine::ATTR_ERRMODE, Doctrine::ERRMODE_EXCEPTION); $this->setAttribute(Doctrine::ATTR_ERRMODE, Doctrine::ERRMODE_EXCEPTION);
...@@ -229,10 +227,10 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -229,10 +227,10 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
/** /**
* getOption * getOption
* *
* Retrieves option * Retrieves option
* *
* @param string $option * @param string $option
* @return void * @return void
*/ */
public function getOption($option) public function getOption($option)
...@@ -286,7 +284,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -286,7 +284,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* setAttribute * setAttribute
* sets an attribute * sets an attribute
* *
* @todo why check for >= 100? has this any special meaning when creating * @todo why check for >= 100? has this any special meaning when creating
* attributes? * attributes?
* *
* @param integer $attribute * @param integer $attribute
...@@ -317,12 +315,12 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -317,12 +315,12 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
{ {
return $this->_name; return $this->_name;
} }
public function setName($name) public function setName($name)
{ {
$this->_name = $name; $this->_name = $name;
} }
public function getDriverName() public function getDriverName()
{ {
return $this->driverName; return $this->driverName;
...@@ -405,12 +403,12 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -405,12 +403,12 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
$e = explode(':', $this->options['dsn']); $e = explode(':', $this->options['dsn']);
$found = false; $found = false;
if (extension_loaded('pdo')) { if (extension_loaded('pdo')) {
if (in_array($e[0], PDO::getAvailableDrivers())) { if (in_array($e[0], PDO::getAvailableDrivers())) {
$this->dbh = new PDO($this->options['dsn'], $this->options['username'], $this->dbh = new PDO($this->options['dsn'], $this->options['username'],
$this->options['password'], $this->options['other']); $this->options['password'], $this->options['other']);
$this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$found = true; $found = true;
} }
...@@ -422,7 +420,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -422,7 +420,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
if (class_exists($class)) { if (class_exists($class)) {
$this->dbh = new $class($this->options['dsn'], $this->options['username'], $this->options['password']); $this->dbh = new $class($this->options['dsn'], $this->options['username'], $this->options['password']);
} else { } else {
throw new Doctrine_Connection_Exception("Couldn't locate driver named " . $e[0]); throw new Doctrine_Connection_Exception("Couldn't locate driver named " . $e[0]);
} }
} }
...@@ -440,8 +438,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -440,8 +438,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
$this->getListener()->postConnect($event); $this->getListener()->postConnect($event);
return true; return true;
} }
public function incrementQueryCount() public function incrementQueryCount()
{ {
$this->_count++; $this->_count++;
} }
...@@ -618,9 +616,9 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -618,9 +616,9 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
$a[] = '?'; $a[] = '?';
} }
} }
// build the statement // build the statement
$query = 'INSERT INTO ' . $this->quoteIdentifier($tableName) $query = 'INSERT INTO ' . $this->quoteIdentifier($tableName)
. ' (' . implode(', ', $cols) . ') ' . ' (' . implode(', ', $cols) . ') '
. 'VALUES ('; . 'VALUES (';
...@@ -628,7 +626,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -628,7 +626,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
// prepare and execute the statement // prepare and execute the statement
return $this->exec($query, array_values($fields)); return $this->exec($query, array_values($fields));
} }
/** /**
* Set the charset on the current connection * Set the charset on the current connection
...@@ -677,8 +675,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -677,8 +675,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
// quick fix for the identifiers that contain a dot // quick fix for the identifiers that contain a dot
if (strpos($str, '.')) { if (strpos($str, '.')) {
$e = explode('.', $str); $e = explode('.', $str);
return $this->formatter->quoteIdentifier($e[0], $checkOption) . '.' return $this->formatter->quoteIdentifier($e[0], $checkOption) . '.'
. $this->formatter->quoteIdentifier($e[1], $checkOption); . $this->formatter->quoteIdentifier($e[1], $checkOption);
} }
return $this->formatter->quoteIdentifier($str, $checkOption); return $this->formatter->quoteIdentifier($str, $checkOption);
...@@ -730,7 +728,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -730,7 +728,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @param array $params prepared statement params * @param array $params prepared statement params
* @return array * @return array
*/ */
public function fetchAll($statement, array $params = array()) public function fetchAll($statement, array $params = array())
{ {
return $this->execute($statement, $params)->fetchAll(Doctrine::FETCH_ASSOC); return $this->execute($statement, $params)->fetchAll(Doctrine::FETCH_ASSOC);
} }
...@@ -743,7 +741,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -743,7 +741,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @param int $colnum 0-indexed column number to retrieve * @param int $colnum 0-indexed column number to retrieve
* @return mixed * @return mixed
*/ */
public function fetchOne($statement, array $params = array(), $colnum = 0) public function fetchOne($statement, array $params = array(), $colnum = 0)
{ {
return $this->execute($statement, $params)->fetchColumn($colnum); return $this->execute($statement, $params)->fetchColumn($colnum);
} }
...@@ -755,7 +753,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -755,7 +753,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @param array $params prepared statement params * @param array $params prepared statement params
* @return array * @return array
*/ */
public function fetchRow($statement, array $params = array()) public function fetchRow($statement, array $params = array())
{ {
return $this->execute($statement, $params)->fetch(Doctrine::FETCH_ASSOC); return $this->execute($statement, $params)->fetch(Doctrine::FETCH_ASSOC);
} }
...@@ -767,7 +765,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -767,7 +765,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @param array $params prepared statement params * @param array $params prepared statement params
* @return array * @return array
*/ */
public function fetchArray($statement, array $params = array()) public function fetchArray($statement, array $params = array())
{ {
return $this->execute($statement, $params)->fetch(Doctrine::FETCH_NUM); return $this->execute($statement, $params)->fetch(Doctrine::FETCH_NUM);
} }
...@@ -780,7 +778,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -780,7 +778,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @param int $colnum 0-indexed column number to retrieve * @param int $colnum 0-indexed column number to retrieve
* @return array * @return array
*/ */
public function fetchColumn($statement, array $params = array(), $colnum = 0) public function fetchColumn($statement, array $params = array(), $colnum = 0)
{ {
return $this->execute($statement, $params)->fetchAll(Doctrine::FETCH_COLUMN, $colnum); return $this->execute($statement, $params)->fetchAll(Doctrine::FETCH_COLUMN, $colnum);
} }
...@@ -792,7 +790,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -792,7 +790,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @param array $params prepared statement params * @param array $params prepared statement params
* @return array * @return array
*/ */
public function fetchAssoc($statement, array $params = array()) public function fetchAssoc($statement, array $params = array())
{ {
return $this->execute($statement, $params)->fetchAll(Doctrine::FETCH_ASSOC); return $this->execute($statement, $params)->fetchAll(Doctrine::FETCH_ASSOC);
} }
...@@ -804,7 +802,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -804,7 +802,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @param array $params prepared statement params * @param array $params prepared statement params
* @return array * @return array
*/ */
public function fetchBoth($statement, array $params = array()) public function fetchBoth($statement, array $params = array())
{ {
return $this->execute($statement, $params)->fetchAll(Doctrine::FETCH_BOTH); return $this->execute($statement, $params)->fetchAll(Doctrine::FETCH_BOTH);
} }
...@@ -844,17 +842,17 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -844,17 +842,17 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
try { try {
$event = new Doctrine_Event($this, Doctrine_Event::CONN_PREPARE, $statement); $event = new Doctrine_Event($this, Doctrine_Event::CONN_PREPARE, $statement);
$this->getAttribute(Doctrine::ATTR_LISTENER)->prePrepare($event); $this->getAttribute(Doctrine::ATTR_LISTENER)->prePrepare($event);
$stmt = false; $stmt = false;
if ( ! $event->skipOperation) { if ( ! $event->skipOperation) {
$stmt = $this->dbh->prepare($statement); $stmt = $this->dbh->prepare($statement);
} }
$this->getAttribute(Doctrine::ATTR_LISTENER)->postPrepare($event); $this->getAttribute(Doctrine::ATTR_LISTENER)->postPrepare($event);
return new Doctrine_Connection_Statement($this, $stmt); return new Doctrine_Connection_Statement($this, $stmt);
} catch(Doctrine_Adapter_Exception $e) { } catch(Doctrine_Adapter_Exception $e) {
} catch(PDOException $e) { } } catch(PDOException $e) { }
...@@ -881,7 +879,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -881,7 +879,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @return Doctrine_Record|false Doctrine_Record object on success, * @return Doctrine_Record|false Doctrine_Record object on success,
* boolean false on failure * boolean false on failure
*/ */
public function queryOne($query, array $params = array()) public function queryOne($query, array $params = array())
{ {
$parser = new Doctrine_Query($this); $parser = new Doctrine_Query($this);
...@@ -951,7 +949,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -951,7 +949,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
echo $query . "<br /><br />"; echo $query . "<br /><br />";
} }
}*/ }*/
$this->_count++; $this->_count++;
} }
$this->getAttribute(Doctrine::ATTR_LISTENER)->postQuery($event); $this->getAttribute(Doctrine::ATTR_LISTENER)->postQuery($event);
...@@ -1009,7 +1007,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -1009,7 +1007,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
{ {
$event = new Doctrine_Event($this, Doctrine_Event::CONN_ERROR); $event = new Doctrine_Event($this, Doctrine_Event::CONN_ERROR);
$this->getListener()->preError($event); $this->getListener()->preError($event);
$name = 'Doctrine_Connection_' . $this->driverName . '_Exception'; $name = 'Doctrine_Connection_' . $this->driverName . '_Exception';
$exc = new $name($e->getMessage(), (int) $e->getCode()); $exc = new $name($e->getMessage(), (int) $e->getCode());
...@@ -1021,7 +1019,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -1021,7 +1019,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
if ($this->getAttribute(Doctrine::ATTR_THROW_EXCEPTIONS)) { if ($this->getAttribute(Doctrine::ATTR_THROW_EXCEPTIONS)) {
throw $exc; throw $exc;
} }
$this->getListener()->postError($event); $this->getListener()->postError($event);
} }
...@@ -1036,7 +1034,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -1036,7 +1034,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
{ {
return isset($this->tables[$name]); return isset($this->tables[$name]);
} }
/** /**
* Gets the table object that represents the database table that is used to * Gets the table object that represents the database table that is used to
* persist the specified domain class. * persist the specified domain class.
...@@ -1049,22 +1047,27 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -1049,22 +1047,27 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
if (isset($this->tables[$className])) { if (isset($this->tables[$className])) {
return $this->tables[$className]; return $this->tables[$className];
} }
if (!($this->_tableFactory instanceOf Doctrine_Table_Factory)) {
$this->_tableFactory = new Doctrine_Table_Factory($this);
}
$this->_tableFactory->loadTables($className, $this->tables); $this->_tableFactory->loadTables($className, $this->tables);
return $this->tables[$className]; return $this->tables[$className];
} }
/** /**
* Gets a mapper for the specified domain class that is used to map instances of * Gets a mapper for the specified domain class that is used to map instances of
* the class between the relational database and their object representation. * the class between the relational database and their object representation.
* *
* @return Doctrine_Mapper_Abstract The mapper object. * @return Doctrine_Mapper_Abstract The mapper object.
*/ */
public function getMapper($className) public function getMapper($className)
{ {
if (isset($this->_mappers[$className])) { if (isset($this->_mappers[$className])) {
return $this->_mappers[$className]; return $this->_mappers[$className];
} }
$customMapperClass = $className . 'Mapper'; $customMapperClass = $className . 'Mapper';
if (class_exists($customMapperClass, $this->getAttribute(Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES)) && if (class_exists($customMapperClass, $this->getAttribute(Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES)) &&
in_array('Doctrine_Mapper_Abstract', class_parents($customMapperClass))) { in_array('Doctrine_Mapper_Abstract', class_parents($customMapperClass))) {
...@@ -1086,7 +1089,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -1086,7 +1089,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
} }
$this->_mappers[$className] = $mapper; $this->_mappers[$className] = $mapper;
return $mapper; return $mapper;
} }
...@@ -1099,7 +1102,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -1099,7 +1102,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
{ {
return $this->tables; return $this->tables;
} }
public function getMappers() public function getMappers()
{ {
//var_dump($this->_mappers); //var_dump($this->_mappers);
...@@ -1163,11 +1166,11 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -1163,11 +1166,11 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
{ {
return $this->getMapper($name)->create(); return $this->getMapper($name)->create();
} }
/** /**
* Creates a new Doctrine_Query object that operates on this connection. * Creates a new Doctrine_Query object that operates on this connection.
* *
* @return Doctrine_Query * @return Doctrine_Query
*/ */
public function createQuery() public function createQuery()
{ {
...@@ -1228,7 +1231,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -1228,7 +1231,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
$this->getAttribute(Doctrine::ATTR_LISTENER)->preClose($event); $this->getAttribute(Doctrine::ATTR_LISTENER)->preClose($event);
$this->clear(); $this->clear();
unset($this->dbh); unset($this->dbh);
$this->isConnected = false; $this->isConnected = false;
...@@ -1244,7 +1247,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -1244,7 +1247,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
{ {
return $this->transaction->getTransactionLevel(); return $this->transaction->getTransactionLevel();
} }
/** /**
* get the current internal transaction nesting level * get the current internal transaction nesting level
* *
...@@ -1278,7 +1281,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -1278,7 +1281,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
$this->connect(); $this->connect();
return $this->dbh->errorInfo(); return $this->dbh->errorInfo();
} }
/** /**
* getCacheDriver * getCacheDriver
* *
...@@ -1289,7 +1292,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -1289,7 +1292,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
{ {
return $this->getResultCacheDriver(); return $this->getResultCacheDriver();
} }
/** /**
* getResultCacheDriver * getResultCacheDriver
* *
...@@ -1302,7 +1305,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -1302,7 +1305,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
} }
return $this->getAttribute(Doctrine::ATTR_RESULT_CACHE); return $this->getAttribute(Doctrine::ATTR_RESULT_CACHE);
} }
/** /**
* getQueryCacheDriver * getQueryCacheDriver
* *
...@@ -1322,7 +1325,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -1322,7 +1325,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* Returns the ID of the last inserted row, or the last value from a sequence object, * Returns the ID of the last inserted row, or the last value from a sequence object,
* depending on the underlying driver. * depending on the underlying driver.
* *
* Note: This method may not return a meaningful or consistent result across different drivers, * Note: This method may not return a meaningful or consistent result across different drivers,
* because the underlying database may not even support the notion of auto-increment fields or sequences. * because the underlying database may not even support the notion of auto-increment fields or sequences.
* *
* @param string $table name of the table into which a new row was inserted * @param string $table name of the table into which a new row was inserted
...@@ -1350,7 +1353,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -1350,7 +1353,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
{ {
return $this->transaction->beginTransaction($savepoint); return $this->transaction->beginTransaction($savepoint);
} }
/** /**
* Initiates a transaction. * Initiates a transaction.
* *
...@@ -1390,7 +1393,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -1390,7 +1393,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* this method can be listened with onPreTransactionRollback and onTransactionRollback * this method can be listened with onPreTransactionRollback and onTransactionRollback
* eventlistener methods * eventlistener methods
* *
* @param string $savepoint name of a savepoint to rollback to * @param string $savepoint name of a savepoint to rollback to
* @throws Doctrine_Transaction_Exception if the rollback operation fails at database level * @throws Doctrine_Transaction_Exception if the rollback operation fails at database level
* @return boolean false if rollback couldn't be performed, true otherwise * @return boolean false if rollback couldn't be performed, true otherwise
*/ */
...@@ -1455,7 +1458,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -1455,7 +1458,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
} }
$info = $this->getManager()->parsePdoDsn($dsn); $info = $this->getManager()->parsePdoDsn($dsn);
$this->export->dropDatabase($info['dbname']); $this->export->dropDatabase($info['dbname']);
return 'Successfully dropped database for connection "' . $this->getName() . '" named "' . $info['dbname'] . '"'; return 'Successfully dropped database for connection "' . $this->getName() . '" named "' . $info['dbname'] . '"';
...@@ -1472,4 +1475,4 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -1472,4 +1475,4 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
{ {
return Doctrine_Lib::getConnectionAsString($this); return Doctrine_Lib::getConnectionAsString($this);
} }
} }
\ No newline at end of file
...@@ -63,7 +63,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera ...@@ -63,7 +63,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
* @var Doctrine_Query_Registry the query registry * @var Doctrine_Query_Registry the query registry
*/ */
protected $_queryRegistry; protected $_queryRegistry;
protected static $driverMap = array('oci' => 'oracle'); protected static $driverMap = array('oci' => 'oracle');
/** /**
...@@ -95,7 +95,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera ...@@ -95,7 +95,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
Doctrine::ATTR_QUERY_CACHE => null, Doctrine::ATTR_QUERY_CACHE => null,
Doctrine::ATTR_LOAD_REFERENCES => true, Doctrine::ATTR_LOAD_REFERENCES => true,
Doctrine::ATTR_LISTENER => new Doctrine_EventListener(), Doctrine::ATTR_LISTENER => new Doctrine_EventListener(),
Doctrine::ATTR_RECORD_LISTENER => new Doctrine_Record_Listener(), Doctrine::ATTR_RECORD_LISTENER => null,
Doctrine::ATTR_THROW_EXCEPTIONS => true, Doctrine::ATTR_THROW_EXCEPTIONS => true,
Doctrine::ATTR_VALIDATE => Doctrine::VALIDATE_NONE, Doctrine::ATTR_VALIDATE => Doctrine::VALIDATE_NONE,
Doctrine::ATTR_QUERY_LIMIT => Doctrine::LIMIT_RECORDS, Doctrine::ATTR_QUERY_LIMIT => Doctrine::LIMIT_RECORDS,
...@@ -109,7 +109,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera ...@@ -109,7 +109,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
Doctrine::ATTR_DECIMAL_PLACES => 2, Doctrine::ATTR_DECIMAL_PLACES => 2,
Doctrine::ATTR_DEFAULT_PARAM_NAMESPACE => 'doctrine', Doctrine::ATTR_DEFAULT_PARAM_NAMESPACE => 'doctrine',
Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES => true, Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES => true,
); );
foreach ($attributes as $attribute => $value) { foreach ($attributes as $attribute => $value) {
$old = $this->getAttribute($attribute); $old = $this->getAttribute($attribute);
if ($old === null) { if ($old === null) {
...@@ -170,16 +170,16 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera ...@@ -170,16 +170,16 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
public function setQueryRegistry(Doctrine_Query_Registry $registry) public function setQueryRegistry(Doctrine_Query_Registry $registry)
{ {
$this->_queryRegistry = $registry; $this->_queryRegistry = $registry;
return $this; return $this;
} }
/** /**
* fetch * fetch
* fetches data using the provided queryKey and * fetches data using the provided queryKey and
* the associated query in the query registry * the associated query in the query registry
* *
* if no query for given queryKey is being found a * if no query for given queryKey is being found a
* Doctrine_Query_Registry exception is being thrown * Doctrine_Query_Registry exception is being thrown
* *
* @param string $queryKey the query key * @param string $queryKey the query key
...@@ -196,10 +196,10 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera ...@@ -196,10 +196,10 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
/** /**
* fetchOne * fetchOne
* fetches data using the provided queryKey and * fetches data using the provided queryKey and
* the associated query in the query registry * the associated query in the query registry
* *
* if no query for given queryKey is being found a * if no query for given queryKey is being found a
* Doctrine_Query_Registry exception is being thrown * Doctrine_Query_Registry exception is being thrown
* *
* @param string $queryKey the query key * @param string $queryKey the query key
...@@ -269,7 +269,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera ...@@ -269,7 +269,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
$parts['scheme'] = $e[0]; $parts['scheme'] = $e[0];
$parts['user'] = (isset($adapter[1])) ? $adapter[1] : null; $parts['user'] = (isset($adapter[1])) ? $adapter[1] : null;
$parts['pass'] = (isset($adapter[2])) ? $adapter[2] : null; $parts['pass'] = (isset($adapter[2])) ? $adapter[2] : null;
$driverName = $e[0]; $driverName = $e[0];
$adapter = $parts; $adapter = $parts;
} else { } else {
...@@ -305,11 +305,11 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera ...@@ -305,11 +305,11 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
'firebird' => 'Doctrine_Connection_Firebird', 'firebird' => 'Doctrine_Connection_Firebird',
'informix' => 'Doctrine_Connection_Informix', 'informix' => 'Doctrine_Connection_Informix',
'mock' => 'Doctrine_Connection_Mock'); 'mock' => 'Doctrine_Connection_Mock');
if ( ! isset($drivers[$driverName])) { if ( ! isset($drivers[$driverName])) {
throw new Doctrine_Manager_Exception('Unknown driver ' . $driverName); throw new Doctrine_Manager_Exception('Unknown driver ' . $driverName);
} }
$className = $drivers[$driverName]; $className = $drivers[$driverName];
$conn = new $className($this, $adapter); $conn = new $className($this, $adapter);
$conn->setName($name); $conn->setName($name);
...@@ -321,17 +321,17 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera ...@@ -321,17 +321,17 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
} }
return $this->_connections[$name]; return $this->_connections[$name];
} }
/** /**
* parsePdoDsn * parsePdoDsn
* *
* @param array $dsn An array of dsn information * @param array $dsn An array of dsn information
* @return array The array parsed * @return array The array parsed
*/ */
public function parsePdoDsn($dsn) public function parsePdoDsn($dsn)
{ {
$parts = array(); $parts = array();
$names = array('dsn', 'scheme', 'host', 'port', 'user', 'pass', 'path', 'query', 'fragment'); $names = array('dsn', 'scheme', 'host', 'port', 'user', 'pass', 'path', 'query', 'fragment');
foreach ($names as $name) { foreach ($names as $name) {
...@@ -339,11 +339,11 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera ...@@ -339,11 +339,11 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
$parts[$name] = null; $parts[$name] = null;
} }
} }
$e = explode(':', $dsn); $e = explode(':', $dsn);
$parts['scheme'] = $e[0]; $parts['scheme'] = $e[0];
$parts['dsn'] = $dsn; $parts['dsn'] = $dsn;
$e = explode(';', $e[1]); $e = explode(';', $e[1]);
foreach ($e as $string) { foreach ($e as $string) {
if ($string) { if ($string) {
...@@ -370,7 +370,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera ...@@ -370,7 +370,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
// fix sqlite dsn so that it will parse correctly // fix sqlite dsn so that it will parse correctly
$dsn = str_replace("////", "/", $dsn); $dsn = str_replace("////", "/", $dsn);
$dsn = str_replace("///c:/", "//c:/", $dsn); $dsn = str_replace("///c:/", "//c:/", $dsn);
// silence any warnings // silence any warnings
$parts = @parse_url($dsn); $parts = @parse_url($dsn);
...@@ -404,7 +404,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera ...@@ -404,7 +404,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
} }
break; break;
case 'mssql': case 'mssql':
case 'dblib': case 'dblib':
if ( ! isset($parts['path']) || $parts['path'] == '/') { if ( ! isset($parts['path']) || $parts['path'] == '/') {
...@@ -416,7 +416,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera ...@@ -416,7 +416,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
if ( ! isset($parts['host'])) { if ( ! isset($parts['host'])) {
throw new Doctrine_Manager_Exception('No hostname set in data source name'); throw new Doctrine_Manager_Exception('No hostname set in data source name');
} }
if (isset(self::$driverMap[$parts['scheme']])) { if (isset(self::$driverMap[$parts['scheme']])) {
$parts['scheme'] = self::$driverMap[$parts['scheme']]; $parts['scheme'] = self::$driverMap[$parts['scheme']];
} }
...@@ -424,7 +424,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera ...@@ -424,7 +424,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
$parts['dsn'] = $parts['scheme'] . ':host=' $parts['dsn'] = $parts['scheme'] . ':host='
. $parts['host'] . (isset($parts['port']) ? ':' . $parts['port']:null) . ';dbname=' . $parts['host'] . (isset($parts['port']) ? ':' . $parts['port']:null) . ';dbname='
. $parts['database']; . $parts['database'];
break; break;
case 'mysql': case 'mysql':
...@@ -445,7 +445,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera ...@@ -445,7 +445,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
if ( ! isset($parts['host'])) { if ( ! isset($parts['host'])) {
throw new Doctrine_Manager_Exception('No hostname set in data source name'); throw new Doctrine_Manager_Exception('No hostname set in data source name');
} }
if (isset(self::$driverMap[$parts['scheme']])) { if (isset(self::$driverMap[$parts['scheme']])) {
$parts['scheme'] = self::$driverMap[$parts['scheme']]; $parts['scheme'] = self::$driverMap[$parts['scheme']];
} }
...@@ -453,7 +453,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera ...@@ -453,7 +453,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
$parts['dsn'] = $parts['scheme'] . ':host=' $parts['dsn'] = $parts['scheme'] . ':host='
. $parts['host'] . (isset($parts['port']) ? ';port=' . $parts['port']:null) . ';dbname=' . $parts['host'] . (isset($parts['port']) ? ';port=' . $parts['port']:null) . ';dbname='
. $parts['database']; . $parts['database'];
break; break;
default: default:
throw new Doctrine_Manager_Exception('Unknown driver '.$parts['scheme']); throw new Doctrine_Manager_Exception('Unknown driver '.$parts['scheme']);
...@@ -550,7 +550,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera ...@@ -550,7 +550,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
} }
return $this->getCurrentConnection(); return $this->getCurrentConnection();
} }
/** /**
* hasConnectionForComponent * hasConnectionForComponent
* *
...@@ -575,7 +575,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera ...@@ -575,7 +575,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
{ {
return $this->getConnectionForComponent($componentName)->getTable($componentName); return $this->getConnectionForComponent($componentName)->getTable($componentName);
} }
/** /**
* getMapper * getMapper
* Returns the mapper object for the given component name. * Returns the mapper object for the given component name.
...@@ -770,4 +770,4 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera ...@@ -770,4 +770,4 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
$r[] = "</pre>"; $r[] = "</pre>";
return implode("\n",$r); return implode("\n",$r);
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment