Commit e2a0e189 authored by romanb's avatar romanb

minor refactorings on code and API docs

parent c8e4e7e7
This diff is collapsed.
<?php <?php
/**
* PDO implementation of the driver Connection interface.
* Used by all PDO-based drivers.
*
* @since 2.0
*/
class Doctrine_DBAL_Driver_PDOConnection extends PDO implements Doctrine_DBAL_Driver_Connection class Doctrine_DBAL_Driver_PDOConnection extends PDO implements Doctrine_DBAL_Driver_Connection
{ {
public function __construct($dsn, $user = null, $password = null, array $options = null) public function __construct($dsn, $user = null, $password = null, array $options = null)
{ {
parent::__construct($dsn, $user, $password, $options); parent::__construct($dsn, $user, $password, $options);
$this->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('Doctrine_DBAL_Driver_PDOStatement', array())); $this->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('Doctrine_DBAL_Driver_PDOStatement', array()));
$this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
} }
} }
......
...@@ -4,9 +4,22 @@ ...@@ -4,9 +4,22 @@
#use Doctrine::DBAL::Driver; #use Doctrine::DBAL::Driver;
/**
* The PDO Sqlite driver.
*
* @since 2.0
*/
class Doctrine_DBAL_Driver_PDOSqlite_Driver implements Doctrine_DBAL_Driver class Doctrine_DBAL_Driver_PDOSqlite_Driver implements Doctrine_DBAL_Driver
{ {
/**
* Tries to establish a database connection to SQLite.
*
* @param array $params
* @param unknown_type $username
* @param unknown_type $password
* @param array $driverOptions
* @return unknown
*/
public function connect(array $params, $username = null, $password = null, array $driverOptions = array()) public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
{ {
return new Doctrine_DBAL_Driver_PDOConnection( return new Doctrine_DBAL_Driver_PDOConnection(
...@@ -34,11 +47,20 @@ class Doctrine_DBAL_Driver_PDOSqlite_Driver implements Doctrine_DBAL_Driver ...@@ -34,11 +47,20 @@ class Doctrine_DBAL_Driver_PDOSqlite_Driver implements Doctrine_DBAL_Driver
return $dsn; return $dsn;
} }
/**
* Gets the database platform that is relevant for this driver.
*/
public function getDatabasePlatform() public function getDatabasePlatform()
{ {
return new Doctrine_DBAL_Platforms_SqlitePlatform(); return new Doctrine_DBAL_Platforms_SqlitePlatform();
} }
/**
* Gets the schema manager that is relevant for this driver.
*
* @param Doctrine::DBAL::Connection $conn
* @return Doctrine::DBAL::Schema::AbstractSchemaManager
*/
public function getSchemaManager(Doctrine_DBAL_Connection $conn) public function getSchemaManager(Doctrine_DBAL_Connection $conn)
{ {
return new Doctrine_DBAL_Schema_SqliteSchemaManager($conn); return new Doctrine_DBAL_Schema_SqliteSchemaManager($conn);
......
...@@ -22,19 +22,19 @@ ...@@ -22,19 +22,19 @@
#namespace Doctrine::DBAL; #namespace Doctrine::DBAL;
/** /**
* Factory for creating dbms-specific Connection instances. * Factory for creating Doctrine::DBAL::Connection instances.
* *
* @author Roman Borschel <roman@code-factory.org> * @author Roman Borschel <roman@code-factory.org>
* @since 2.0 * @since 2.0
*/ */
class Doctrine_DBAL_DriverManager final class Doctrine_DBAL_DriverManager
{ {
/** /**
* List of supported drivers and their mappings to the driver class. * List of supported drivers and their mappings to the driver class.
* *
* @var array * @var array
*/ */
private $_drivers = array( private static $_driverMap = array(
'pdo_mysql' => 'Doctrine_DBAL_Driver_PDOMySql_Driver', 'pdo_mysql' => 'Doctrine_DBAL_Driver_PDOMySql_Driver',
'pdo_sqlite' => 'Doctrine_DBAL_Driver_PDOSqlite_Driver', 'pdo_sqlite' => 'Doctrine_DBAL_Driver_PDOSqlite_Driver',
'pdo_pgsql' => 'Doctrine_DBAL_Driver_PDOPgSql_Driver', 'pdo_pgsql' => 'Doctrine_DBAL_Driver_PDOPgSql_Driver',
...@@ -44,18 +44,53 @@ class Doctrine_DBAL_DriverManager ...@@ -44,18 +44,53 @@ class Doctrine_DBAL_DriverManager
'pdo_informix' => 'Doctrine_DBAL_Driver_PDOInformix_Driver', 'pdo_informix' => 'Doctrine_DBAL_Driver_PDOInformix_Driver',
); );
public function __construct() private function __construct() {}
{
}
/** /**
* Creates a connection object with the specified parameters. * Creates a connection object based on the specified parameters.
* This method returns a Doctrine::DBAL::Connection which wraps the underlying
* driver connection.
* *
* @param array $params * $params must contain at least one of the following.
* @return Connection *
* Either 'driver' with one of the following values:
* pdo_mysql
* pdo_sqlite
* pdo_pgsql
* pdo_oracle
* pdo_mssql
* pdo_firebird
* pdo_informix
*
* OR 'driverClass' that contains the full class name (with namespace) of the
* driver class to instantiate.
*
* Other (optional) parameters:
*
* <b>user (string)</b>:
* The username to use when connecting.
*
* <b>password (string)</b>:
* The password to use when connecting.
*
* <b>driverOptions (array)</b>:
* Any additional driver-specific options for the driver. These are just passed
* through to the driver.
*
* <b>pdo</b>:
* You can pass an existing PDO instance through this parameter. The PDO
* instance will be wrapped in a Doctrine::DBAL::Connection.
*
* <b>wrapperClass</b>:
* You may specify a custom wrapper class through the 'wrapperClass'
* parameter but this class MUST inherit from Doctrine::DBAL::Connection.
*
* @param array $params The parameters.
* @param Doctrine::Common::Configuration The configuration to use.
* @param Doctrine::Common::EventManager The event manager to use.
* @return Doctrine::DBAL::Connection
*/ */
public function getConnection(array $params, Doctrine_Common_Configuration $config = null, public static function getConnection(array $params, Doctrine_Common_Configuration $config = null,
Doctrine_Common_EventManager $eventManager = null) Doctrine_Common_EventManager $eventManager = null)
{ {
// create default config and event manager, if not set // create default config and event manager, if not set
...@@ -72,18 +107,18 @@ class Doctrine_DBAL_DriverManager ...@@ -72,18 +107,18 @@ class Doctrine_DBAL_DriverManager
} else if (isset($params['pdo'])) { } else if (isset($params['pdo'])) {
$params['driver'] = $params['pdo']->getAttribute(PDO::ATTR_DRIVER_NAME); $params['driver'] = $params['pdo']->getAttribute(PDO::ATTR_DRIVER_NAME);
} else { } else {
$this->_checkParams($params); self::_checkParams($params);
} }
if (isset($params['driverClass'])) { if (isset($params['driverClass'])) {
$className = $params['driverClass']; $className = $params['driverClass'];
} else { } else {
$className = $this->_drivers[$params['driver']]; $className = self::$_driverMap[$params['driver']];
} }
$driver = new $className(); $driver = new $className();
$wrapperClass = 'Doctrine_DBAL_Connection'; $wrapperClass = 'Doctrine_DBAL_Connection';
if (isset($params['wrapperClass'])) { if (isset($params['wrapperClass']) && is_subclass_of($params['wrapperClass'], $wrapperClass)) {
$wrapperClass = $params['wrapperClass']; $wrapperClass = $params['wrapperClass'];
} }
...@@ -95,7 +130,7 @@ class Doctrine_DBAL_DriverManager ...@@ -95,7 +130,7 @@ class Doctrine_DBAL_DriverManager
* *
* @param array $params * @param array $params
*/ */
private function _checkParams(array $params) private static function _checkParams(array $params)
{ {
// check existance of mandatory parameters // check existance of mandatory parameters
...@@ -107,7 +142,7 @@ class Doctrine_DBAL_DriverManager ...@@ -107,7 +142,7 @@ class Doctrine_DBAL_DriverManager
// check validity of parameters // check validity of parameters
// driver // driver
if ( isset($params['driver']) && ! isset($this->_drivers[$params['driver']])) { if ( isset($params['driver']) && ! isset(self::$_driverMap[$params['driver']])) {
throw Doctrine_DBAL_Exceptions_DBALException::unknownDriver($params['driver']); throw Doctrine_DBAL_Exceptions_DBALException::unknownDriver($params['driver']);
} }
} }
......
This diff is collapsed.
...@@ -23,8 +23,7 @@ ...@@ -23,8 +23,7 @@
#use Doctrine::Common::Configuration; #use Doctrine::Common::Configuration;
#use Doctrine::Common::EventManager; #use Doctrine::Common::EventManager;
#use Doctrine::Common::NullObject; #use Doctrine::DBAL::Connection;
#use Doctrine::DBAL::Connections::Connection;
#use Doctrine::ORM::Exceptions::EntityManagerException; #use Doctrine::ORM::Exceptions::EntityManagerException;
#use Doctrine::ORM::Internal::UnitOfWork; #use Doctrine::ORM::Internal::UnitOfWork;
#use Doctrine::ORM::Mapping::ClassMetadata; #use Doctrine::ORM::Mapping::ClassMetadata;
...@@ -355,6 +354,12 @@ class Doctrine_ORM_EntityManager ...@@ -355,6 +354,12 @@ class Doctrine_ORM_EntityManager
$this->_flushMode = $flushMode; $this->_flushMode = $flushMode;
} }
/**
* Checks whether the given value is a valid flush mode.
*
* @param string $value
* @return boolean
*/
private function _isFlushMode($value) private function _isFlushMode($value)
{ {
return $value == self::FLUSHMODE_AUTO || return $value == self::FLUSHMODE_AUTO ||
...@@ -397,34 +402,6 @@ class Doctrine_ORM_EntityManager ...@@ -397,34 +402,6 @@ class Doctrine_ORM_EntityManager
$this->_closed = true; $this->_closed = true;
} }
/**
* Gets the result cache driver used by the EntityManager.
*
* @return Doctrine::ORM::Cache::CacheDriver The cache driver.
*/
public function getResultCacheDriver()
{
if ( ! $this->getAttribute(Doctrine::ATTR_RESULT_CACHE)) {
throw new Doctrine_Exception('Result Cache driver not initialized.');
}
return $this->getAttribute(Doctrine::ATTR_RESULT_CACHE);
}
/**
* getQueryCacheDriver
*
* @return Doctrine_Cache_Interface
*/
public function getQueryCacheDriver()
{
if ( ! $this->getAttribute(Doctrine::ATTR_QUERY_CACHE)) {
throw new Doctrine_Exception('Query Cache driver not initialized.');
}
return $this->getAttribute(Doctrine::ATTR_QUERY_CACHE);
}
/** /**
* Saves the given entity, persisting it's state. * Saves the given entity, persisting it's state.
* *
...@@ -649,6 +626,9 @@ class Doctrine_ORM_EntityManager ...@@ -649,6 +626,9 @@ class Doctrine_ORM_EntityManager
return $this->_config; return $this->_config;
} }
/**
* Throws an exception if the EntityManager is closed or currently not active.
*/
private function _errorIfNotActiveOrClosed() private function _errorIfNotActiveOrClosed()
{ {
if ( ! $this->isActive() || $this->_closed) { if ( ! $this->isActive() || $this->_closed) {
...@@ -702,9 +682,8 @@ class Doctrine_ORM_EntityManager ...@@ -702,9 +682,8 @@ class Doctrine_ORM_EntityManager
Doctrine_Common_EventManager $eventManager = null) Doctrine_Common_EventManager $eventManager = null)
{ {
if (is_array($conn)) { if (is_array($conn)) {
$connFactory = new Doctrine_DBAL_DriverManager(); $conn = Doctrine_DBAL_DriverManager::getConnection($conn, $config, $eventManager);
$conn = $connFactory->getConnection($conn, $config, $eventManager); } else if ( ! $conn instanceof Doctrine_DBAL_Connection) {
} else if ( ! $conn instanceof Doctrine_Connection) {
throw new Doctrine_Exception("Invalid parameter '$conn'."); throw new Doctrine_Exception("Invalid parameter '$conn'.");
} }
...@@ -722,7 +701,9 @@ class Doctrine_ORM_EntityManager ...@@ -722,7 +701,9 @@ class Doctrine_ORM_EntityManager
} }
/** /**
* Gets the currently active EntityManager. * Static lookup to get the currently active EntityManager.
* This is used in the Entity constructor as well as unserialize() to connect
* the Entity with an EntityManager.
* *
* @return Doctrine::ORM::EntityManager * @return Doctrine::ORM::EntityManager
*/ */
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
* correct order in which changes to entities need to be persisted. * correct order in which changes to entities need to be persisted.
* *
* @since 2.0 * @since 2.0
* @todo Rename to: CommitOrderCalculator
* @author Roman Borschel <roman@code-factory.org> * @author Roman Borschel <roman@code-factory.org>
*/ */
class Doctrine_ORM_Internal_CommitOrderCalculator class Doctrine_ORM_Internal_CommitOrderCalculator
...@@ -88,16 +87,34 @@ class Doctrine_ORM_Internal_CommitOrderCalculator ...@@ -88,16 +87,34 @@ class Doctrine_ORM_Internal_CommitOrderCalculator
return $this->_sorted; return $this->_sorted;
} }
/**
* Adds a node to consider when ordering.
*
* @param mixed $key Somme arbitrary key for the node (must be unique!).
* @param unknown_type $node
*/
public function addNode($key, $node) public function addNode($key, $node)
{ {
$this->_nodes[$key] = $node; $this->_nodes[$key] = $node;
} }
/**
* Enter description here...
*
* @param unknown_type $key
* @param unknown_type $item
*/
public function addNodeWithItem($key, $item) public function addNodeWithItem($key, $item)
{ {
$this->_nodes[$key] = new Doctrine_ORM_Internal_CommitOrderNode($item, $this); $this->_nodes[$key] = new Doctrine_ORM_Internal_CommitOrderNode($item, $this);
} }
/**
* Enter description here...
*
* @param unknown_type $key
* @return unknown
*/
public function getNodeForKey($key) public function getNodeForKey($key)
{ {
return $this->_nodes[$key]; return $this->_nodes[$key];
...@@ -108,13 +125,17 @@ class Doctrine_ORM_Internal_CommitOrderCalculator ...@@ -108,13 +125,17 @@ class Doctrine_ORM_Internal_CommitOrderCalculator
return isset($this->_nodes[$key]); return isset($this->_nodes[$key]);
} }
/**
* Clears the current graph and the last result.
*
* @return void
*/
public function clear() public function clear()
{ {
$this->_nodes = array(); $this->_nodes = array();
$this->_sorted = array(); $this->_sorted = array();
} }
public function getNextTime() public function getNextTime()
{ {
return ++$this->_currentTime; return ++$this->_currentTime;
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
#namespace Doctrine::ORM::Internal; #namespace Doctrine::ORM::Internal;
/** /**
* A CommitOrderNode is a temporary wrapper around ClassMetadata objects * A CommitOrderNode is a temporary wrapper around ClassMetadata instances
* that is used to sort the order of commits. * that is used to sort the order of commits.
* *
* @since 2.0 * @since 2.0
...@@ -40,19 +40,32 @@ class Doctrine_ORM_Internal_CommitOrderNode ...@@ -40,19 +40,32 @@ class Doctrine_ORM_Internal_CommitOrderNode
private $_calculator; private $_calculator;
private $_relatedNodes = array(); private $_relatedNodes = array();
/* The "time" when this node was first discovered during traversal */
private $_discoveryTime; private $_discoveryTime;
/* The "time" when this node was finished during traversal */
private $_finishingTime; private $_finishingTime;
/* The wrapped object */
private $_wrappedObj; private $_wrappedObj;
private $_relationEdges = array();
/**
* Constructor.
* Creates a new node.
*
* @param mixed $wrappedObj The object to wrap.
* @param Doctrine::ORM::Internal::CommitOrderCalculator $calc The calculator.
*/
public function __construct($wrappedObj, Doctrine_ORM_Internal_CommitOrderCalculator $calc) public function __construct($wrappedObj, Doctrine_ORM_Internal_CommitOrderCalculator $calc)
{ {
$this->_wrappedObj = $wrappedObj; $this->_wrappedObj = $wrappedObj;
$this->_calculator = $calc; $this->_calculator = $calc;
} }
/**
* Gets the wrapped object.
*
* @return mixed
*/
public function getClass() public function getClass()
{ {
return $this->_wrappedObj; return $this->_wrappedObj;
...@@ -142,7 +155,7 @@ class Doctrine_ORM_Internal_CommitOrderNode ...@@ -142,7 +155,7 @@ class Doctrine_ORM_Internal_CommitOrderNode
/** /**
* Adds a directed dependency (an edge on the graph). "$this -before-> $other". * Adds a directed dependency (an edge on the graph). "$this -before-> $other".
* *
* @param Doctrine_Internal_CommitOrderNode $node * @param Doctrine::ORM::Internal::CommitOrderNode $node
*/ */
public function before(Doctrine_ORM_Internal_CommitOrderNode $node) public function before(Doctrine_ORM_Internal_CommitOrderNode $node)
{ {
......
...@@ -62,9 +62,9 @@ abstract class Doctrine_ORM_Internal_Hydration_AbstractHydrator ...@@ -62,9 +62,9 @@ abstract class Doctrine_ORM_Internal_Hydration_AbstractHydrator
/** /**
* constructor * Constructor.
* *
* @param Doctrine_Connection|null $connection * @param Doctrine::ORM::EntityManager $em The EntityManager to use during hydration.
*/ */
public function __construct(Doctrine_ORM_EntityManager $em) public function __construct(Doctrine_ORM_EntityManager $em)
{ {
...@@ -134,20 +134,14 @@ abstract class Doctrine_ORM_Internal_Hydration_AbstractHydrator ...@@ -134,20 +134,14 @@ abstract class Doctrine_ORM_Internal_Hydration_AbstractHydrator
} }
/** /**
* hydrateResultSet
*
* Processes data returned by statement object. * Processes data returned by statement object.
* *
* This is method defines the core of Doctrine object population algorithm * This is method defines the core of Doctrine object/array population algorithm.
* hence this method strives to be as fast as possible.
*
* The key idea is the loop over the rowset only once doing all the needed operations
* within this massive loop.
* *
* @param mixed $stmt PDOStatement * @param mixed $stmt PDOStatement
* @param integer $hydrationMode Doctrine processing mode to be used during hydration process. * @param integer $hydrationMode Doctrine processing mode to be used during hydration process.
* One of the Doctrine::HYDRATE_* constants. * One of the Doctrine::HYDRATE_* constants.
* @return mixed Doctrine_Collection|array * @return mixed
*/ */
abstract public function hydrateResultSet($parserResult); abstract public function hydrateResultSet($parserResult);
} }
...@@ -126,7 +126,6 @@ class Doctrine_ORM_Internal_Hydration_ArrayDriver ...@@ -126,7 +126,6 @@ class Doctrine_ORM_Internal_Hydration_ArrayDriver
public function getLastKey(&$data) public function getLastKey(&$data)
{ {
end($data); end($data);
return key($data); return key($data);
} }
......
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
* <http://www.phpdoctrine.org>. * <http://www.phpdoctrine.org>.
*/ */
#namespace Doctrine::ORM::Internal::Hydration;
/** /**
* Hydration strategy used for creating graphs of entities. * Hydration strategy used for creating graphs of entities.
* *
...@@ -28,7 +30,6 @@ ...@@ -28,7 +30,6 @@
* @version $Revision$ * @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Roman Borschel <roman@code-factory.org> * @author Roman Borschel <roman@code-factory.org>
* @todo Rename to ObjectDriver
*/ */
class Doctrine_ORM_Internal_Hydration_ObjectDriver class Doctrine_ORM_Internal_Hydration_ObjectDriver
{ {
......
...@@ -4,8 +4,6 @@ class Doctrine_TestUtil ...@@ -4,8 +4,6 @@ class Doctrine_TestUtil
{ {
public static function getConnection() public static function getConnection()
{ {
$connFactory = new Doctrine_DBAL_DriverManager();
if (isset($GLOBALS['db_type'], $GLOBALS['db_username'], $GLOBALS['db_password'], if (isset($GLOBALS['db_type'], $GLOBALS['db_username'], $GLOBALS['db_password'],
$GLOBALS['db_host'], $GLOBALS['db_name'])) { $GLOBALS['db_host'], $GLOBALS['db_name'])) {
$params = array( $params = array(
...@@ -24,7 +22,7 @@ class Doctrine_TestUtil ...@@ -24,7 +22,7 @@ class Doctrine_TestUtil
); );
} }
return $connFactory->getConnection($params); return Doctrine_DBAL_DriverManager::getConnection($params);
} }
/* /*
public static function autoloadModel($className) public static function autoloadModel($className)
......
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