diff --git a/lib/Doctrine/EntityManager.php b/lib/Doctrine/EntityManager.php index 0459e2cd3..3a2c74c86 100644 --- a/lib/Doctrine/EntityManager.php +++ b/lib/Doctrine/EntityManager.php @@ -698,8 +698,8 @@ class Doctrine_EntityManager * @param Doctrine::Common::EventManager $eventManager The EventManager instance to use. * @return Doctrine::ORM::EntityManager The created EntityManager. */ - public static function create($conn, $name, Doctrine_Configuration $config = null, - Doctrine_EventManager $eventManager = null) + public static function create($conn, $name, Doctrine_Common_Configuration $config = null, + Doctrine_Common_EventManager $eventManager = null) { if (is_array($conn)) { $connFactory = new Doctrine_DBAL_DriverManager(); @@ -709,10 +709,10 @@ class Doctrine_EntityManager } if (is_null($config)) { - $config = new Doctrine_Configuration(); + $config = new Doctrine_Common_Configuration(); } if (is_null($eventManager)) { - $eventManager = new Doctrine_EventManager(); + $eventManager = new Doctrine_Common_EventManager(); } $em = new Doctrine_EntityManager($conn, $name, $config, $eventManager); diff --git a/lib/Doctrine/Collection.php b/lib/Doctrine/ORM/Collection.php similarity index 99% rename from lib/Doctrine/Collection.php rename to lib/Doctrine/ORM/Collection.php index 3c3e1f23a..35043901f 100644 --- a/lib/Doctrine/Collection.php +++ b/lib/Doctrine/ORM/Collection.php @@ -1,6 +1,6 @@ * @author Roman Borschel * @todo Add more typical Collection methods. */ -class Doctrine_Collection implements Countable, IteratorAggregate, Serializable, ArrayAccess +class Doctrine_ORM_Collection implements Countable, IteratorAggregate, Serializable, ArrayAccess { /** * The base type of the collection. diff --git a/lib/Doctrine/ORM/Entity.php b/lib/Doctrine/ORM/Entity.php index 86c9b69fc..384224798 100644 --- a/lib/Doctrine/ORM/Entity.php +++ b/lib/Doctrine/ORM/Entity.php @@ -543,7 +543,7 @@ abstract class Doctrine_ORM_Entity implements ArrayAccess, Serializable if ($rel->isOneToOne() && ! $value instanceof Doctrine_ORM_Entity) { throw Doctrine_Entity_Exception::invalidValueForOneToOneReference(); - } else if (($rel->isOneToMany() || $rel->isManyToMany()) && ! $value instanceof Doctrine_Collection) { + } else if (($rel->isOneToMany() || $rel->isManyToMany()) && ! $value instanceof Doctrine_ORM_Collection) { throw Doctrine_Entity_Exception::invalidValueForOneToManyReference(); } diff --git a/lib/Doctrine/ORM/Internal/Hydration/ObjectDriver.php b/lib/Doctrine/ORM/Internal/Hydration/ObjectDriver.php index 063b14a19..d63d9f0b9 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/ObjectDriver.php +++ b/lib/Doctrine/ORM/Internal/Hydration/ObjectDriver.php @@ -49,7 +49,7 @@ class Doctrine_ORM_Internal_Hydration_ObjectDriver public function getElementCollection($component) { - $coll = new Doctrine_Collection($component); + $coll = new Doctrine_ORM_Collection($component); $this->_collections[] = $coll; return $coll; @@ -80,7 +80,7 @@ class Doctrine_ORM_Internal_Hydration_ObjectDriver } } - public function registerCollection(Doctrine_Collection $coll) + public function registerCollection(Doctrine_ORM_Collection $coll) { $this->_collections[] = $coll; } diff --git a/lib/Doctrine/Sequence.php b/lib/Doctrine/Sequence.php deleted file mode 100644 index 71afd61e7..000000000 --- a/lib/Doctrine/Sequence.php +++ /dev/null @@ -1,73 +0,0 @@ -. - */ - -/** - * The base class for sequence handling drivers. - * - * @package Doctrine - * @subpackage Sequence - * @author Konsta Vesterinen - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Sequence extends Doctrine_Connection_Module -{ - /** - * Returns the next free id of a sequence - * - * @param string $seqName name of the sequence - * @param bool when true missing sequences are automatic created - * - * @return integer next id in the given sequence - */ - public function nextId($seqName, $ondemand = true) - { - throw new Doctrine_Sequence_Exception('method not implemented'); - } - - /** - * Returns the autoincrement ID if supported or $id or fetches the current - * ID in a sequence called: $table.(empty($field) ? '' : '_'.$field) - * - * @param string name of the table into which a new row was inserted - * @param string name of the field into which a new row was inserted - */ - public function lastInsertId($table = null, $field = null) - { - throw new Doctrine_Sequence_Exception('method not implemented'); - } - - /** - * Returns the current id of a sequence - * - * @param string $seqName name of the sequence - * - * @return integer current id in the given sequence - */ - public function currId($seqName) - { - $this->warnings[] = 'database does not support getting current - sequence value, the sequence value was incremented'; - return $this->nextId($seqName); - } -} \ No newline at end of file diff --git a/lib/Doctrine/Transaction.php b/lib/Doctrine/Transaction.php deleted file mode 100644 index ed204fee1..000000000 --- a/lib/Doctrine/Transaction.php +++ /dev/null @@ -1,337 +0,0 @@ -. - */ - -#namespace Doctrine::DBAL::Transactions; - -/** - * Handles transaction savepoint and isolation abstraction - * - * @author Konsta Vesterinen - * @author Lukas Smith (PEAR MDB2 library) - * @author Roman Borschel - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link www.phpdoctrine.org - * @since 1.0 - * @version $Revision$ - * @deprecated - */ -class Doctrine_Transaction extends Doctrine_Connection_Module -{ - /** - * A transaction is in sleep state when it is not active. - */ - const STATE_SLEEP = 0; - - /** - * A transaction is in active state when it is active. - */ - const STATE_ACTIVE = 1; - - /** - * A transaction is in busy state when it is active and has a nesting level > 1. - */ - const STATE_BUSY = 2; - - /** - * @var integer $_nestingLevel The current nesting level of this transaction. - * A nesting level of 0 means there is currently no active - * transaction. - */ - protected $_nestingLevel = 0; - - /** - * @var array $savepoints an array containing all savepoints - */ - protected $savePoints = array(); - - /** - * Returns the state of this transaction module. - * - * @see Doctrine_Connection_Transaction::STATE_* constants - * @return integer the connection state - */ - public function getState() - { - switch ($this->_nestingLevel) { - case 0: - return self::STATE_SLEEP; - break; - case 1: - return self::STATE_ACTIVE; - break; - default: - return self::STATE_BUSY; - } - } - - /** - * Gets the current transaction nesting level. - * - * @return integer - * @todo Name suggestion: getNestingLevel(). $transaction->getTransactionLevel() looks odd. - */ - public function getTransactionLevel() - { - return $this->_nestingLevel; - } - - /** - * Start a transaction or set a savepoint. - * - * if trying to set a savepoint and there is no active transaction - * a new transaction is being started - * - * This method should only be used by userland-code to initiate transactions. - * To initiate a transaction from inside Doctrine use {@link beginInternalTransaction()}. - * - * Listeners: onPreTransactionBegin, onTransactionBegin - * - * @param string $savepoint name of a savepoint to set - * @throws Doctrine_Transaction_Exception if the transaction fails at database level - * @return integer current transaction nesting level - */ - public function begin($savepoint = null) - { - $this->conn->connect(); - - if ( ! is_null($savepoint)) { - $this->savePoints[] = $savepoint; - $this->createSavePoint($savepoint); - } else { - if ($this->_nestingLevel == 0) { - try { - $this->_doBeginTransaction(); - } catch (Exception $e) { - throw new Doctrine_Transaction_Exception($e->getMessage()); - } - } - } - - $level = ++$this->_nestingLevel; - - return $level; - } - - /** - * Commits the database changes done during a transaction that is in - * progress or release a savepoint. This function may only be called when - * auto-committing is disabled, otherwise it will fail. - * - * Listeners: preTransactionCommit, postTransactionCommit - * - * @param string $savepoint name of a savepoint to release - * @throws Doctrine_Transaction_Exception if the transaction fails at database level - * @throws Doctrine_Validator_Exception if the transaction fails due to record validations - * @return boolean false if commit couldn't be performed, true otherwise - */ - public function commit($savepoint = null) - { - if ($this->_nestingLevel == 0) { - throw new Doctrine_Transaction_Exception("Commit failed. There is no active transaction."); - } - - $this->conn->connect(); - - if ( ! is_null($savepoint)) { - $this->_nestingLevel -= $this->removeSavePoints($savepoint); - $this->releaseSavePoint($savepoint); - } else { - if ($this->_nestingLevel == 1) { - $this->_doCommit(); - } - - if ($this->_nestingLevel > 0) { - $this->_nestingLevel--; - } - } - - return true; - } - - /** - * Cancel any database changes done during a transaction or since a specific - * savepoint that is in progress. This function may only be called when - * auto-committing is disabled, otherwise it will fail. Therefore, a new - * transaction is implicitly started after canceling the pending changes. - * - * this method can be listened with onPreTransactionRollback and onTransactionRollback - * eventlistener methods - * - * @param string $savepoint name of a savepoint to rollback to - * @throws Doctrine_Transaction_Exception if the rollback operation fails at database level - * @return boolean false if rollback couldn't be performed, true otherwise - */ - public function rollback($savepoint = null) - { - if ($this->_nestingLevel == 0) { - throw new Doctrine_Transaction_Exception("Rollback failed. There is no active transaction."); - } - - $this->conn->connect(); - - if ($this->_nestingLevel > 1) { - $this->_nestingLevel--; - return false; - } - - $listener = $this->conn->getAttribute(Doctrine::ATTR_LISTENER); - - if ( ! is_null($savepoint)) { - $this->_nestingLevel -= $this->removeSavePoints($savepoint); - $this->rollbackSavePoint($savepoint); - } else { - $this->_nestingLevel = 0; - try { - $this->_doRollback(); - } catch (Exception $e) { - throw new Doctrine_Transaction_Exception($e->getMessage()); - } - } - - return true; - } - - /** - * Creates a new savepoint. - * - * @param string $savepoint name of a savepoint to create - * @return void - */ - protected function createSavePoint($savepoint) - { - throw new Doctrine_Transaction_Exception('Savepoints not supported by this driver.'); - } - - /** - * Releases given savepoint. - * - * @param string $savepoint name of a savepoint to release - * @return void - */ - protected function releaseSavePoint($savepoint) - { - throw new Doctrine_Transaction_Exception('Savepoints not supported by this driver.'); - } - - /** - * Performs a rollback to a specified savepoint. - * - * @param string $savepoint name of a savepoint to rollback to - * @return void - */ - protected function rollbackSavePoint($savepoint) - { - throw new Doctrine_Transaction_Exception('Savepoints not supported by this driver.'); - } - - /** - * Performs the rollback. - */ - protected function _doRollback() - { - $this->conn->getDbh()->rollback(); - } - - /** - * Performs the commit. - */ - protected function _doCommit() - { - $this->conn->getDbh()->commit(); - } - - /** - * Begins a database transaction. - */ - protected function _doBeginTransaction() - { - $this->conn->getDbh()->beginTransaction(); - } - - /** - * removes a savepoint from the internal savePoints array of this transaction object - * and all its children savepoints - * - * @param sring $savepoint name of the savepoint to remove - * @return integer removed savepoints - */ - private function removeSavePoints($savepoint) - { - $this->savePoints = array_values($this->savePoints); - - $found = false; - $i = 0; - - foreach ($this->savePoints as $key => $sp) { - if ( ! $found) { - if ($sp === $savepoint) { - $found = true; - } - } - if ($found) { - $i++; - unset($this->savePoints[$key]); - } - } - - return $i; - } - - /** - * Set the transacton isolation level. - * (implemented by the connection drivers) - * - * example: - * - * - * $tx->setIsolation('READ UNCOMMITTED'); - * - * - * @param string standard isolation level - * READ UNCOMMITTED (allows dirty reads) - * READ COMMITTED (prevents dirty reads) - * REPEATABLE READ (prevents nonrepeatable reads) - * SERIALIZABLE (prevents phantom reads) - * - * @throws Doctrine_Transaction_Exception if the feature is not supported by the driver - * @throws PDOException if something fails at the PDO level - * @return void - */ - public function setIsolation($isolation) - { - throw new Doctrine_Transaction_Exception('Transaction isolation levels not supported by this driver.'); - } - - /** - * Fetches the current session transaction isolation level. - * - * note: some drivers may support setting the transaction isolation level - * but not fetching it - * - * @throws Doctrine_Transaction_Exception if the feature is not supported by the driver - * @throws PDOException if something fails at the PDO level - * @return string returns the current session transaction isolation level - */ - public function getIsolation() - { - throw new Doctrine_Transaction_Exception('Fetching transaction isolation level not supported by this driver.'); - } -} diff --git a/tests/Orm/Component/CollectionTest.php b/tests/Orm/Component/CollectionTest.php index 500770889..ab85af23c 100644 --- a/tests/Orm/Component/CollectionTest.php +++ b/tests/Orm/Component/CollectionTest.php @@ -41,10 +41,10 @@ class Orm_Component_CollectionTest extends Doctrine_OrmTestCase { parent::setUp(); - $this->coll = new Doctrine_Collection('ForumUser'); + $this->coll = new Doctrine_ORM_Collection('ForumUser'); //we create a CmsUser with username as key column and add a user to it - $cmsColl = new Doctrine_Collection('CmsUser', 'username'); + $cmsColl = new Doctrine_ORM_Collection('CmsUser', 'username'); $user = new CmsUser(); $user->username ='test'; $cmsColl[] = $user; @@ -67,7 +67,7 @@ class Orm_Component_CollectionTest extends Doctrine_OrmTestCase */ public function shouldUseSpecifiedKeyColumn() { - $coll = new Doctrine_Collection('ForumUser', 'id'); + $coll = new Doctrine_ORM_Collection('ForumUser', 'id'); $this->assertEquals('id', $coll->getKeyField()); } @@ -80,7 +80,7 @@ class Orm_Component_CollectionTest extends Doctrine_OrmTestCase */ public function shouldThrowExceptionIfNonValidFieldSetAsKey() { - $coll = new Doctrine_Collection('ForumUser', 'xxNonValidFieldxx'); + $coll = new Doctrine_ORM_Collection('ForumUser', 'xxNonValidFieldxx'); } /** @@ -99,7 +99,7 @@ class Orm_Component_CollectionTest extends Doctrine_OrmTestCase { $serialized = serialize($this->coll); $coll = unserialize($serialized); - $this->assertEquals('Doctrine_Collection', get_class($coll)); + $this->assertEquals('Doctrine_ORM_Collection', get_class($coll)); } /** diff --git a/tests/Orm/Hydration/BasicHydrationTest.php b/tests/Orm/Hydration/BasicHydrationTest.php index 628402229..b051d4c73 100644 --- a/tests/Orm/Hydration/BasicHydrationTest.php +++ b/tests/Orm/Hydration/BasicHydrationTest.php @@ -85,7 +85,7 @@ class Orm_Hydration_BasicHydrationTest extends Doctrine_OrmTestCase } if ($hydrationMode == Doctrine::HYDRATE_RECORD) { - $this->assertTrue($result instanceof Doctrine_Collection); + $this->assertTrue($result instanceof Doctrine_ORM_Collection); $this->assertTrue($result[0] instanceof Doctrine_ORM_Entity); $this->assertTrue($result[1] instanceof Doctrine_ORM_Entity); } else if ($hydrationMode == Doctrine::HYDRATE_ARRAY) { @@ -187,11 +187,11 @@ class Orm_Hydration_BasicHydrationTest extends Doctrine_OrmTestCase if ($hydrationMode == Doctrine::HYDRATE_RECORD) { $this->assertTrue($result[0][0] instanceof Doctrine_ORM_Entity); - $this->assertTrue($result[0][0]['phonenumbers'] instanceof Doctrine_Collection); + $this->assertTrue($result[0][0]['phonenumbers'] instanceof Doctrine_ORM_Collection); $this->assertTrue($result[0][0]['phonenumbers'][0] instanceof Doctrine_ORM_Entity); $this->assertTrue($result[0][0]['phonenumbers'][1] instanceof Doctrine_ORM_Entity); $this->assertTrue($result[1][0] instanceof Doctrine_ORM_Entity); - $this->assertTrue($result[1][0]['phonenumbers'] instanceof Doctrine_Collection); + $this->assertTrue($result[1][0]['phonenumbers'] instanceof Doctrine_ORM_Collection); } else if ($hydrationMode == Doctrine::HYDRATE_SCALAR) { $this->assertTrue(is_array($result)); $this->assertEquals(3, count($result)); @@ -379,7 +379,7 @@ class Orm_Hydration_BasicHydrationTest extends Doctrine_OrmTestCase if ($hydrationMode == Doctrine::HYDRATE_RECORD) { $this->assertTrue($result[0]['1'] instanceof Doctrine_ORM_Entity); $this->assertTrue($result[1]['2'] instanceof Doctrine_ORM_Entity); - $this->assertTrue($result[0]['1']['phonenumbers'] instanceof Doctrine_Collection); + $this->assertTrue($result[0]['1']['phonenumbers'] instanceof Doctrine_ORM_Collection); $this->assertEquals(2, count($result[0]['1']['phonenumbers'])); } else if ($hydrationMode == Doctrine::HYDRATE_SCALAR) { // NOTE: Indexing has no effect with HYDRATE_SCALAR @@ -522,14 +522,14 @@ class Orm_Hydration_BasicHydrationTest extends Doctrine_OrmTestCase if ($hydrationMode == Doctrine::HYDRATE_RECORD) { $this->assertTrue($result[0][0] instanceof Doctrine_ORM_Entity); - $this->assertTrue($result[0][0]['phonenumbers'] instanceof Doctrine_Collection); + $this->assertTrue($result[0][0]['phonenumbers'] instanceof Doctrine_ORM_Collection); $this->assertTrue($result[0][0]['phonenumbers'][0] instanceof Doctrine_ORM_Entity); $this->assertTrue($result[0][0]['phonenumbers'][1] instanceof Doctrine_ORM_Entity); - $this->assertTrue($result[0][0]['articles'] instanceof Doctrine_Collection); + $this->assertTrue($result[0][0]['articles'] instanceof Doctrine_ORM_Collection); $this->assertTrue($result[0][0]['articles'][0] instanceof Doctrine_ORM_Entity); $this->assertTrue($result[0][0]['articles'][1] instanceof Doctrine_ORM_Entity); $this->assertTrue($result[1][0] instanceof Doctrine_ORM_Entity); - $this->assertTrue($result[1][0]['phonenumbers'] instanceof Doctrine_Collection); + $this->assertTrue($result[1][0]['phonenumbers'] instanceof Doctrine_ORM_Collection); $this->assertTrue($result[1][0]['phonenumbers'][0] instanceof Doctrine_ORM_Entity); $this->assertTrue($result[1][0]['articles'][0] instanceof Doctrine_ORM_Entity); $this->assertTrue($result[1][0]['articles'][1] instanceof Doctrine_ORM_Entity); @@ -708,26 +708,26 @@ class Orm_Hydration_BasicHydrationTest extends Doctrine_OrmTestCase $this->assertTrue($result[0][0] instanceof Doctrine_ORM_Entity); $this->assertTrue($result[1][0] instanceof Doctrine_ORM_Entity); // phonenumbers - $this->assertTrue($result[0][0]['phonenumbers'] instanceof Doctrine_Collection); + $this->assertTrue($result[0][0]['phonenumbers'] instanceof Doctrine_ORM_Collection); $this->assertTrue($result[0][0]['phonenumbers'][0] instanceof Doctrine_ORM_Entity); $this->assertTrue($result[0][0]['phonenumbers'][1] instanceof Doctrine_ORM_Entity); - $this->assertTrue($result[1][0]['phonenumbers'] instanceof Doctrine_Collection); + $this->assertTrue($result[1][0]['phonenumbers'] instanceof Doctrine_ORM_Collection); $this->assertTrue($result[1][0]['phonenumbers'][0] instanceof Doctrine_ORM_Entity); // articles - $this->assertTrue($result[0][0]['articles'] instanceof Doctrine_Collection); + $this->assertTrue($result[0][0]['articles'] instanceof Doctrine_ORM_Collection); $this->assertTrue($result[0][0]['articles'][0] instanceof Doctrine_ORM_Entity); $this->assertTrue($result[0][0]['articles'][1] instanceof Doctrine_ORM_Entity); $this->assertTrue($result[1][0]['articles'][0] instanceof Doctrine_ORM_Entity); $this->assertTrue($result[1][0]['articles'][1] instanceof Doctrine_ORM_Entity); // article comments - $this->assertTrue($result[0][0]['articles'][0]['comments'] instanceof Doctrine_Collection); + $this->assertTrue($result[0][0]['articles'][0]['comments'] instanceof Doctrine_ORM_Collection); $this->assertTrue($result[0][0]['articles'][0]['comments'][0] instanceof Doctrine_ORM_Entity); // empty comment collections - $this->assertTrue($result[0][0]['articles'][1]['comments'] instanceof Doctrine_Collection); + $this->assertTrue($result[0][0]['articles'][1]['comments'] instanceof Doctrine_ORM_Collection); $this->assertEquals(0, count($result[0][0]['articles'][1]['comments'])); - $this->assertTrue($result[1][0]['articles'][0]['comments'] instanceof Doctrine_Collection); + $this->assertTrue($result[1][0]['articles'][0]['comments'] instanceof Doctrine_ORM_Collection); $this->assertEquals(0, count($result[1][0]['articles'][0]['comments'])); - $this->assertTrue($result[1][0]['articles'][1]['comments'] instanceof Doctrine_Collection); + $this->assertTrue($result[1][0]['articles'][1]['comments'] instanceof Doctrine_ORM_Collection); $this->assertEquals(0, count($result[1][0]['articles'][1]['comments'])); } else if ($hydrationMode == Doctrine::HYDRATE_SCALAR) { //... @@ -848,7 +848,7 @@ class Orm_Hydration_BasicHydrationTest extends Doctrine_OrmTestCase $this->assertTrue(is_array($result[0])); $this->assertTrue(is_array($result[1])); } else if ($hydrationMode == Doctrine::HYDRATE_RECORD) { - $this->assertTrue($result instanceof Doctrine_Collection); + $this->assertTrue($result instanceof Doctrine_ORM_Collection); $this->assertTrue($result[0] instanceof Doctrine_ORM_Entity); $this->assertTrue($result[1] instanceof Doctrine_ORM_Entity); } else if ($hydrationMode == Doctrine::HYDRATE_SCALAR) {