diff --git a/lib/Doctrine/Common/ClassLoader.php b/lib/Doctrine/Common/ClassLoader.php index 329d232b1..d4ad0041c 100644 --- a/lib/Doctrine/Common/ClassLoader.php +++ b/lib/Doctrine/Common/ClassLoader.php @@ -1,4 +1,7 @@ */ -class Doctrine_Common_ClassLoader +class ClassLoader { - private $_namespaceSeparator = '_'; + private $_namespaceSeparator = '\\'; private $_fileExtension = '.php'; private $_checkFileExists = false; private $_basePaths = array(); @@ -71,7 +74,10 @@ class Doctrine_Common_ClassLoader if (isset($this->_basePaths[$prefix])) { $class .= $this->_basePaths[$prefix] . DIRECTORY_SEPARATOR; } - $class .= str_replace($this->_namespaceSeparator, DIRECTORY_SEPARATOR, $className) + + if ($className[0] == '\\') $className = substr($className, 1); + + $class .= str_replace(array($this->_namespaceSeparator, '_'), DIRECTORY_SEPARATOR, $className) . $this->_fileExtension; if ($this->_checkFileExists) { @@ -81,6 +87,21 @@ class Doctrine_Common_ClassLoader @fclose($fh); } + if ($class == 'ForumAvatar.php' || $class == 'ForumUser.php') { + echo $class . PHP_EOL; + try { + throw new \Exception(); + } catch (\Exception $e) { + echo $e->getTraceAsString(); + } + } else if ($class == 'Doctrine/Common/Exceptions/DoctrineException.php') { + try { + throw new \Exception(); + } catch (\Exception $e) { + echo $e->getTraceAsString(); + } + } + require $class; return true; diff --git a/lib/Doctrine/Common/Collections/Collection.php b/lib/Doctrine/Common/Collections/Collection.php index 882524b0c..a6b925f8f 100644 --- a/lib/Doctrine/Common/Collections/Collection.php +++ b/lib/Doctrine/Common/Collections/Collection.php @@ -4,11 +4,11 @@ * and open the template in the editor. */ -#namespace Doctrine\Common\Collections; +namespace Doctrine\Common\Collections; -#use \Countable; -#use \IteratorAggregate; -#use \ArrayAccess; +use \Countable; +use \IteratorAggregate; +use \ArrayAccess; /** * A Collection is a wrapper around a php array and just like a php array a @@ -16,7 +16,7 @@ * * @author robo */ -class Doctrine_Common_Collections_Collection implements Countable, IteratorAggregate, ArrayAccess +class Collection implements Countable, IteratorAggregate, ArrayAccess { /** * An array containing the entries of this collection. @@ -323,7 +323,7 @@ class Doctrine_Common_Collections_Collection implements Countable, IteratorAggre */ public function map(Closure $func) { - return new Doctrine_Common_Collections_Collection(array_map($func, $this->_data)); + return new Collection(array_map($func, $this->_data)); } /** @@ -334,7 +334,7 @@ class Doctrine_Common_Collections_Collection implements Countable, IteratorAggre */ public function filter(Closure $func) { - return new Doctrine_Common_Collections_Collection(array_filter($this->_data, $func)); + return new Collection(array_filter($this->_data, $func)); } /** diff --git a/lib/Doctrine/Common/Exceptions/DoctrineException.php b/lib/Doctrine/Common/DoctrineException.php similarity index 87% rename from lib/Doctrine/Common/Exceptions/DoctrineException.php rename to lib/Doctrine/Common/DoctrineException.php index 428890a94..bb9c94560 100644 --- a/lib/Doctrine/Common/Exceptions/DoctrineException.php +++ b/lib/Doctrine/Common/DoctrineException.php @@ -1,6 +1,8 @@ \ No newline at end of file diff --git a/lib/Doctrine/Common/EventManager.php b/lib/Doctrine/Common/EventManager.php index 3afb80cde..4b43d98c5 100644 --- a/lib/Doctrine/Common/EventManager.php +++ b/lib/Doctrine/Common/EventManager.php @@ -19,7 +19,9 @@ * . */ -#namespace Doctrine\Common; +namespace Doctrine\Common; + +use Doctrine\Common\Events\Event; /** * The EventManager is the central point of Doctrine's event listener system. @@ -30,7 +32,7 @@ * @author Guilherme Blanco * @since 2.0 */ -class Doctrine_Common_EventManager +class EventManager { /** * Map of registered listeners. @@ -52,7 +54,7 @@ class Doctrine_Common_EventManager $callback = $argIsCallback ? $event : $event->getType(); if (isset($this->_listeners[$callback])) { - $event = $argIsCallback ? new Doctrine_Event($event) : $event; + $event = $argIsCallback ? new Event($event) : $event; foreach ($this->_listeners[$callback] as $listener) { $listener->$callback($event); } @@ -103,10 +105,9 @@ class Doctrine_Common_EventManager * * @param Doctrine\Common\EventSubscriber $subscriber The subscriber. */ - public function addEventSubscriber(Doctrine_Common_EventSubscriber $subscriber) + public function addEventSubscriber(EventSubscriber $subscriber) { $this->addEventListener($subscriber->getSubscribedEvents(), $subscriber); } } -?> \ No newline at end of file diff --git a/lib/Doctrine/Common/EventSubscriber.php b/lib/Doctrine/Common/EventSubscriber.php index 1dffe7ee8..a117950f1 100644 --- a/lib/Doctrine/Common/EventSubscriber.php +++ b/lib/Doctrine/Common/EventSubscriber.php @@ -19,7 +19,7 @@ * . */ -#namespace Doctrine::Common; +namespace Doctrine\Common; /** * An EventSubscriber knows himself what events he is interested in. @@ -33,7 +33,7 @@ * @since 2.0 * @version $Revision: 4653 $ */ -interface Doctrine_Common_EventSubscriber +interface EventSubscriber { public function getSubscribedEvents(); } diff --git a/lib/Doctrine/Common/Events/Event.php b/lib/Doctrine/Common/Events/Event.php index 796f4a23d..88dc75603 100644 --- a/lib/Doctrine/Common/Events/Event.php +++ b/lib/Doctrine/Common/Events/Event.php @@ -19,20 +19,18 @@ * . */ -#namespace Doctrine\Common\Events; +namespace Doctrine\Common\Events; /** * Doctrine_Event * * @author Konsta Vesterinen * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @package Doctrine - * @subpackage Event * @link www.phpdoctrine.org * @since 2.0 * @version $Revision$ */ -class Doctrine_Common_Events_Event +class Event { /* Event callback constants */ const preDelete = 'preDelete'; diff --git a/lib/Doctrine/DBAL/Configuration.php b/lib/Doctrine/DBAL/Configuration.php index cf714b05f..a7ad07f4f 100644 --- a/lib/Doctrine/DBAL/Configuration.php +++ b/lib/Doctrine/DBAL/Configuration.php @@ -19,7 +19,9 @@ * . */ -#namespace Doctrine\DBAL; +namespace Doctrine\DBAL; + +use Doctrine\DBAL\Types\Type; /** * Configuration container for the Doctrine DBAL. @@ -30,7 +32,7 @@ * @author Roman Borschel * @since 2.0 */ -class Doctrine_DBAL_Configuration +class Configuration { /** * The attributes that are contained in the configuration. @@ -99,14 +101,14 @@ class Doctrine_DBAL_Configuration public function setCustomTypes(array $types) { foreach ($types as $name => $typeClassName) { - Doctrine_DBAL_Types_Type::addCustomType($name, $typeClassName); + Type::addCustomType($name, $typeClassName); } } public function setTypeOverrides(array $overrides) { foreach ($override as $name => $typeClassName) { - Doctrine_DBAL_Types_Type::overrideType($name, $typeClassName); + Type::overrideType($name, $typeClassName); } } } \ No newline at end of file diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index 771027794..6971526c9 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -19,9 +19,10 @@ * . */ -#namespace Doctrine\DBAL; +namespace Doctrine\DBAL; -#use Doctrine\Common\EventManager; +use Doctrine\Common\EventManager; +use Doctrine\Common\DoctrineException; #use Doctrine\DBAL\Exceptions\ConnectionException; /** @@ -53,7 +54,7 @@ * Doctrine\DBAL could ship with a simple standard broker that uses a primitive * round-robin approach to distribution. User can provide its own brokers. */ -class Doctrine_DBAL_Connection +class Connection { /** * Constant for transaction isolation level READ UNCOMMITTED. @@ -155,9 +156,9 @@ class Doctrine_DBAL_Connection * * @param array $params The connection parameters. */ - public function __construct(array $params, Doctrine_DBAL_Driver $driver, - Doctrine_DBAL_Configuration $config = null, - Doctrine_Common_EventManager $eventManager = null) + public function __construct(array $params, Driver $driver, + Configuration $config = null, + EventManager $eventManager = null) { $this->_driver = $driver; $this->_params = $params; @@ -169,10 +170,10 @@ class Doctrine_DBAL_Connection // Create default config and event manager if none given if ( ! $config) { - $this->_config = new Doctrine_DBAL_Configuration(); + $this->_config = new Configuration(); } if ( ! $eventManager) { - $this->_eventManager = new Doctrine_Common_EventManager(); + $this->_eventManager = new EventManager(); } $this->_platform = $driver->getDatabasePlatform(); @@ -702,7 +703,7 @@ class Doctrine_DBAL_Connection public function commit() { if ($this->_transactionNestingLevel == 0) { - throw new Doctrine_Exception("Commit failed. There is no active transaction."); + throw new DoctrineException("Commit failed. There is no active transaction."); } $this->connect(); diff --git a/lib/Doctrine/DBAL/Driver.php b/lib/Doctrine/DBAL/Driver.php index 6f483760b..66e757c7e 100644 --- a/lib/Doctrine/DBAL/Driver.php +++ b/lib/Doctrine/DBAL/Driver.php @@ -1,11 +1,14 @@ \ No newline at end of file diff --git a/lib/Doctrine/DBAL/Driver/Connection.php b/lib/Doctrine/DBAL/Driver/Connection.php index ca6c019a4..ef0e4fceb 100644 --- a/lib/Doctrine/DBAL/Driver/Connection.php +++ b/lib/Doctrine/DBAL/Driver/Connection.php @@ -1,5 +1,7 @@ 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); } diff --git a/lib/Doctrine/DBAL/Driver/PDOMsSql/Connection.php b/lib/Doctrine/DBAL/Driver/PDOMsSql/Connection.php index 7352fcbb7..90c2b79b3 100644 --- a/lib/Doctrine/DBAL/Driver/PDOMsSql/Connection.php +++ b/lib/Doctrine/DBAL/Driver/PDOMsSql/Connection.php @@ -1,13 +1,13 @@ \ No newline at end of file diff --git a/lib/Doctrine/DBAL/Driver/PDOMsSql/Driver.php b/lib/Doctrine/DBAL/Driver/PDOMsSql/Driver.php index 978a51a04..8ce0294f5 100644 --- a/lib/Doctrine/DBAL/Driver/PDOMsSql/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOMsSql/Driver.php @@ -1,15 +1,13 @@ _constructPdoDsn($params), $username, $password, @@ -40,4 +38,3 @@ class Doctrine_DBAL_Driver_PDOMsSql_Driver implements Doctrine_DBAL_Driver } -?> \ No newline at end of file diff --git a/lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php b/lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php index 2f91b8915..5b0b68a38 100644 --- a/lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php @@ -1,15 +1,13 @@ _constructPdoDsn($params), $username, $password, @@ -28,14 +26,13 @@ class Doctrine_DBAL_Driver_PDOOracle_Driver implements Doctrine_DBAL_Driver public function getDatabasePlatform() { - return new Doctrine_DatabasePlatform_OraclePlatform(); + return new \Doctrine\DBAL\Platforms\OraclePlatform(); } - public function getSchemaManager(Doctrine_Connection $conn) + public function getSchemaManager(\Doctrine\DBAL\Connection $conn) { - return new Doctrine_Schema_OracleSchemaManager($conn); + return new \Doctrine\DBAL\Schema\OracleSchemaManager($conn); } } -?> \ No newline at end of file diff --git a/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php b/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php index 689ac791c..9afaf0205 100644 --- a/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php @@ -1,6 +1,6 @@ _constructPdoDsn($params), $username, $password, @@ -52,7 +52,7 @@ class Doctrine_DBAL_Driver_PDOSqlite_Driver implements Doctrine_DBAL_Driver */ public function getDatabasePlatform() { - return new Doctrine_DBAL_Platforms_SqlitePlatform(); + return new \Doctrine\DBAL\Platforms\SqlitePlatform(); } /** @@ -61,9 +61,9 @@ class Doctrine_DBAL_Driver_PDOSqlite_Driver implements Doctrine_DBAL_Driver * @param Doctrine\DBAL\Connection $conn * @return Doctrine\DBAL\Schema\SqliteSchemaManager */ - 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); } } diff --git a/lib/Doctrine/DBAL/Driver/PDOStatement.php b/lib/Doctrine/DBAL/Driver/PDOStatement.php index 4d3b88c84..f628a1ec1 100644 --- a/lib/Doctrine/DBAL/Driver/PDOStatement.php +++ b/lib/Doctrine/DBAL/Driver/PDOStatement.php @@ -1,6 +1,8 @@ . */ -#namespace Doctrine\DBAL\Driver; +namespace Doctrine\DBAL\Driver; /** * Statement interface. @@ -34,7 +34,7 @@ * @since 2.0 * @version $Revision$ */ -interface Doctrine_DBAL_Driver_Statement +interface Statement { /** * Bind a column to a PHP variable diff --git a/lib/Doctrine/DBAL/DriverManager.php b/lib/Doctrine/DBAL/DriverManager.php index 35f75f7ba..1df4fc9e7 100644 --- a/lib/Doctrine/DBAL/DriverManager.php +++ b/lib/Doctrine/DBAL/DriverManager.php @@ -19,7 +19,9 @@ * . */ -#namespace Doctrine\DBAL; +namespace Doctrine\DBAL; + +use Doctrine\Common\EventManager; /** * Factory for creating Doctrine\DBAL\Connection instances. @@ -27,7 +29,7 @@ * @author Roman Borschel * @since 2.0 */ -final class Doctrine_DBAL_DriverManager +final class DriverManager { /** * List of supported drivers and their mappings to the driver class. @@ -35,13 +37,13 @@ final class Doctrine_DBAL_DriverManager * @var array */ private static $_driverMap = array( - 'pdo_mysql' => 'Doctrine_DBAL_Driver_PDOMySql_Driver', - 'pdo_sqlite' => 'Doctrine_DBAL_Driver_PDOSqlite_Driver', - 'pdo_pgsql' => 'Doctrine_DBAL_Driver_PDOPgSql_Driver', - 'pdo_oracle' => 'Doctrine_DBAL_Driver_PDOOracle_Driver', - 'pdo_mssql' => 'Doctrine_DBAL_Driver_PDOMsSql_Driver', - 'pdo_firebird' => 'Doctrine_DBAL_Driver_PDOFirebird_Driver', - 'pdo_informix' => 'Doctrine_DBAL_Driver_PDOInformix_Driver', + 'pdo_mysql' => 'Doctrine\DBAL\Driver\PDOMySql\Driver', + 'pdo_sqlite' => 'Doctrine\DBAL\Driver\PDOSqlite\Driver', + 'pdo_pgsql' => 'Doctrine\DBAL\Driver\PDOPgSql\Driver', + 'pdo_oracle' => 'Doctrine\DBAL\Driver\PDOOracle\Driver', + 'pdo_mssql' => 'Doctrine\DBAL\Driver\PDOMsSql\Driver', + 'pdo_firebird' => 'Doctrine\DBAL\Driver\PDOFirebird\Driver', + 'pdo_informix' => 'Doctrine\DBAL\Driver\PDOInformix\Driver', ); /** Private constructor. This class cannot be instantiated. */ @@ -92,20 +94,20 @@ final class Doctrine_DBAL_DriverManager * @return Doctrine\DBAL\Connection */ public static function getConnection(array $params, - Doctrine_DBAL_Configuration $config = null, - Doctrine_Common_EventManager $eventManager = null) + Configuration $config = null, + EventManager $eventManager = null) { // create default config and event manager, if not set if ( ! $config) { - $config = new Doctrine_DBAL_Configuration(); + $config = new Configuration(); } if ( ! $eventManager) { - $eventManager = new Doctrine_Common_EventManager(); + $eventManager = new EventManager(); } // check for existing pdo object if (isset($params['pdo']) && ! $params['pdo'] instanceof PDO) { - throw Doctrine_DBAL_Exceptions_DBALException::invalidPDOInstance(); + throw DBALException::invalidPDOInstance(); } else if (isset($params['pdo'])) { $params['driver'] = $params['pdo']->getAttribute(PDO::ATTR_DRIVER_NAME); } else { @@ -119,7 +121,7 @@ final class Doctrine_DBAL_DriverManager $driver = new $className(); - $wrapperClass = 'Doctrine_DBAL_Connection'; + $wrapperClass = 'Doctrine\DBAL\Connection'; if (isset($params['wrapperClass']) && is_subclass_of($params['wrapperClass'], $wrapperClass)) { $wrapperClass = $params['wrapperClass']; } @@ -138,16 +140,15 @@ final class Doctrine_DBAL_DriverManager // driver if ( ! isset($params['driver']) && ! isset($params['driverClass'])) { - throw Doctrine_ConnectionFactory_Exception::driverRequired(); + throw DBALException::driverRequired(); } // check validity of parameters // driver if ( isset($params['driver']) && ! isset(self::$_driverMap[$params['driver']])) { - throw Doctrine_DBAL_Exceptions_DBALException::unknownDriver($params['driver']); + throw DBALException::unknownDriver($params['driver']); } } } -?> \ No newline at end of file diff --git a/lib/Doctrine/DBAL/Exceptions/DBALException.php b/lib/Doctrine/DBAL/Exceptions/DBALException.php index c1b2a133d..bf1fc3a60 100644 --- a/lib/Doctrine/DBAL/Exceptions/DBALException.php +++ b/lib/Doctrine/DBAL/Exceptions/DBALException.php @@ -1,5 +1,9 @@ */ -class Doctrine_DBAL_Exceptions_DBALException extends Exception +class DBALException extends DoctrineException { public static function invalidPDOInstance() { diff --git a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php index 8979b647f..25c7ad882 100644 --- a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php @@ -19,7 +19,9 @@ * . */ -#namespace Doctrine\DBAL\Platforms; +namespace Doctrine\DBAL\Platforms; + +use Doctrine\DBAL\Connection; /** * Base class for all DatabasePlatforms. The DatabasePlatforms are the central @@ -30,7 +32,7 @@ * @author Roman Borschel * @author Lukas Smith (PEAR MDB2 library) */ -abstract class Doctrine_DBAL_Platforms_AbstractPlatform +abstract class AbstractPlatform { protected $_quoteIdentifiers = false; @@ -1766,7 +1768,7 @@ abstract class Doctrine_DBAL_Platforms_AbstractPlatform public function getProperty($name) { if ( ! isset($this->_properties[$name])) { - throw Doctrine_Connection_Exception::unknownProperty($name); + throw DoctrineException::unknownProperty($name); } return $this->_properties[$name]; } @@ -1813,13 +1815,13 @@ abstract class Doctrine_DBAL_Platforms_AbstractPlatform protected function _getTransactionIsolationLevelSql($level) { switch ($level) { - case Doctrine_DBAL_Connection::TRANSACTION_READ_UNCOMMITTED: + case Connection::TRANSACTION_READ_UNCOMMITTED: return 'READ UNCOMMITTED'; - case Doctrine_DBAL_Connection::TRANSACTION_READ_COMMITTED: + case Connection::TRANSACTION_READ_COMMITTED: return 'READ COMMITTED'; - case Doctrine_DBAL_Connection::TRANSACTION_REPEATABLE_READ: + case Connection::TRANSACTION_REPEATABLE_READ: return 'REPEATABLE READ'; - case Doctrine_DBAL_Connection::TRANSACTION_SERIALIZABLE: + case Connection::TRANSACTION_SERIALIZABLE: return 'SERIALIZABLE'; default: throw new Doctrine_Common_Exceptions_DoctrineException('isolation level is not supported: ' . $isolation); @@ -1833,7 +1835,7 @@ abstract class Doctrine_DBAL_Platforms_AbstractPlatform */ public function getSetTransactionIsolationSql($level) { - throw new Doctrine_Export_Exception('Set transaction isolation not supported by this platform.'); + throw new DoctrineException('Set transaction isolation not supported by this platform.'); } /** @@ -1844,7 +1846,7 @@ abstract class Doctrine_DBAL_Platforms_AbstractPlatform */ public function getDefaultTransactionIsolationLevel() { - return Doctrine_DBAL_Connection::TRANSACTION_READ_COMMITTED; + return Connection::TRANSACTION_READ_COMMITTED; } diff --git a/lib/Doctrine/DBAL/Platforms/Db2Platform.php b/lib/Doctrine/DBAL/Platforms/Db2Platform.php index 90e5899c5..5d11caff8 100644 --- a/lib/Doctrine/DBAL/Platforms/Db2Platform.php +++ b/lib/Doctrine/DBAL/Platforms/Db2Platform.php @@ -1,8 +1,8 @@ \ No newline at end of file diff --git a/lib/Doctrine/DBAL/Platforms/FirebirdPlatform.php b/lib/Doctrine/DBAL/Platforms/FirebirdPlatform.php index b50324d37..f040c456d 100644 --- a/lib/Doctrine/DBAL/Platforms/FirebirdPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/FirebirdPlatform.php @@ -1,13 +1,13 @@ \ No newline at end of file diff --git a/lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php b/lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php index b99f75ed3..e1309c1c6 100644 --- a/lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php @@ -1,8 +1,8 @@ . */ -#namespace Doctrine\DBAL\Platforms; +namespace Doctrine\DBAL\Platforms; /** * The MySqlPlatform provides the behavior, features and SQL dialect of the @@ -28,7 +28,7 @@ * @since 2.0 * @author Roman Borschel */ -class Doctrine_DBAL_Platforms_MySqlPlatform extends Doctrine_DBAL_Platforms_AbstractPlatform +class MySqlPlatform extends AbstractPlatform { /** * MySql reserved words. diff --git a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php index 9fa021c87..44da52f02 100644 --- a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php @@ -19,7 +19,7 @@ * . */ -#namespace Doctrine::DBAL::Platforms; +namespace Doctrine\DBAL\Platforms; /** * Base class for all DatabasePlatforms. The DatabasePlatforms are the central @@ -30,7 +30,7 @@ * @author Roman Borschel * @author Lukas Smith (PEAR MDB2 library) */ -class Doctrine_DBAL_Platforms_OraclePlatform extends Doctrine_DBAL_Platforms_AbstractPlatform +class OraclePlatform extends AbstractPlatform { /** * Constructor. diff --git a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php index 04f6283a3..7420bf265 100644 --- a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php @@ -1,8 +1,8 @@ . */ -#namespace Doctrine\DBAL\Schema; +namespace Doctrine\DBAL\Schema; /** * Base class for schema managers. Schema managers are used to inspect and/or @@ -32,11 +32,11 @@ * @version $Revision$ * @since 2.0 */ -abstract class Doctrine_DBAL_Schema_AbstractSchemaManager +abstract class AbstractSchemaManager { protected $_conn; - public function __construct(Doctrine_DBAL_Connection $conn) + public function __construct(\Doctrine\DBAL\Connection $conn) { $this->_conn = $conn; } diff --git a/lib/Doctrine/DBAL/Schema/FirebirdSchemaManager.php b/lib/Doctrine/DBAL/Schema/FirebirdSchemaManager.php index 722b682d1..149b224b1 100644 --- a/lib/Doctrine/DBAL/Schema/FirebirdSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/FirebirdSchemaManager.php @@ -19,7 +19,7 @@ * . */ -#namespace Doctrine::DBAL::Schema; +namespace Doctrine\DBAL\Schema; /** * xxx @@ -31,13 +31,8 @@ * @version $Revision$ * @since 2.0 */ -class Doctrine_DBAL_Schema_FirebirdSchemaManager extends Doctrine_DBAL_Schema_AbstractSchemaManager -{ - public function __construct(Doctrine_Connection_Firebird $conn) - { - $this->_conn = $conn; - } - +class FirebirdSchemaManager extends AbstractSchemaManager +{ /** * list all tables in the current database * diff --git a/lib/Doctrine/DBAL/Schema/InformixSchemaManager.php b/lib/Doctrine/DBAL/Schema/InformixSchemaManager.php index f212c40e9..df1179548 100644 --- a/lib/Doctrine/DBAL/Schema/InformixSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/InformixSchemaManager.php @@ -19,7 +19,7 @@ * . */ -#namespace Doctrine::DBAL::Schema; +namespace Doctrine\DBAL\Schema; /** * xxx @@ -31,7 +31,7 @@ * @version $Revision$ * @since 2.0 */ -class Doctrine_DBAL_Schema_InformixSchemaManager extends Doctrine_DBAL_Schema_AbstractSchemaManager +class InformixSchemaManager extends AbstractSchemaManager { protected $sql = array( 'listTables' => "SELECT tabname,tabtype FROM systables WHERE tabtype IN ('T','V') AND owner != 'informix'", @@ -54,12 +54,8 @@ class Doctrine_DBAL_Schema_InformixSchemaManager extends Doctrine_DBAL_Schema_Ab and s2.constrid=r.primary and i2.idxname=s2.idxname", ); - public function __construct(Doctrine_Connection_Informix $conn) - { - $this->_conn = $conn; - } + } -?> \ No newline at end of file diff --git a/lib/Doctrine/DBAL/Schema/MsSqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/MsSqlSchemaManager.php index ed99f4a6d..158cb1ce7 100644 --- a/lib/Doctrine/DBAL/Schema/MsSqlSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/MsSqlSchemaManager.php @@ -19,7 +19,7 @@ * . */ -#namespace Doctrine::DBAL::Schema; +namespace Doctrine\DBAL\Schema; /** * xxx @@ -30,13 +30,8 @@ * @version $Revision$ * @since 2.0 */ -class Doctrine_DBAL_Schema_MsSqlSchemaManager extends Doctrine_DBAL_Schema_AbstractSchemaManager -{ - public function __construct(Doctrine_Connection_Mssql $conn) - { - $this->_conn = $conn; - } - +class MsSqlSchemaManager extends AbstractSchemaManager +{ /** * create a new database * diff --git a/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php index ad7fe6b6a..2932b2eec 100644 --- a/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php @@ -19,7 +19,7 @@ * . */ -#namespace Doctrine\DBAL\Schema; +namespace Doctrine\DBAL\Schema; /** * xxx @@ -30,7 +30,7 @@ * @version $Revision$ * @since 2.0 */ -class Doctrine_DBAL_Schema_MySqlSchemaManager extends Doctrine_DBAL_Schema_AbstractSchemaManager +class MySqlSchemaManager extends AbstractSchemaManager { /** * lists all database sequences diff --git a/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php b/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php index 79ce29e14..419fea413 100644 --- a/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php @@ -19,7 +19,7 @@ * . */ -#namespace Doctrine\DBAL\Schema; +namespace Doctrine\DBAL\Schema; /** * xxx @@ -30,7 +30,7 @@ * @version $Revision$ * @since 2.0 */ -class Doctrine_DBAL_Schema_OracleSchemaManager extends Doctrine_DBAL_Schema_AbstractSchemaManager +class OracleSchemaManager extends AbstractSchemaManager { /** * create a new database diff --git a/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php index 7840d2555..cb5c5fcc7 100644 --- a/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php @@ -19,7 +19,7 @@ * . */ -#namespace Doctrine\DBAL\Schema; +namespace Doctrine\DBAL\Schema; /** * xxx @@ -30,7 +30,7 @@ * @version $Revision$ * @since 2.0 */ -class Doctrine_DBAL_Schema_PostgreSqlSchemaManager extends Doctrine_DBAL_Schema_AbstractSchemaManager +class PostgreSqlSchemaManager extends AbstractSchemaManager { /** * alter an existing table diff --git a/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php b/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php index 467ae2c6f..0057b348a 100644 --- a/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php @@ -19,7 +19,7 @@ * . */ -#namespace Doctrine\DBAL\Schema; +namespace Doctrine\DBAL\Schema; /** * xxx @@ -30,7 +30,7 @@ * @version $Revision$ * @since 2.0 */ -class Doctrine_DBAL_Schema_SqliteSchemaManager extends Doctrine_DBAL_Schema_AbstractSchemaManager +class SqliteSchemaManager extends AbstractSchemaManager { /** * lists all databases diff --git a/lib/Doctrine/DBAL/Statement.php b/lib/Doctrine/DBAL/Statement.php index cb4356fb7..ec4736b0d 100644 --- a/lib/Doctrine/DBAL/Statement.php +++ b/lib/Doctrine/DBAL/Statement.php @@ -18,8 +18,8 @@ * and is licensed under the LGPL. For more information, see * . */ - -#namespace Doctrine::DBAL; + +namespace Doctrine\DBAL; /** * A thin wrapper around PDOStatement. @@ -28,10 +28,10 @@ * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @link www.phpdoctrine.org * @since 1.0 - * @version $Revision: 1532 $ + * @version $Revision: 1532 $ * @todo Do we seriously need this wrapper? */ -class Doctrine_DBAL_Statement +class Statement { /** * @var Doctrine_Connection $conn Doctrine_Connection object, every connection @@ -51,13 +51,13 @@ class Doctrine_DBAL_Statement * statement holds an instance of Doctrine_Connection * @param mixed $stmt */ - public function __construct(Doctrine_Connection $conn, $stmt) + public function __construct(Connection $conn, $stmt) { $this->_conn = $conn; $this->_stmt = $stmt; if ($stmt === false) { - throw new Doctrine_Exception('Unknown statement object given.'); + throw new DoctrineException('Unknown statement object given.'); } } @@ -231,7 +231,7 @@ class Doctrine_DBAL_Statement //$this->_conn->getListener()->postStmtExecute($event); return $result; - } catch (PDOException $e) { + } catch (PDOException $e) { $this->_conn->rethrowException($e, $this); } diff --git a/lib/Doctrine/DBAL/Types/ArrayType.php b/lib/Doctrine/DBAL/Types/ArrayType.php index 3c4dbabe5..44c95b023 100644 --- a/lib/Doctrine/DBAL/Types/ArrayType.php +++ b/lib/Doctrine/DBAL/Types/ArrayType.php @@ -1,11 +1,13 @@ \ No newline at end of file diff --git a/lib/Doctrine/DBAL/Types/IntegerType.php b/lib/Doctrine/DBAL/Types/IntegerType.php index 5f7f88aa9..2d3350c02 100644 --- a/lib/Doctrine/DBAL/Types/IntegerType.php +++ b/lib/Doctrine/DBAL/Types/IntegerType.php @@ -1,15 +1,17 @@ getIntegerTypeDeclarationSql($fieldDeclaration); } diff --git a/lib/Doctrine/DBAL/Types/MediumIntType.php b/lib/Doctrine/DBAL/Types/MediumIntType.php index 0b827e618..119d71b4e 100644 --- a/lib/Doctrine/DBAL/Types/MediumIntType.php +++ b/lib/Doctrine/DBAL/Types/MediumIntType.php @@ -1,15 +1,14 @@ + diff --git a/lib/Doctrine/DBAL/Types/TextType.php b/lib/Doctrine/DBAL/Types/TextType.php index b0132330b..c31d0d45a 100644 --- a/lib/Doctrine/DBAL/Types/TextType.php +++ b/lib/Doctrine/DBAL/Types/TextType.php @@ -1,11 +1,13 @@ 'Doctrine_DBAL_Types_IntegerType', - 'int' => 'Doctrine_DBAL_Types_IntegerType', - 'tinyint' => 'Doctrine_DBAL_Types_TinyIntType', - 'smallint' => 'Doctrine_DBAL_Types_SmallIntType', - 'mediumint' => 'Doctrine_DBAL_Types_MediumIntType', - 'bigint' => 'Doctrine_DBAL_Types_BigIntType', - 'varchar' => 'Doctrine_DBAL_Types_VarcharType', - 'text' => 'Doctrine_DBAL_Types_TextType', - 'datetime' => 'Doctrine_DBAL_Types_DateTimeType', - 'decimal' => 'Doctrine_DBAL_Types_DecimalType', - 'double' => 'Doctrine_DBAL_Types_DoubleType' + 'integer' => 'Doctrine\DBAL\Types\IntegerType', + 'int' => '\Doctrine\DBAL\Types\IntegerType', + 'tinyint' => '\Doctrine\DBAL\Types\TinyIntType', + 'smallint' => '\Doctrine\DBAL\Types\SmallIntType', + 'mediumint' => '\Doctrine\DBAL\Types\MediumIntType', + 'bigint' => '\Doctrine\DBAL\Types\BigIntType', + 'varchar' => 'Doctrine\DBAL\Types\VarcharType', + 'text' => '\Doctrine\DBAL\Types\TextType', + 'datetime' => '\Doctrine\DBAL\Types\DateTimeType', + 'decimal' => '\Doctrine\DBAL\Types\DecimalType', + 'double' => '\Doctrine\DBAL\Types\DoubleType' ); - public function convertToDatabaseValue($value, Doctrine_DBAL_Platforms_AbstractPlatform $platform) + public function convertToDatabaseValue($value, \Doctrine\DBAL\Platforms\AbstractPlatform $platform) { return $value; } @@ -31,12 +31,12 @@ abstract class Doctrine_DBAL_Types_Type return $value; } - public function getDefaultLength(Doctrine_DBAL_Platforms_AbstractPlatform $platform) + public function getDefaultLength(\Doctrine\DBAL\Platforms\AbstractPlatform $platform) { return null; } - abstract public function getSqlDeclaration(array $fieldDeclaration, Doctrine_DBAL_Platforms_AbstractPlatform $platform); + abstract public function getSqlDeclaration(array $fieldDeclaration, \Doctrine\DBAL\Platforms\AbstractPlatform $platform); abstract public function getName(); /** @@ -55,7 +55,7 @@ abstract class Doctrine_DBAL_Types_Type } if ( ! isset(self::$_typeObjects[$name])) { if ( ! isset(self::$_typesMap[$name])) { - throw new Doctrine_Exception("Unknown type: $name"); + throw new DoctrineException("Unknown type: $name"); } self::$_typeObjects[$name] = new self::$_typesMap[$name](); } @@ -86,10 +86,9 @@ abstract class Doctrine_DBAL_Types_Type public static function overrideType($name, $className) { if ( ! isset(self::$_typesMap[$name])) { - throw Doctrine_Exception::typeNotFound($name); + throw DoctrineException::typeNotFound($name); } self::$_typesMap[$name] = $className; } } -?> \ No newline at end of file diff --git a/lib/Doctrine/DBAL/Types/VarcharType.php b/lib/Doctrine/DBAL/Types/VarcharType.php index e5d0a56f2..2af868c67 100644 --- a/lib/Doctrine/DBAL/Types/VarcharType.php +++ b/lib/Doctrine/DBAL/Types/VarcharType.php @@ -1,22 +1,22 @@ getVarcharDeclarationSql($fieldDeclaration); } /** @override */ - public function getDefaultLength(Doctrine_DBAL_Platforms_AbstractPlatform $platform) + public function getDefaultLength(\Doctrine\DBAL\Platforms\AbstractPlatform $platform) { return $platform->getVarcharDefaultLength(); } diff --git a/lib/Doctrine/ORM/Query/Abstract.php b/lib/Doctrine/ORM/AbstractQuery.php similarity index 99% rename from lib/Doctrine/ORM/Query/Abstract.php rename to lib/Doctrine/ORM/AbstractQuery.php index a903ca59a..f642b96b2 100644 --- a/lib/Doctrine/ORM/Query/Abstract.php +++ b/lib/Doctrine/ORM/AbstractQuery.php @@ -20,6 +20,8 @@ * . */ +namespace Doctrine\ORM; + /** * Doctrine_ORM_Query_Abstract * @@ -33,7 +35,7 @@ * @author Konsta Vesterinen * @todo See {@link Doctrine_ORM_Query} */ -abstract class Doctrine_ORM_Query_Abstract +abstract class AbstractQuery { /** * QUERY TYPE CONSTANTS diff --git a/lib/Doctrine/ORM/Collection.php b/lib/Doctrine/ORM/Collection.php index 0033168cb..2ed39d4dc 100644 --- a/lib/Doctrine/ORM/Collection.php +++ b/lib/Doctrine/ORM/Collection.php @@ -19,7 +19,7 @@ * . */ -#namespace Doctrine\ORM; +namespace Doctrine\ORM; /** * A persistent collection wrapper. @@ -42,7 +42,7 @@ * @author Roman Borschel * @todo Rename to PersistentCollection */ -final class Doctrine_ORM_Collection extends Doctrine_Common_Collections_Collection +final class Collection extends \Doctrine\Common\Collections\Collection { /** * The base type of the collection. @@ -109,7 +109,7 @@ final class Doctrine_ORM_Collection extends Doctrine_Common_Collections_Collecti /** * Creates a new persistent collection. */ - public function __construct(Doctrine_ORM_EntityManager $em, $entityBaseType, $keyField = null) + public function __construct(EntityManager $em, $entityBaseType, $keyField = null) { $this->_entityBaseType = $entityBaseType; $this->_em = $em; @@ -151,7 +151,7 @@ final class Doctrine_ORM_Collection extends Doctrine_Common_Collections_Collecti * @param object $entity * @param AssociationMapping $relation */ - public function _setOwner($entity, Doctrine_ORM_Mapping_AssociationMapping $relation) + public function _setOwner($entity, \Doctrine\ORM\Mapping\AssociationMapping $relation) { $this->_owner = $entity; $this->_association = $relation; diff --git a/lib/Doctrine/ORM/Configuration.php b/lib/Doctrine/ORM/Configuration.php index 87eda3b3f..e210f18d4 100644 --- a/lib/Doctrine/ORM/Configuration.php +++ b/lib/Doctrine/ORM/Configuration.php @@ -19,10 +19,9 @@ * . */ -#namespace Doctrine\ORM; +namespace Doctrine\ORM; -#use Doctrine\DBAL\Configuration; -#use Doctrine\ORM\Mapping\Driver\AnnotationDriver; +use Doctrine\ORM\Mapping\Driver\AnnotationDriver; /** * Configuration container for all configuration options of Doctrine. @@ -34,7 +33,7 @@ * @author Roman Borschel * @since 2.0 */ -class Doctrine_ORM_Configuration extends Doctrine_DBAL_Configuration +class Configuration extends \Doctrine\DBAL\Configuration { /** * Creates a new configuration that can be used for Doctrine. @@ -45,7 +44,7 @@ class Doctrine_ORM_Configuration extends Doctrine_DBAL_Configuration 'resultCacheImpl' => null, 'queryCacheImpl' => null, 'metadataCacheImpl' => null, - 'metadataDriverImpl' => new Doctrine_ORM_Mapping_Driver_AnnotationDriver() + 'metadataDriverImpl' => new AnnotationDriver() )); } diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index f34871a49..b2604ef89 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -19,25 +19,25 @@ * . */ -#namespace Doctrine\ORM; +namespace Doctrine\ORM; #use Doctrine\Common\Configuration; -#use Doctrine\Common\EventManager; -#use Doctrine\DBAL\Connection; -#use Doctrine\ORM\Exceptions\EntityManagerException; -#use Doctrine\ORM\Internal\UnitOfWork; -#use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\Common\EventManager; +use Doctrine\Common\DoctrineException; +use Doctrine\DBAL\Connection; +use Doctrine\ORM\Exceptions\EntityManagerException; +use Doctrine\ORM\Mapping\ClassMetadata; /** * The EntityManager is the central access point to ORM functionality. * * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link www.phpdoctrine.org + * @link www.doctrine-project.org * @since 2.0 * @version $Revision$ * @author Roman Borschel */ -class Doctrine_ORM_EntityManager +class EntityManager { /** * IMMEDIATE: Flush occurs automatically after each operation that issues database @@ -158,20 +158,20 @@ class Doctrine_ORM_EntityManager * @param Doctrine\Common\EventManager $eventManager */ protected function __construct( - Doctrine_DBAL_Connection $conn, + Connection $conn, $name, - Doctrine_ORM_Configuration $config, - Doctrine_Common_EventManager $eventManager) + Configuration $config, + EventManager $eventManager) { $this->_conn = $conn; $this->_name = $name; $this->_config = $config; $this->_eventManager = $eventManager; - $this->_metadataFactory = new Doctrine_ORM_Mapping_ClassMetadataFactory( + $this->_metadataFactory = new \Doctrine\ORM\Mapping\ClassMetadataFactory( $this->_config->getMetadataDriverImpl(), $this->_conn->getDatabasePlatform()); $this->_metadataFactory->setCacheDriver($this->_config->getMetadataCacheImpl()); - $this->_unitOfWork = new Doctrine_ORM_UnitOfWork($this); + $this->_unitOfWork = new UnitOfWork($this); } /** @@ -259,14 +259,14 @@ class Doctrine_ORM_EntityManager */ protected function _createIdGenerator($generatorType) { - if ($generatorType == Doctrine_ORM_Mapping_ClassMetadata::GENERATOR_TYPE_IDENTITY) { - return new Doctrine_ORM_Id_IdentityGenerator($this); - } else if ($generatorType == Doctrine_ORM_Mapping_ClassMetadata::GENERATOR_TYPE_SEQUENCE) { - return new Doctrine_ORM_Id_SequenceGenerator($this); - } else if ($generatorType == Doctrine_ORM_Mapping_ClassMetadata::GENERATOR_TYPE_TABLE) { - return new Doctrine_ORM_Id_TableGenerator($this); + if ($generatorType == ClassMetadata::GENERATOR_TYPE_IDENTITY) { + return new \Doctrine\ORM\Id\IdentityGenerator($this); + } else if ($generatorType == ClassMetadata::GENERATOR_TYPE_SEQUENCE) { + return new \Doctrine\ORM\Id\SequenceGenerator($this); + } else if ($generatorType == ClassMetadata::GENERATOR_TYPE_TABLE) { + return new \Doctrine\ORM\Id\TableGenerator($this); } else { - return new Doctrine_ORM_Id_Assigned($this); + return new \Doctrine\ORM\Id\Assigned($this); } } @@ -278,7 +278,7 @@ class Doctrine_ORM_EntityManager */ public function createQuery($dql = "") { - $query = new Doctrine_ORM_Query($this); + $query = new Query($this); if ( ! empty($dql)) { $query->setDql($dql); } @@ -298,9 +298,9 @@ class Doctrine_ORM_EntityManager if ( ! isset($this->_persisters[$entityName])) { $class = $this->getClassMetadata($entityName); if ($class->isInheritanceTypeJoined()) { - $persister = new Doctrine_EntityPersister_JoinedSubclass($this, $class); + $persister = new \Doctrine\ORM\Persisters\JoinedSubclassPersister($this, $class); } else { - $persister = new Doctrine_ORM_Persisters_StandardEntityPersister($this, $class); + $persister = new \Doctrine\ORM\Persisters\StandardEntityPersister($this, $class); } $this->_persisters[$entityName] = $persister; } @@ -313,7 +313,7 @@ class Doctrine_ORM_EntityManager * @param Doctrine\ORM\Entity $entity * @return boolean */ - public function detach(Doctrine_ORM_Entity $entity) + public function detach($entity) { return $this->_unitOfWork->removeFromIdentityMap($entity); } @@ -385,7 +385,7 @@ class Doctrine_ORM_EntityManager public function setFlushMode($flushMode) { if ( ! $this->_isFlushMode($flushMode)) { - throw Doctrine_ORM_Exceptions_EntityManagerException::invalidFlushMode(); + throw EntityManagerException::invalidFlushMode(); } $this->_flushMode = $flushMode; } @@ -472,7 +472,7 @@ class Doctrine_ORM_EntityManager public function refresh(Doctrine_ORM_Entity $entity) { $this->_mergeData($entity, $entity->getRepository()->find( - $entity->identifier(), Doctrine_Query::HYDRATE_ARRAY), + $entity->identifier(), Query::HYDRATE_ARRAY), true); } @@ -482,7 +482,7 @@ class Doctrine_ORM_EntityManager * @param Doctrine\ORM\Entity $entity The entity to copy. * @return Doctrine\ORM\Entity The new entity. */ - public function copy(Doctrine_ORM_Entity $entity, $deep = false) + public function copy($entity, $deep = false) { //... } @@ -504,7 +504,7 @@ class Doctrine_ORM_EntityManager if ($customRepositoryClassName !== null) { $repository = new $customRepositoryClassName($entityName, $metadata); } else { - $repository = new Doctrine_ORM_EntityRepository($this, $metadata); + $repository = new \Doctrine\ORM\EntityRepository($this, $metadata); } $this->_repositories[$entityName] = $repository; @@ -552,7 +552,7 @@ class Doctrine_ORM_EntityManager private function _errorIfNotActiveOrClosed() { if ($this->_closed) { - throw Doctrine_ORM_Exceptions_EntityManagerException::notActiveOrClosed($this->_name); + throw EntityManagerException::notActiveOrClosed($this->_name); } } @@ -587,23 +587,23 @@ class Doctrine_ORM_EntityManager { if ( ! isset($this->_hydrators[$hydrationMode])) { switch ($hydrationMode) { - case Doctrine_ORM_Query::HYDRATE_OBJECT: - $this->_hydrators[$hydrationMode] = new Doctrine_ORM_Internal_Hydration_ObjectHydrator($this); + case Query::HYDRATE_OBJECT: + $this->_hydrators[$hydrationMode] = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this); break; case Doctrine_ORM_Query::HYDRATE_ARRAY: - $this->_hydrators[$hydrationMode] = new Doctrine_ORM_Internal_Hydration_ArrayHydrator($this); + $this->_hydrators[$hydrationMode] = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this); break; case Doctrine_ORM_Query::HYDRATE_SCALAR: - $this->_hydrators[$hydrationMode] = new Doctrine_ORM_Internal_Hydration_ScalarHydrator($this); + $this->_hydrators[$hydrationMode] = new \Doctrine\ORM\Internal\Hydration\ScalarHydrator($this); break; case Doctrine_ORM_Query::HYDRATE_SINGLE_SCALAR: - $this->_hydrators[$hydrationMode] = new Doctrine_ORM_Internal_Hydration_SingleScalarHydrator($this); + $this->_hydrators[$hydrationMode] = new \Doctrine\ORM\Internal\Hydration\SingleScalarHydrator($this); break; case Doctrine_ORM_Query::HYDRATE_NONE: - $this->_hydrators[$hydrationMode] = new Doctrine_ORM_Internal_Hydration_NoneHydrator($this); + $this->_hydrators[$hydrationMode] = new \Doctrine\ORM\Internal\Hydration\NoneHydrator($this); break; default: - throw new Doctrine_Exception("No hydrator found for hydration mode '$hydrationMode'."); + throw new DoctrineException("No hydrator found for hydration mode '$hydrationMode'."); } } else if ($this->_hydrators[$hydrationMode] instanceof Closure) { $this->_hydrators[$hydrationMode] = $this->_hydrators[$hydrationMode]($this); @@ -649,23 +649,23 @@ class Doctrine_ORM_EntityManager public static function create( $conn, $name, - Doctrine_ORM_Configuration $config = null, - Doctrine_Common_EventManager $eventManager = null) + Configuration $config = null, + EventManager $eventManager = null) { if (is_array($conn)) { - $conn = Doctrine_DBAL_DriverManager::getConnection($conn, $config, $eventManager); - } else if ( ! $conn instanceof Doctrine_DBAL_Connection) { - throw new Doctrine_Exception("Invalid parameter '$conn'."); + $conn = \Doctrine\DBAL\DriverManager::getConnection($conn, $config, $eventManager); + } else if ( ! $conn instanceof Connection) { + throw new DoctrineException("Invalid parameter '$conn'."); } if (is_null($config)) { - $config = new Doctrine_ORM_Configuration(); + $config = new Configuration(); } if (is_null($eventManager)) { - $eventManager = new Doctrine_Common_EventManager(); + $eventManager = new EventManager(); } - $em = new Doctrine_ORM_EntityManager($conn, $name, $config, $eventManager); + $em = new EntityManager($conn, $name, $config, $eventManager); return $em; } diff --git a/lib/Doctrine/ORM/EntityRepository.php b/lib/Doctrine/ORM/EntityRepository.php index 389959c03..8469b5dbf 100644 --- a/lib/Doctrine/ORM/EntityRepository.php +++ b/lib/Doctrine/ORM/EntityRepository.php @@ -19,7 +19,7 @@ * . */ -#namespace Doctrine\ORM; +namespace Doctrine\ORM; /** * A repository provides the illusion of an in-memory Entity store. @@ -32,13 +32,13 @@ * @version $Revision$ * @author Roman Borschel */ -class Doctrine_ORM_EntityRepository +class EntityRepository { protected $_entityName; protected $_em; protected $_classMetadata; - public function __construct($em, Doctrine_ORM_Mapping_ClassMetadata $classMetadata) + public function __construct($em, \Doctrine\ORM\Mapping\ClassMetadata $classMetadata) { $this->_entityName = $classMetadata->getClassName(); $this->_em = $em; diff --git a/lib/Doctrine/ORM/Exceptions/EntityManagerException.php b/lib/Doctrine/ORM/Exceptions/EntityManagerException.php index 61823ca90..0d1255f19 100644 --- a/lib/Doctrine/ORM/Exceptions/EntityManagerException.php +++ b/lib/Doctrine/ORM/Exceptions/EntityManagerException.php @@ -19,7 +19,7 @@ * . */ -#namespace Doctrine::ORM::Exceptions; +namespace Doctrine\ORM\Exceptions; /** * Doctrine_EntityManager_Exception @@ -31,7 +31,7 @@ * @since 2.0 * @version $Revision$ */ -class Doctrine_ORM_Exceptions_EntityManagerException extends Doctrine_ORM_Exceptions_ORMException +class EntityManagerException extends \Doctrine\Common\DoctrineException { public static function invalidFlushMode() { diff --git a/lib/Doctrine/ORM/Exceptions/HydrationException.php b/lib/Doctrine/ORM/Exceptions/HydrationException.php index 563a53dc9..a743b26cd 100644 --- a/lib/Doctrine/ORM/Exceptions/HydrationException.php +++ b/lib/Doctrine/ORM/Exceptions/HydrationException.php @@ -1,6 +1,8 @@ \ No newline at end of file diff --git a/lib/Doctrine/ORM/Exceptions/MappingException.php b/lib/Doctrine/ORM/Exceptions/MappingException.php index ad76b0443..3c709b4c2 100644 --- a/lib/Doctrine/ORM/Exceptions/MappingException.php +++ b/lib/Doctrine/ORM/Exceptions/MappingException.php @@ -19,14 +19,14 @@ * . */ -#namespace Doctrine\ORM\Exceptions; +namespace Doctrine\ORM\Exceptions; /** * A MappingException indicates that something is wrong with the mapping setup. * * @since 2.0 */ -class Doctrine_ORM_Exceptions_MappingException extends Doctrine_ORM_Exceptions_ORMException +class MappingException extends \Doctrine\Common\DoctrineException { public static function identifierRequired($entityName) { diff --git a/lib/Doctrine/ORM/Exceptions/QueryException.php b/lib/Doctrine/ORM/Exceptions/QueryException.php new file mode 100644 index 000000000..8632845ab --- /dev/null +++ b/lib/Doctrine/ORM/Exceptions/QueryException.php @@ -0,0 +1,17 @@ +. */ -#namespace Doctrine\ORM\Export; +namespace Doctrine\ORM\Export; /** * The ClassExporter can generate database schemas/structures from ClassMetadata @@ -35,14 +35,14 @@ * @since 2.0 * @version $Revision: 4805 $ */ -class Doctrine_ORM_Export_ClassExporter +class ClassExporter { /** The SchemaManager */ private $_sm; /** The EntityManager */ private $_em; - public function __construct(Doctrine_ORM_EntityManager $em) + public function __construct(\Doctrine\ORM\EntityManager $em) { $this->_em = $em; $this->_sm = $em->getConnection()->getSchemaManager(); diff --git a/lib/Doctrine/ORM/Id/AbstractIdGenerator.php b/lib/Doctrine/ORM/Id/AbstractIdGenerator.php index 4708f341d..4bbaa7c90 100644 --- a/lib/Doctrine/ORM/Id/AbstractIdGenerator.php +++ b/lib/Doctrine/ORM/Id/AbstractIdGenerator.php @@ -1,17 +1,15 @@ _em = $em; } diff --git a/lib/Doctrine/ORM/Id/Assigned.php b/lib/Doctrine/ORM/Id/Assigned.php index 285e4baa2..936f29301 100644 --- a/lib/Doctrine/ORM/Id/Assigned.php +++ b/lib/Doctrine/ORM/Id/Assigned.php @@ -1,12 +1,14 @@ */ -class Doctrine_ORM_Id_Assigned extends Doctrine_ORM_Id_AbstractIdGenerator +class Assigned extends AbstractIdGenerator { /** * Returns the identifier assigned to the given entity. diff --git a/lib/Doctrine/ORM/Id/IdentityGenerator.php b/lib/Doctrine/ORM/Id/IdentityGenerator.php index 83f5b7a1f..f3c9558ad 100644 --- a/lib/Doctrine/ORM/Id/IdentityGenerator.php +++ b/lib/Doctrine/ORM/Id/IdentityGenerator.php @@ -1,6 +1,8 @@ \ No newline at end of file diff --git a/lib/Doctrine/ORM/Id/SequenceIdentityGenerator.php b/lib/Doctrine/ORM/Id/SequenceIdentityGenerator.php index f5643d155..22e20594e 100644 --- a/lib/Doctrine/ORM/Id/SequenceIdentityGenerator.php +++ b/lib/Doctrine/ORM/Id/SequenceIdentityGenerator.php @@ -1,6 +1,8 @@ \ No newline at end of file diff --git a/lib/Doctrine/ORM/Id/TableGenerator.php b/lib/Doctrine/ORM/Id/TableGenerator.php index 2d62d69b2..d5e20e7c2 100644 --- a/lib/Doctrine/ORM/Id/TableGenerator.php +++ b/lib/Doctrine/ORM/Id/TableGenerator.php @@ -1,18 +1,19 @@ \ No newline at end of file diff --git a/lib/Doctrine/ORM/Internal/CommitOrderCalculator.php b/lib/Doctrine/ORM/Internal/CommitOrderCalculator.php index b3dbbf0de..5be57fe8e 100644 --- a/lib/Doctrine/ORM/Internal/CommitOrderCalculator.php +++ b/lib/Doctrine/ORM/Internal/CommitOrderCalculator.php @@ -19,7 +19,7 @@ * . */ -#namespace Doctrine\ORM\Internal; +namespace Doctrine\ORM\Internal; /** * The CommitOrderCalculator is used by the UnitOfWork to sort out the @@ -28,7 +28,7 @@ * @since 2.0 * @author Roman Borschel */ -class Doctrine_ORM_Internal_CommitOrderCalculator +class CommitOrderCalculator { private $_currentTime; @@ -106,7 +106,7 @@ class Doctrine_ORM_Internal_CommitOrderCalculator */ public function addNodeWithItem($key, $item) { - $this->_nodes[$key] = new Doctrine_ORM_Internal_CommitOrderNode($item, $this); + $this->_nodes[$key] = new CommitOrderNode($item, $this); } /** diff --git a/lib/Doctrine/ORM/Internal/CommitOrderNode.php b/lib/Doctrine/ORM/Internal/CommitOrderNode.php index e7888345c..a658dae4b 100644 --- a/lib/Doctrine/ORM/Internal/CommitOrderNode.php +++ b/lib/Doctrine/ORM/Internal/CommitOrderNode.php @@ -19,7 +19,7 @@ * . */ -#namespace Doctrine\ORM\Internal; +namespace Doctrine\ORM\Internal; /** * A CommitOrderNode is a temporary wrapper around ClassMetadata instances @@ -28,7 +28,7 @@ * @since 2.0 * @author Roman Borschel */ -class Doctrine_ORM_Internal_CommitOrderNode +class CommitOrderNode { const NOT_VISITED = 1; const IN_PROGRESS = 2; @@ -55,7 +55,7 @@ class Doctrine_ORM_Internal_CommitOrderNode * @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, CommitOrderCalculator $calc) { $this->_wrappedObj = $wrappedObj; $this->_calculator = $calc; @@ -157,7 +157,7 @@ class Doctrine_ORM_Internal_CommitOrderNode * * @param Doctrine\ORM\Internal\CommitOrderNode $node */ - public function before(Doctrine_ORM_Internal_CommitOrderNode $node) + public function before(CommitOrderNode $node) { $this->_relatedNodes[] = $node; } diff --git a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php index e14ac06ad..4650fe895 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php @@ -19,7 +19,9 @@ * . */ -#namespace Doctrine\ORM\Internal\Hydration; +namespace Doctrine\ORM\Internal\Hydration; + +use \PDO; /** * Base class for all hydrators (ok, we got only 1 currently). @@ -31,7 +33,7 @@ * @author Konsta Vesterinen * @author Roman Borschel */ -abstract class Doctrine_ORM_Internal_Hydration_AbstractHydrator +abstract class AbstractHydrator { /** * @var array $_queryComponents @@ -69,7 +71,7 @@ abstract class Doctrine_ORM_Internal_Hydration_AbstractHydrator * * @param Doctrine\ORM\EntityManager $em The EntityManager to use. */ - public function __construct(Doctrine_ORM_EntityManager $em) + public function __construct(\Doctrine\ORM\EntityManager $em) { $this->_em = $em; $this->_uow = $em->getUnitOfWork(); @@ -86,7 +88,7 @@ abstract class Doctrine_ORM_Internal_Hydration_AbstractHydrator { $this->_stmt = $stmt; $this->_prepare($parserResult); - return new Doctrine_ORM_Internal_Hydration_IterableResult($this); + return new IterableResult($this); } /** @@ -192,10 +194,10 @@ abstract class Doctrine_ORM_Internal_Hydration_AbstractHydrator if ($this->_isIgnoredName($key)) continue; // Cache general information like the column name <-> field name mapping - $e = explode(Doctrine_ORM_Query_ParserRule::SQLALIAS_SEPARATOR, $key); + $e = explode(\Doctrine\ORM\Query\ParserRule::SQLALIAS_SEPARATOR, $key); $columnName = array_pop($e); $cache[$key]['dqlAlias'] = $this->_tableAliases[ - implode(Doctrine_ORM_Query_ParserRule::SQLALIAS_SEPARATOR, $e) + implode(\Doctrine\ORM\Query\ParserRule::SQLALIAS_SEPARATOR, $e) ]; $classMetadata = $this->_queryComponents[$cache[$key]['dqlAlias']]['metadata']; // check whether it's an aggregate value or a regular field @@ -261,10 +263,10 @@ abstract class Doctrine_ORM_Internal_Hydration_AbstractHydrator if ($this->_isIgnoredName($key)) continue; // cache general information like the column name <-> field name mapping - $e = explode(Doctrine_ORM_Query_ParserRule::SQLALIAS_SEPARATOR, $key); + $e = explode(\Doctrine\ORM\Query\ParserRule::SQLALIAS_SEPARATOR, $key); $columnName = array_pop($e); $cache[$key]['dqlAlias'] = $this->_tableAliases[ - implode(Doctrine_ORM_Query_ParserRule::SQLALIAS_SEPARATOR, $e) + implode(\Doctrine\ORM\Query\ParserRule::SQLALIAS_SEPARATOR, $e) ]; $classMetadata = $this->_queryComponents[$cache[$key]['dqlAlias']]['metadata']; // check whether it's an aggregate value or a regular field diff --git a/lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php index b387d2f63..8635c1be9 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php @@ -4,12 +4,16 @@ * and open the template in the editor. */ +namespace Doctrine\ORM\Internal\Hydration; + +use \PDO; + /** * Description of ArrayHydrator * * @author robo */ -class Doctrine_ORM_Internal_Hydration_ArrayHydrator extends Doctrine_ORM_Internal_Hydration_AbstractHydrator +class ArrayHydrator extends AbstractHydrator { private $_rootAlias; private $_rootEntityName; diff --git a/lib/Doctrine/ORM/Internal/Hydration/IterableResult.php b/lib/Doctrine/ORM/Internal/Hydration/IterableResult.php index 27413ad01..695477e58 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/IterableResult.php +++ b/lib/Doctrine/ORM/Internal/Hydration/IterableResult.php @@ -1,4 +1,7 @@ _parserResult->isMixedQuery()) { $result = array(); } else { - $result = new Doctrine_ORM_Collection($this->_em, $this->_rootEntityName); + $result = new \Doctrine\ORM\Collection($this->_em, $this->_rootEntityName); } $cache = array(); @@ -102,7 +105,7 @@ class Doctrine_ORM_Internal_Hydration_ObjectHydrator extends Doctrine_ORM_Intern if ( ! is_object($coll)) { end($coll); $this->_resultPointers[$dqlAlias] =& $coll[key($coll)]; - } else if ($coll instanceof Doctrine_ORM_Collection) { + } else if ($coll instanceof \Doctrine\ORM\Collection) { if (count($coll) > 0) { $this->_resultPointers[$dqlAlias] = $coll->last(); } @@ -113,7 +116,7 @@ class Doctrine_ORM_Internal_Hydration_ObjectHydrator extends Doctrine_ORM_Intern private function getCollection($component) { - $coll = new Doctrine_ORM_Collection($this->_em, $component); + $coll = new \Doctrine\ORM\Collection($this->_em, $component); $this->_collections[] = $coll; return $coll; } @@ -335,7 +338,7 @@ class Doctrine_ORM_Internal_Hydration_ObjectHydrator extends Doctrine_ORM_Intern ->getValue($baseElement)); } } else if ( ! $this->isFieldSet($baseElement, $relationAlias)) { - $coll = new Doctrine_ORM_Collection($this->_em, $entityName); + $coll = new \Doctrine\ORM\Collection($this->_em, $entityName); $this->_collections[] = $coll; $this->setRelatedElement($baseElement, $relationAlias, $coll); } @@ -370,7 +373,7 @@ class Doctrine_ORM_Internal_Hydration_ObjectHydrator extends Doctrine_ORM_Intern /** {@inheritdoc} */ protected function _getRowContainer() { - return new Doctrine_Common_Collections_Collection; + return new \Doctrine\Common\Collections\Collection; } } diff --git a/lib/Doctrine/ORM/Internal/Hydration/ScalarHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/ScalarHydrator.php index 088311ef5..9b8984c9d 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/ScalarHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/ScalarHydrator.php @@ -1,5 +1,9 @@ _stmt->fetchAll(PDO::FETCH_ASSOC); //TODO: Let this exception be raised by Query as QueryException if (count($result) > 1 || count($result[0]) > 1) { - throw Doctrine_ORM_Exceptions_HydrationException::nonUniqueResult(); + throw HydrationException::nonUniqueResult(); } $result = $this->_gatherScalarRowData($result[0], $cache); return array_shift($result); diff --git a/lib/Doctrine/ORM/Mapping/AssociationMapping.php b/lib/Doctrine/ORM/Mapping/AssociationMapping.php index eb1488c28..565d208fe 100644 --- a/lib/Doctrine/ORM/Mapping/AssociationMapping.php +++ b/lib/Doctrine/ORM/Mapping/AssociationMapping.php @@ -19,7 +19,7 @@ * . */ -#namespace Doctrine\ORM\Mapping; +namespace Doctrine\ORM\Mapping; /** * Base class for association mappings. @@ -27,7 +27,7 @@ * @author Roman Borschel * @since 2.0 */ -abstract class Doctrine_ORM_Mapping_AssociationMapping +abstract class AssociationMapping { const FETCH_MANUAL = 1; const FETCH_LAZY = 2; diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadata.php b/lib/Doctrine/ORM/Mapping/ClassMetadata.php index b87a92ef9..c006d0e72 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadata.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadata.php @@ -19,9 +19,9 @@ * . */ -#namespace Doctrine\ORM\Mapping; +namespace Doctrine\ORM\Mapping; -#use \Serializable; +use \ReflectionClass; /** * A ClassMetadata instance holds all the information (metadata) of an entity and @@ -31,7 +31,7 @@ * @author Roman Borschel * @since 2.0 */ -class Doctrine_ORM_Mapping_ClassMetadata +class ClassMetadata { /* The inheritance mapping types */ /** @@ -613,7 +613,7 @@ class Doctrine_ORM_Mapping_ClassMetadata } if ( ! is_object($mapping['type'])) { - $mapping['type'] = Doctrine_DBAL_Types_Type::getType($mapping['type']); + $mapping['type'] = \Doctrine\DBAL\Types\Type::getType($mapping['type']); } // Complete fieldName and columnName mapping @@ -1186,12 +1186,12 @@ class Doctrine_ORM_Mapping_ClassMetadata { $this->_validateAndCompleteFieldMapping($mapping); if (isset($this->_fieldMappings[$mapping['fieldName']])) { - throw Doctrine_ORM_Exceptions_MappingException::duplicateFieldMapping(); + throw MappingException::duplicateFieldMapping(); } $this->_fieldMappings[$mapping['fieldName']] = $mapping; } - public function addAssociationMapping(Doctrine_ORM_Mapping_AssociationMapping $mapping) + public function addAssociationMapping(AssociationMapping $mapping) { $this->_storeAssociationMapping($mapping); } @@ -1204,7 +1204,7 @@ class Doctrine_ORM_Mapping_ClassMetadata public function mapOneToOne(array $mapping) { $mapping = $this->_completeAssociationMapping($mapping); - $oneToOneMapping = new Doctrine_ORM_Mapping_OneToOneMapping($mapping); + $oneToOneMapping = new OneToOneMapping($mapping); $this->_storeAssociationMapping($oneToOneMapping); } @@ -1215,7 +1215,7 @@ class Doctrine_ORM_Mapping_ClassMetadata * @param AssociationMapping The mapping to register as inverse if it is a mapping * for the inverse side of an association. */ - private function _registerMappingIfInverse(Doctrine_ORM_Mapping_AssociationMapping $assoc) + private function _registerMappingIfInverse(AssociationMapping $assoc) { if ($assoc->isInverseSide()) { $this->_inverseMappings[$assoc->getMappedByFieldName()] = $assoc; @@ -1230,7 +1230,7 @@ class Doctrine_ORM_Mapping_ClassMetadata public function mapOneToMany(array $mapping) { $mapping = $this->_completeAssociationMapping($mapping); - $oneToManyMapping = new Doctrine_ORM_Mapping_OneToManyMapping($mapping); + $oneToManyMapping = new OneToManyMapping($mapping); $this->_storeAssociationMapping($oneToManyMapping); } @@ -1253,7 +1253,7 @@ class Doctrine_ORM_Mapping_ClassMetadata public function mapManyToMany(array $mapping) { $mapping = $this->_completeAssociationMapping($mapping); - $manyToManyMapping = new Doctrine_ORM_Mapping_ManyToManyMapping($mapping); + $manyToManyMapping = new ManyToManyMapping($mapping); $this->_storeAssociationMapping($manyToManyMapping); } @@ -1262,11 +1262,11 @@ class Doctrine_ORM_Mapping_ClassMetadata * * @param Doctrine_Association $assocMapping */ - private function _storeAssociationMapping(Doctrine_ORM_Mapping_AssociationMapping $assocMapping) + private function _storeAssociationMapping(AssociationMapping $assocMapping) { $sourceFieldName = $assocMapping->getSourceFieldName(); if (isset($this->_associationMappings[$sourceFieldName])) { - throw Doctrine_ORM_Exceptions_MappingException::duplicateFieldMapping(); + throw MappingException::duplicateFieldMapping(); } $this->_associationMappings[$sourceFieldName] = $assocMapping; $this->_registerMappingIfInverse($assocMapping); @@ -1343,7 +1343,7 @@ class Doctrine_ORM_Mapping_ClassMetadata * @param string $event The lifecycle event. * @param Entity $entity The Entity on which the event occured. */ - public function invokeLifecycleCallbacks($lifecycleEvent, Doctrine_ORM_Entity $entity) + public function invokeLifecycleCallbacks($lifecycleEvent, $entity) { foreach ($this->getLifecycleCallbacks($lifecycleEvent) as $callback) { $entity->$callback(); diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index 9a78d831d..311dffed8 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -19,9 +19,9 @@ * . */ -#namespace Doctrine\ORM\Mapping; +namespace Doctrine\ORM\Mapping; -#use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Platforms\AbstractPlatform; /** * The metadata factory is used to create ClassMetadata objects that contain all the @@ -35,7 +35,7 @@ * @link www.doctrine-project.org * @since 2.0 */ -class Doctrine_ORM_Mapping_ClassMetadataFactory +class ClassMetadataFactory { /** The targeted database platform. */ private $_targetPlatform; @@ -47,7 +47,7 @@ class Doctrine_ORM_Mapping_ClassMetadataFactory * * @param $driver The metadata driver to use. */ - public function __construct($driver, Doctrine_DBAL_Platforms_AbstractPlatform $targetPlatform) + public function __construct($driver, AbstractPlatform $targetPlatform) { $this->_driver = $driver; $this->_targetPlatform = $targetPlatform; @@ -161,7 +161,7 @@ class Doctrine_ORM_Mapping_ClassMetadataFactory */ protected function _newClassMetadataInstance($className) { - return new Doctrine_ORM_Mapping_ClassMetadata($className); + return new ClassMetadata($className); } /** @@ -199,10 +199,10 @@ class Doctrine_ORM_Mapping_ClassMetadataFactory * @param Doctrine_ClassMetadata $class The container for the metadata. * @param string $name The name of the class for which the metadata will be loaded. */ - private function _loadClassMetadata(Doctrine_ORM_Mapping_ClassMetadata $class, $name) + private function _loadClassMetadata(ClassMetadata $class, $name) { if ( ! class_exists($name) || empty($name)) { - throw new Doctrine_Exception("Couldn't find class " . $name . "."); + throw new DoctrineException("Couldn't find class " . $name . "."); } $names = array(); @@ -224,13 +224,13 @@ class Doctrine_ORM_Mapping_ClassMetadataFactory // Complete Id generator mapping. If AUTO is specified we choose the generator // most appropriate for the target platform. - if ($class->getIdGeneratorType() == Doctrine_ORM_Mapping_ClassMetadata::GENERATOR_TYPE_AUTO) { + if ($class->getIdGeneratorType() == \Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_AUTO) { if ($this->_targetPlatform->prefersSequences()) { - $class->setIdGeneratorType(Doctrine_ORM_Mapping_ClassMetadata::GENERATOR_TYPE_SEQUENCE); + $class->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_SEQUENCE); } else if ($this->_targetPlatform->prefersIdentityColumns()) { - $class->setIdGeneratorType(Doctrine_ORM_Mapping_ClassMetadata::GENERATOR_TYPE_IDENTITY); + $class->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_IDENTITY); } else { - $class->setIdGeneratorType(Doctrine_ORM_Mapping_ClassMetadata::GENERATOR_TYPE_TABLE); + $class->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_TABLE); } } diff --git a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php index 245afacde..def8a1207 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php @@ -1,27 +1,31 @@ getAnnotation('DoctrineEntity')) === false) { - throw new Doctrine_ORM_Exceptions_MappingException("$className is no entity."); + throw new MappingException("$className is no entity."); } if ($entityAnnot->tableName) { @@ -54,7 +58,7 @@ class Doctrine_ORM_Mapping_Driver_AnnotationDriver { $mapping['fieldName'] = $property->getName(); if ($columnAnnot = $property->getAnnotation('DoctrineColumn')) { if ($columnAnnot->type == null) { - throw new Doctrine_ORM_Exceptions_MappingException("Missing type on property " . $property->getName()); + throw new MappingException("Missing type on property " . $property->getName()); } $mapping['type'] = $columnAnnot->type; $mapping['length'] = $columnAnnot->length; @@ -91,59 +95,3 @@ class Doctrine_ORM_Mapping_Driver_AnnotationDriver { } } } - -/* Annotations */ - -final class DoctrineEntity extends Annotation { - public $tableName; - public $repositoryClass; - public $inheritanceType; -} -final class DoctrineInheritanceType extends Annotation {} -final class DoctrineDiscriminatorColumn extends Annotation { - public $name; - public $type; - public $length; -} -final class DoctrineDiscriminatorMap extends Annotation {} -final class DoctrineSubClasses extends Annotation {} -final class DoctrineId extends Annotation {} -final class DoctrineIdGenerator extends Annotation {} -final class DoctrineVersion extends Annotation {} -final class DoctrineJoinColumn extends Annotation { - public $name; - public $type; - public $length; - public $onDelete; - public $onUpdate; -} -final class DoctrineColumn extends Annotation { - public $type; - public $length; - public $unique; - public $nullable; -} -final class DoctrineOneToOne extends Annotation { - public $targetEntity; - public $mappedBy; - public $joinColumns; - public $cascade; -} -final class DoctrineOneToMany extends Annotation { - public $mappedBy; - public $targetEntity; - public $cascade; -} -final class DoctrineManyToOne extends Annotation { - public $targetEntity; - public $joinColumns; - public $cascade; -} -final class DoctrineManyToMany extends Annotation { - public $targetEntity; - public $joinColumns; - public $inverseJoinColumns; - public $joinTable; - public $mappedBy; - public $cascade; -} diff --git a/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php b/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php new file mode 100644 index 000000000..768e8c3bf --- /dev/null +++ b/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php @@ -0,0 +1,62 @@ +parse($targetReflection); $annotations = array(); foreach($data as $class => $parameters) { - if(is_subclass_of($class, 'Annotation')) { + if(is_subclass_of($class, '\Addendum\Annotation')) { foreach($parameters as $params) { $annotationReflection = new ReflectionClass($class); $annotations[$class][] = $annotationReflection->newInstance($params, $targetReflection); @@ -310,7 +316,7 @@ class Addendum { /** Raw mode test */ private static function checkRawDocCommentParsingNeeded() { if(self::$rawMode === null) { - $reflection = new ReflectionClass('Addendum'); + $reflection = new ReflectionClass('\Addendum\Addendum'); $method = $reflection->getMethod('checkRawDocCommentParsingNeeded'); self::setRawMode($method->getDocComment() === false); } diff --git a/lib/Doctrine/ORM/Mapping/Driver/addendum/annotations/annotation_parser.php b/lib/Doctrine/ORM/Mapping/Driver/addendum/annotations/annotation_parser.php index a951ceaff..5e80f0a22 100755 --- a/lib/Doctrine/ORM/Mapping/Driver/addendum/annotations/annotation_parser.php +++ b/lib/Doctrine/ORM/Mapping/Driver/addendum/annotations/annotation_parser.php @@ -19,7 +19,9 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA **/ - + +namespace Addendum; + class CompositeMatcher { protected $matchers = array(); private $wasConstructed = false; @@ -332,4 +334,4 @@ return $matches[1]; } } -?> + diff --git a/lib/Doctrine/ORM/Mapping/OneToManyMapping.php b/lib/Doctrine/ORM/Mapping/OneToManyMapping.php index 5283f919d..dca4026c9 100644 --- a/lib/Doctrine/ORM/Mapping/OneToManyMapping.php +++ b/lib/Doctrine/ORM/Mapping/OneToManyMapping.php @@ -19,7 +19,7 @@ * . */ -#namespace Doctrine\ORM\Mapping; +namespace Doctrine\ORM\Mapping; /** * Represents a one-to-many mapping. @@ -31,9 +31,8 @@ * * @author Roman Borschel * @since 2.0 - * @todo Rename to OneToManyMapping */ -class Doctrine_ORM_Mapping_OneToManyMapping extends Doctrine_ORM_Mapping_AssociationMapping +class OneToManyMapping extends AssociationMapping { /** The target foreign key columns that reference the sourceKeyColumns. */ /* NOTE: Currently not used because uni-directional one-many not supported atm. */ diff --git a/lib/Doctrine/ORM/Mapping/OneToOneMapping.php b/lib/Doctrine/ORM/Mapping/OneToOneMapping.php index 5a608253e..5770fab64 100644 --- a/lib/Doctrine/ORM/Mapping/OneToOneMapping.php +++ b/lib/Doctrine/ORM/Mapping/OneToOneMapping.php @@ -19,7 +19,7 @@ * . */ -#namespace Doctrine\ORM\Mappings; +namespace Doctrine\ORM\Mapping; /** * A one-to-one mapping describes a uni-directional mapping from one entity @@ -28,7 +28,7 @@ * @since 2.0 * @author Roman Borschel */ -class Doctrine_ORM_Mapping_OneToOneMapping extends Doctrine_ORM_Mapping_AssociationMapping +class OneToOneMapping extends AssociationMapping { /** * Maps the source foreign/primary key columns to the target primary/foreign key columns. diff --git a/lib/Doctrine/ORM/Persisters/AbstractEntityPersister.php b/lib/Doctrine/ORM/Persisters/AbstractEntityPersister.php index 39312b5c1..7a79a8bce 100644 --- a/lib/Doctrine/ORM/Persisters/AbstractEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/AbstractEntityPersister.php @@ -19,7 +19,7 @@ * . */ -#namespace Doctrine\ORM\Persisters; +namespace Doctrine\ORM\Persisters; /** * Base class for all EntityPersisters. @@ -27,11 +27,10 @@ * @author Roman Borschel * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @version $Revision: 3406 $ - * @link www.phpdoctrine.org + * @link www.doctrine-project.org * @since 2.0 - * @todo Rename to AbstractEntityPersister */ -abstract class Doctrine_ORM_Persisters_AbstractEntityPersister +abstract class AbstractEntityPersister { /** * The names of all the fields that are available on entities. @@ -71,7 +70,7 @@ abstract class Doctrine_ORM_Persisters_AbstractEntityPersister * that uses the given EntityManager and persists instances of the class described * by the given class metadata descriptor. */ - public function __construct(Doctrine_ORM_EntityManager $em, Doctrine_ORM_Mapping_ClassMetadata $classMetadata) + public function __construct(\Doctrine\ORM\EntityManager $em, \Doctrine\ORM\Mapping\ClassMetadata $classMetadata) { $this->_em = $em; $this->_entityName = $classMetadata->getClassName(); diff --git a/lib/Doctrine/ORM/Persisters/StandardEntityPersister.php b/lib/Doctrine/ORM/Persisters/StandardEntityPersister.php index a296ad1b0..e1a13bb72 100644 --- a/lib/Doctrine/ORM/Persisters/StandardEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/StandardEntityPersister.php @@ -19,9 +19,7 @@ * . */ -#namespace Doctrine\ORM\Persisters; - -#use Doctrine\ORM\Entity; +namespace Doctrine\ORM\Persisters; /** * The default persister strategy maps a single entity instance to a single database table, @@ -33,12 +31,12 @@ * @link www.doctrine-project.org * @since 2.0 */ -class Doctrine_ORM_Persisters_StandardEntityPersister extends Doctrine_ORM_Persisters_AbstractEntityPersister +class StandardEntityPersister extends AbstractEntityPersister { /** * Deletes an entity. */ - protected function _doDelete(Doctrine_ORM_Entity $record) + protected function _doDelete($record) { /*try { $this->_conn->beginInternalTransaction(); diff --git a/lib/Doctrine/ORM/Query.php b/lib/Doctrine/ORM/Query.php index 976e470b4..3a23df242 100644 --- a/lib/Doctrine/ORM/Query.php +++ b/lib/Doctrine/ORM/Query.php @@ -20,12 +20,14 @@ * . */ -#namespace Doctrine\ORM; +namespace Doctrine\ORM; + +use Doctrine\ORM\Query\Parser; /** * A Doctrine_ORM_Query object represents a DQL query. It is used to query databases for * data in an object-oriented fashion. A DQL query understands relations and inheritance - * and is dbms independant. + * and is to a large degree dbms independant. * * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @link www.doctrine-project.org @@ -35,7 +37,7 @@ * @author Konsta Vesterinen * @author Roman Borschel */ -class Doctrine_ORM_Query extends Doctrine_ORM_Query_Abstract +class Query extends AbstractQuery { /* Hydration mode constants */ /** @@ -122,7 +124,7 @@ class Doctrine_ORM_Query extends Doctrine_ORM_Query_Abstract * * @param Doctrine\ORM\EntityManager $entityManager */ - public function __construct(Doctrine_ORM_EntityManager $entityManager) + public function __construct(EntityManager $entityManager) { $this->_entityManager = $entityManager; $this->free(); @@ -165,7 +167,7 @@ class Doctrine_ORM_Query extends Doctrine_ORM_Query_Abstract return false; } - if ($collection instanceof Doctrine_ORM_Collection) { + if ($collection instanceof Collection) { return $collection->getFirst(); } else if (is_array($collection)) { return array_shift($collection); @@ -208,7 +210,7 @@ class Doctrine_ORM_Query extends Doctrine_ORM_Query_Abstract public function parse() { if ($this->_state === self::STATE_DIRTY) { - $parser = new Doctrine_ORM_Query_Parser($this); + $parser = new Parser($this); $this->_parserResult = $parser->parse(); $this->_state = self::STATE_CLEAN; } @@ -243,13 +245,13 @@ class Doctrine_ORM_Query extends Doctrine_ORM_Query_Abstract if ($cached === false) { // Cache does not exist, we have to create it. $result = $this->_execute($params, self::HYDRATE_ARRAY); - $queryResult = Doctrine_ORM_Query_CacheHandler::fromResultSet($this, $result); + $queryResult = \Doctrine\ORM\Query\CacheHandler::fromResultSet($this, $result); $cacheDriver->save($hash, $queryResult->toCachedForm(), $this->_resultCacheTTL); return $result; } else { // Cache exists, recover it and return the results. - $queryResult = Doctrine_ORM_Query_CacheHandler::fromCachedResult($this, $cached); + $queryResult = \Doctrine\ORM\Query\CacheHandler::fromCachedResult($this, $cached); return $queryResult->getResultSet(); } @@ -288,7 +290,7 @@ class Doctrine_ORM_Query extends Doctrine_ORM_Query_Abstract $cacheDriver->save($hash, $this->_parserResult->toCachedForm(), $this->_queryCacheTTL); } else { // Cache exists, recover it and return the results. - $this->_parserResult = Doctrine_ORM_Query_CacheHandler::fromCachedQuery($this, $cached); + $this->_parserResult = Doctrine\ORM\Query\CacheHandler::fromCachedQuery($this, $cached); $executor = $this->_parserResult->getSqlExecutor(); } @@ -333,8 +335,8 @@ class Doctrine_ORM_Query extends Doctrine_ORM_Query_Abstract */ public function setResultCache($resultCache) { - if ($resultCache !== null && ! ($resultCache instanceof Doctrine_ORM_Cache_Cache)) { - throw new Doctrine_ORM_Query_Exception( + if ($resultCache !== null && ! ($resultCache instanceof \Doctrine\ORM\Cache\Cache)) { + throw new DoctrineException( 'Method setResultCache() accepts only an instance of Doctrine_Cache_Interface or null.' ); } @@ -350,7 +352,7 @@ class Doctrine_ORM_Query extends Doctrine_ORM_Query_Abstract */ public function getResultCache() { - if ($this->_resultCache instanceof Doctrine_ORM_Cache_Cache) { + if ($this->_resultCache instanceof \Doctrine\ORM\Cache\Cache) { return $this->_resultCache; } else { return $this->_entityManager->getConnection()->getResultCacheDriver(); @@ -415,8 +417,8 @@ class Doctrine_ORM_Query extends Doctrine_ORM_Query_Abstract */ public function setQueryCache($queryCache) { - if ($queryCache !== null && ! ($queryCache instanceof Doctrine_ORM_Cache_Cache)) { - throw new Doctrine_ORM_Query_Exception( + if ($queryCache !== null && ! ($queryCache instanceof \Doctrine\ORM\Cache\Cache)) { + throw new DoctrineException( 'Method setResultCache() accepts only an instance of Doctrine_ORM_Cache_Interface or null.' ); } @@ -433,7 +435,7 @@ class Doctrine_ORM_Query extends Doctrine_ORM_Query_Abstract */ public function getQueryCache() { - if ($this->_queryCache instanceof Doctrine_ORM_Cache_Cache) { + if ($this->_queryCache instanceof \Doctrine\ORM\Cache\Cache) { return $this->_queryCache; } else { return $this->_entityManager->getConnection()->getQueryCacheDriver(); @@ -529,7 +531,7 @@ class Doctrine_ORM_Query extends Doctrine_ORM_Query_Abstract { $result = $this->execute(array(), $hydrationMode); if (count($result) > 1) { - throw Doctrine_ORM_Query_Exception::nonUniqueResult(); + throw QueryException::nonUniqueResult(); } return is_array($result) ? array_shift($result) : $result->getFirst(); diff --git a/lib/Doctrine/ORM/Query/AST/AggregateExpression.php b/lib/Doctrine/ORM/Query/AST/AggregateExpression.php index 741b49c26..8e799cc36 100644 --- a/lib/Doctrine/ORM/Query/AST/AggregateExpression.php +++ b/lib/Doctrine/ORM/Query/AST/AggregateExpression.php @@ -4,12 +4,14 @@ * and open the template in the editor. */ +namespace Doctrine\ORM\Query\AST; + /** * Description of AggregateExpression * * @author robo */ -class Doctrine_ORM_Query_AST_AggregateExpression extends Doctrine_ORM_Query_AST +class AggregateExpression extends Node { private $_functionName; private $_pathExpression; diff --git a/lib/Doctrine/ORM/Query/AST/ArithmeticExpression.php b/lib/Doctrine/ORM/Query/AST/ArithmeticExpression.php index a39157548..f35a2d29b 100644 --- a/lib/Doctrine/ORM/Query/AST/ArithmeticExpression.php +++ b/lib/Doctrine/ORM/Query/AST/ArithmeticExpression.php @@ -4,12 +4,14 @@ * and open the template in the editor. */ +namespace Doctrine\ORM\Query\AST; + /** * ArithmeticExpression ::= SimpleArithmeticExpression | "(" Subselect ")" * * @author robo */ -class Doctrine_ORM_Query_AST_ArithmeticExpression extends Doctrine_ORM_Query_AST +class ArithmeticExpression extends Node { private $_simpleArithmeticExpression; private $_subselect; diff --git a/lib/Doctrine/ORM/Query/AST/ArithmeticFactor.php b/lib/Doctrine/ORM/Query/AST/ArithmeticFactor.php index 343e95893..f93c8c95d 100644 --- a/lib/Doctrine/ORM/Query/AST/ArithmeticFactor.php +++ b/lib/Doctrine/ORM/Query/AST/ArithmeticFactor.php @@ -4,12 +4,14 @@ * and open the template in the editor. */ +namespace Doctrine\ORM\Query\AST; + /** * ArithmeticFactor ::= [("+" | "-")] ArithmeticPrimary * * @author robo */ -class Doctrine_ORM_Query_AST_ArithmeticFactor extends Doctrine_ORM_Query_AST +class ArithmeticFactor extends Node { private $_arithmeticPrimary; private $_pSigned; diff --git a/lib/Doctrine/ORM/Query/AST/ArithmeticTerm.php b/lib/Doctrine/ORM/Query/AST/ArithmeticTerm.php index 5dad83b45..057fd4440 100644 --- a/lib/Doctrine/ORM/Query/AST/ArithmeticTerm.php +++ b/lib/Doctrine/ORM/Query/AST/ArithmeticTerm.php @@ -4,12 +4,14 @@ * and open the template in the editor. */ +namespace Doctrine\ORM\Query\AST; + /** * ArithmeticTerm ::= ArithmeticFactor {("*" | "/") ArithmeticFactor}* * * @author robo */ -class Doctrine_ORM_Query_AST_ArithmeticTerm extends Doctrine_ORM_Query_AST +class ArithmeticTerm extends Node { private $_factors; diff --git a/lib/Doctrine/ORM/Query/AST/ComparisonExpression.php b/lib/Doctrine/ORM/Query/AST/ComparisonExpression.php index f8943831b..fbbd20a4c 100644 --- a/lib/Doctrine/ORM/Query/AST/ComparisonExpression.php +++ b/lib/Doctrine/ORM/Query/AST/ComparisonExpression.php @@ -4,6 +4,8 @@ * and open the template in the editor. */ +namespace Doctrine\ORM\Query\AST; + /** * ComparisonExpression ::= ArithmeticExpression ComparisonOperator ( QuantifiedExpression | ArithmeticExpression ) | * StringExpression ComparisonOperator (StringExpression | QuantifiedExpression) | @@ -14,7 +16,7 @@ * * @author robo */ -class Doctrine_ORM_Query_AST_ComparisonExpression extends Doctrine_ORM_Query_AST +class ComparisonExpression extends Node { private $_leftExpr; private $_rightExpr; diff --git a/lib/Doctrine/ORM/Query/AST/ComparisonOperator.php b/lib/Doctrine/ORM/Query/AST/ComparisonOperator.php index 87d256a3e..0db7c769f 100644 --- a/lib/Doctrine/ORM/Query/AST/ComparisonOperator.php +++ b/lib/Doctrine/ORM/Query/AST/ComparisonOperator.php @@ -19,6 +19,8 @@ * . */ +namespace Doctrine\ORM\Query\AST; + /** * ComparisonOperator = "=" | "<" | "<=" | "<>" | ">" | ">=" | "!=" * @@ -31,7 +33,7 @@ * @since 2.0 * @version $Revision$ */ -class Doctrine_ORM_Query_AST_ComparisonOperator extends Doctrine_ORM_Query_AST +class ComparisonOperator extends Node { } diff --git a/lib/Doctrine/ORM/Query/AST/ConditionalExpression.php b/lib/Doctrine/ORM/Query/AST/ConditionalExpression.php index 34f620aee..0479dddd2 100644 --- a/lib/Doctrine/ORM/Query/AST/ConditionalExpression.php +++ b/lib/Doctrine/ORM/Query/AST/ConditionalExpression.php @@ -4,12 +4,14 @@ * and open the template in the editor. */ +namespace Doctrine\ORM\Query\AST; + /** * ConditionalExpression ::= ConditionalTerm {"OR" ConditionalTerm}* * * @author robo */ -class Doctrine_ORM_Query_AST_ConditionalExpression extends Doctrine_ORM_Query_AST +class ConditionalExpression extends Node { private $_conditionalTerms = array(); diff --git a/lib/Doctrine/ORM/Query/AST/ConditionalFactor.php b/lib/Doctrine/ORM/Query/AST/ConditionalFactor.php index 980ed892b..bf69abe1c 100644 --- a/lib/Doctrine/ORM/Query/AST/ConditionalFactor.php +++ b/lib/Doctrine/ORM/Query/AST/ConditionalFactor.php @@ -4,12 +4,14 @@ * and open the template in the editor. */ +namespace Doctrine\ORM\Query\AST; + /** * ConditionalFactor ::= ["NOT"] ConditionalPrimary * * @author robo */ -class Doctrine_ORM_Query_AST_ConditionalFactor extends Doctrine_ORM_Query_AST +class ConditionalFactor extends Node { private $_not = false; private $_conditionalPrimary; diff --git a/lib/Doctrine/ORM/Query/AST/ConditionalPrimary.php b/lib/Doctrine/ORM/Query/AST/ConditionalPrimary.php index 61e9e45c2..b776076ae 100644 --- a/lib/Doctrine/ORM/Query/AST/ConditionalPrimary.php +++ b/lib/Doctrine/ORM/Query/AST/ConditionalPrimary.php @@ -4,12 +4,14 @@ * and open the template in the editor. */ +namespace Doctrine\ORM\Query\AST; + /** * ConditionalPrimary ::= SimpleConditionalExpression | "(" ConditionalExpression ")" * * @author robo */ -class Doctrine_ORM_Query_AST_ConditionalPrimary extends Doctrine_ORM_Query_AST +class ConditionalPrimary extends Node { private $_simpleConditionalExpression; private $_conditionalExpression; diff --git a/lib/Doctrine/ORM/Query/AST/ConditionalTerm.php b/lib/Doctrine/ORM/Query/AST/ConditionalTerm.php index bc5d30324..41956f8a1 100644 --- a/lib/Doctrine/ORM/Query/AST/ConditionalTerm.php +++ b/lib/Doctrine/ORM/Query/AST/ConditionalTerm.php @@ -4,12 +4,14 @@ * and open the template in the editor. */ +namespace Doctrine\ORM\Query\AST; + /** * ConditionalTerm ::= ConditionalFactor {"AND" ConditionalFactor}* * * @author robo */ -class Doctrine_ORM_Query_AST_ConditionalTerm extends Doctrine_ORM_Query_AST +class ConditionalTerm extends Node { private $_conditionalFactors = array(); diff --git a/lib/Doctrine/ORM/Query/AST/DeleteStatement.php b/lib/Doctrine/ORM/Query/AST/DeleteStatement.php index df3d4856c..ad859aafe 100644 --- a/lib/Doctrine/ORM/Query/AST/DeleteStatement.php +++ b/lib/Doctrine/ORM/Query/AST/DeleteStatement.php @@ -19,6 +19,8 @@ * . */ +namespace Doctrine\ORM\Query\AST; + /** * DeleteStatement = DeleteClause [WhereClause] * @@ -28,7 +30,7 @@ * @since 2.0 * @version $Revision$ */ -class Doctrine_ORM_Query_AST_DeleteStatement extends Doctrine_ORM_Query_AST +class DeleteStatement extends Node { protected $_deleteClause; diff --git a/lib/Doctrine/ORM/Query/AST/FromClause.php b/lib/Doctrine/ORM/Query/AST/FromClause.php index 7fb3b8949..2267e1019 100644 --- a/lib/Doctrine/ORM/Query/AST/FromClause.php +++ b/lib/Doctrine/ORM/Query/AST/FromClause.php @@ -19,6 +19,8 @@ * . */ +namespace Doctrine\ORM\Query\AST; + /** * FromClause ::= "FROM" IdentificationVariableDeclaration {"," IdentificationVariableDeclaration} * @@ -28,7 +30,7 @@ * @since 2.0 * @version $Revision$ */ -class Doctrine_ORM_Query_AST_FromClause extends Doctrine_ORM_Query_AST +class FromClause extends Node { protected $_identificationVariableDeclarations = array(); diff --git a/lib/Doctrine/ORM/Query/AST/Function.php b/lib/Doctrine/ORM/Query/AST/Function.php new file mode 100644 index 000000000..7fa7adcbb --- /dev/null +++ b/lib/Doctrine/ORM/Query/AST/Function.php @@ -0,0 +1,20 @@ +. */ +namespace Doctrine\ORM\Query\AST; + /** * IdentificationVariableDeclaration ::= RangeVariableDeclaration [IndexBy] {JoinVariableDeclaration}* * @@ -28,7 +30,7 @@ * @since 2.0 * @version $Revision$ */ -class Doctrine_ORM_Query_AST_IdentificationVariableDeclaration extends Doctrine_ORM_Query_AST +class IdentificationVariableDeclaration extends Node { protected $_rangeVariableDeclaration = null; diff --git a/lib/Doctrine/ORM/Query/AST/IndexBy.php b/lib/Doctrine/ORM/Query/AST/IndexBy.php index 8600c0270..a51d53591 100644 --- a/lib/Doctrine/ORM/Query/AST/IndexBy.php +++ b/lib/Doctrine/ORM/Query/AST/IndexBy.php @@ -19,6 +19,8 @@ * . */ +namespace Doctrine\ORM\Query\AST; + /** * IndexBy ::= "INDEX" "BY" SimpleStateFieldPathExpression * @@ -28,7 +30,7 @@ * @since 2.0 * @version $Revision$ */ -class Doctrine_ORM_Query_AST_IndexBy extends Doctrine_ORM_Query_AST +class IndexBy extends Node { protected $_simpleStateFieldPathExpression = null; diff --git a/lib/Doctrine/ORM/Query/AST/InputParameter.php b/lib/Doctrine/ORM/Query/AST/InputParameter.php index 0e47dfce1..66a3335a1 100644 --- a/lib/Doctrine/ORM/Query/AST/InputParameter.php +++ b/lib/Doctrine/ORM/Query/AST/InputParameter.php @@ -4,12 +4,14 @@ * and open the template in the editor. */ +namespace Doctrine\ORM\Query\AST; + /** * Description of InputParameter * * @author robo */ -class Doctrine_ORM_Query_AST_InputParameter extends Doctrine_ORM_Query_AST +class InputParameter extends Node { private $_isNamed; private $_position; diff --git a/lib/Doctrine/ORM/Query/AST/Join.php b/lib/Doctrine/ORM/Query/AST/Join.php index cb806ffb0..96c1b0b41 100644 --- a/lib/Doctrine/ORM/Query/AST/Join.php +++ b/lib/Doctrine/ORM/Query/AST/Join.php @@ -19,6 +19,8 @@ * . */ +namespace Doctrine\ORM\Query\AST; + /** * Join ::= ["LEFT" ["OUTER"] | "INNER"] "JOIN" JoinAssociationPathExpression * ["AS"] AliasIdentificationVariable [("ON" | "WITH") ConditionalExpression] @@ -29,7 +31,7 @@ * @since 2.0 * @version $Revision$ */ -class Doctrine_ORM_Query_AST_Join extends Doctrine_ORM_Query_AST +class Join extends Node { const JOIN_TYPE_LEFT = 1; diff --git a/lib/Doctrine/ORM/Query/AST/JoinPathExpression.php b/lib/Doctrine/ORM/Query/AST/JoinPathExpression.php index 34b400ae0..2d1b868e3 100644 --- a/lib/Doctrine/ORM/Query/AST/JoinPathExpression.php +++ b/lib/Doctrine/ORM/Query/AST/JoinPathExpression.php @@ -4,12 +4,14 @@ * and open the template in the editor. */ +namespace Doctrine\ORM\Query\AST; + /** * Description of JoinCollectionValuedPathExpression * * @author robo */ -class Doctrine_ORM_Query_AST_JoinPathExpression extends Doctrine_ORM_Query_AST +class JoinPathExpression extends Node { private $_identificationVariable; private $_assocField; diff --git a/lib/Doctrine/ORM/Query/AST/JoinVariableDeclaration.php b/lib/Doctrine/ORM/Query/AST/JoinVariableDeclaration.php index ac560ab5e..8db47445e 100644 --- a/lib/Doctrine/ORM/Query/AST/JoinVariableDeclaration.php +++ b/lib/Doctrine/ORM/Query/AST/JoinVariableDeclaration.php @@ -19,6 +19,8 @@ * . */ +namespace Doctrine\ORM\Query\AST; + /** * JoinVariableDeclaration ::= Join [IndexBy] * @@ -28,7 +30,7 @@ * @since 2.0 * @version $Revision$ */ -class Doctrine_ORM_Query_AST_JoinVariableDeclaration extends Doctrine_ORM_Query_AST +class JoinVariableDeclaration extends Node { protected $_join = null; diff --git a/lib/Doctrine/ORM/Query/AST/LikeExpression.php b/lib/Doctrine/ORM/Query/AST/LikeExpression.php index c2848e4ab..c89e5e889 100644 --- a/lib/Doctrine/ORM/Query/AST/LikeExpression.php +++ b/lib/Doctrine/ORM/Query/AST/LikeExpression.php @@ -4,12 +4,14 @@ * and open the template in the editor. */ +namespace Doctrine\ORM\Query\AST; + /** * LikeExpression ::= StringExpression ["NOT"] "LIKE" string ["ESCAPE" char] * * @author robo */ -class Doctrine_ORM_Query_AST_LikeExpression extends Doctrine_ORM_Query_AST +class LikeExpression extends Node { private $_stringExpr; private $_isNot; diff --git a/lib/Doctrine/ORM/Query/AST.php b/lib/Doctrine/ORM/Query/AST/Node.php similarity index 93% rename from lib/Doctrine/ORM/Query/AST.php rename to lib/Doctrine/ORM/Query/AST/Node.php index 43d292d01..87765836b 100644 --- a/lib/Doctrine/ORM/Query/AST.php +++ b/lib/Doctrine/ORM/Query/AST/Node.php @@ -19,6 +19,8 @@ * . */ +namespace Doctrine\ORM\Query\AST; + /** * Abstract class of an AST node * @@ -29,6 +31,6 @@ * @since 2.0 * @version $Revision$ */ -abstract class Doctrine_ORM_Query_AST +abstract class Node { } \ No newline at end of file diff --git a/lib/Doctrine/ORM/Query/AST/PathExpression.php b/lib/Doctrine/ORM/Query/AST/PathExpression.php index a352e8fad..47ec78983 100644 --- a/lib/Doctrine/ORM/Query/AST/PathExpression.php +++ b/lib/Doctrine/ORM/Query/AST/PathExpression.php @@ -4,12 +4,14 @@ * and open the template in the editor. */ +namespace Doctrine\ORM\Query\AST; + /** * Description of PathExpression * * @author robo */ -class Doctrine_ORM_Query_AST_PathExpression +class PathExpression extends Node { private $_parts; // Information that is attached during semantical analysis. diff --git a/lib/Doctrine/ORM/Query/AST/RangeVariableDeclaration.php b/lib/Doctrine/ORM/Query/AST/RangeVariableDeclaration.php index 28e9403e2..f267857f7 100644 --- a/lib/Doctrine/ORM/Query/AST/RangeVariableDeclaration.php +++ b/lib/Doctrine/ORM/Query/AST/RangeVariableDeclaration.php @@ -19,6 +19,8 @@ * . */ +namespace Doctrine\ORM\Query\AST; + /** * RangeVariableDeclaration ::= AbstractSchemaName ["AS"] AliasIdentificationVariable * @@ -28,7 +30,7 @@ * @since 2.0 * @version $Revision$ */ -class Doctrine_ORM_Query_AST_RangeVariableDeclaration extends Doctrine_ORM_Query_AST +class RangeVariableDeclaration extends Node { private $_classMetadata; private $_abstractSchemaName; diff --git a/lib/Doctrine/ORM/Query/AST/SelectClause.php b/lib/Doctrine/ORM/Query/AST/SelectClause.php index 254a7b585..6bdb5ded0 100644 --- a/lib/Doctrine/ORM/Query/AST/SelectClause.php +++ b/lib/Doctrine/ORM/Query/AST/SelectClause.php @@ -19,6 +19,8 @@ * . */ +namespace Doctrine\ORM\Query\AST; + /** * SelectClause = "SELECT" ["DISTINCT"] SelectExpression {"," SelectExpression} * @@ -28,7 +30,7 @@ * @since 2.0 * @version $Revision$ */ -class Doctrine_ORM_Query_AST_SelectClause extends Doctrine_ORM_Query_AST +class SelectClause extends Node { protected $_isDistinct; diff --git a/lib/Doctrine/ORM/Query/AST/SelectExpression.php b/lib/Doctrine/ORM/Query/AST/SelectExpression.php index df7231194..7cf2da0b0 100644 --- a/lib/Doctrine/ORM/Query/AST/SelectExpression.php +++ b/lib/Doctrine/ORM/Query/AST/SelectExpression.php @@ -19,6 +19,8 @@ * . */ +namespace Doctrine\ORM\Query\AST; + /** * SelectExpression ::= IdentificationVariable ["." "*"] | StateFieldPathExpression | * (AggregateExpression | "(" Subselect ")") [["AS"] FieldAliasIdentificationVariable] @@ -29,7 +31,7 @@ * @since 2.0 * @version $Revision$ */ -class Doctrine_ORM_Query_AST_SelectExpression extends Doctrine_ORM_Query_AST +class SelectExpression extends Node { protected $_expression; diff --git a/lib/Doctrine/ORM/Query/AST/SelectStatement.php b/lib/Doctrine/ORM/Query/AST/SelectStatement.php index 7ce807148..97edc4b2c 100644 --- a/lib/Doctrine/ORM/Query/AST/SelectStatement.php +++ b/lib/Doctrine/ORM/Query/AST/SelectStatement.php @@ -19,6 +19,8 @@ * . */ +namespace Doctrine\ORM\Query\AST; + /** * SelectStatement = SelectClause FromClause [WhereClause] [GroupByClause] [HavingClause] [OrderByClause] * @@ -28,7 +30,7 @@ * @since 2.0 * @version $Revision$ */ -class Doctrine_ORM_Query_AST_SelectStatement extends Doctrine_ORM_Query_AST +class SelectStatement extends Node { protected $_selectClause; protected $_fromClause; diff --git a/lib/Doctrine/ORM/Query/AST/SimpleArithmeticExpression.php b/lib/Doctrine/ORM/Query/AST/SimpleArithmeticExpression.php index e87d2acab..4e5f07a85 100644 --- a/lib/Doctrine/ORM/Query/AST/SimpleArithmeticExpression.php +++ b/lib/Doctrine/ORM/Query/AST/SimpleArithmeticExpression.php @@ -4,12 +4,14 @@ * and open the template in the editor. */ +namespace Doctrine\ORM\Query\AST; + /** * SimpleArithmeticExpression ::= ArithmeticTerm {("+" | "-") ArithmeticTerm}* * * @author robo */ -class Doctrine_ORM_Query_AST_SimpleArithmeticExpression extends Doctrine_ORM_Query_AST +class SimpleArithmeticExpression extends Node { private $_terms; diff --git a/lib/Doctrine/ORM/Query/AST/SimpleStateFieldPathExpression.php b/lib/Doctrine/ORM/Query/AST/SimpleStateFieldPathExpression.php index b79a96e69..2ca59a07f 100644 --- a/lib/Doctrine/ORM/Query/AST/SimpleStateFieldPathExpression.php +++ b/lib/Doctrine/ORM/Query/AST/SimpleStateFieldPathExpression.php @@ -19,6 +19,8 @@ * . */ +namespace Doctrine\ORM\Query\AST; + /** * SimpleStateFieldPathExpression ::= IdentificationVariable "." SimpleStateField * @@ -28,7 +30,7 @@ * @since 2.0 * @version $Revision$ */ -class Doctrine_ORM_Query_AST_SimpleStateFieldPathExpression extends Doctrine_ORM_Query_AST +class SimpleStateFieldPathExpression extends Node { protected $_identificationVariable = null; diff --git a/lib/Doctrine/ORM/Query/AST/UpdateStatetement.php b/lib/Doctrine/ORM/Query/AST/UpdateStatetement.php index 995aaa216..db1cd1bb0 100644 --- a/lib/Doctrine/ORM/Query/AST/UpdateStatetement.php +++ b/lib/Doctrine/ORM/Query/AST/UpdateStatetement.php @@ -19,6 +19,8 @@ * . */ +namespace Doctrine\ORM\Query\AST; + /** * UpdateStatement = UpdateClause [WhereClause] * @@ -28,7 +30,7 @@ * @since 2.0 * @version $Revision$ */ -class Doctrine_ORM_Query_AST_UpdateStatement extends Doctrine_ORM_Query_AST +class UpdateStatement extends Node { protected $_updateClause; diff --git a/lib/Doctrine/ORM/Query/AST/WhereClause.php b/lib/Doctrine/ORM/Query/AST/WhereClause.php index 9442b243b..5585168ec 100644 --- a/lib/Doctrine/ORM/Query/AST/WhereClause.php +++ b/lib/Doctrine/ORM/Query/AST/WhereClause.php @@ -4,12 +4,14 @@ * and open the template in the editor. */ +namespace Doctrine\ORM\Query\AST; + /** * Description of WhereClause * * @author robo */ -class Doctrine_ORM_Query_AST_WhereClause extends Doctrine_ORM_Query_AST +class WhereClause extends Node { private $_conditionalExpression; diff --git a/lib/Doctrine/ORM/Query/AbstractResult.php b/lib/Doctrine/ORM/Query/AbstractResult.php index 03d21ea02..40a9e6194 100644 --- a/lib/Doctrine/ORM/Query/AbstractResult.php +++ b/lib/Doctrine/ORM/Query/AbstractResult.php @@ -20,6 +20,8 @@ * . */ +namespace Doctrine\ORM\Query; + /** * Doctrine_ORM_Query_AbstractResult * @@ -30,7 +32,7 @@ * @author Guilherme Blanco * @author Konsta Vesterinen */ -abstract class Doctrine_ORM_Query_AbstractResult +abstract class AbstractResult { /** * @var mixed $_data The actual data to be stored. Can be an array, a string or an integer. diff --git a/lib/Doctrine/ORM/Query/SqlExecutor/Abstract.php b/lib/Doctrine/ORM/Query/Exec/AbstractExecutor.php similarity index 82% rename from lib/Doctrine/ORM/Query/SqlExecutor/Abstract.php rename to lib/Doctrine/ORM/Query/Exec/AbstractExecutor.php index cbed42684..62bdbf843 100644 --- a/lib/Doctrine/ORM/Query/SqlExecutor/Abstract.php +++ b/lib/Doctrine/ORM/Query/Exec/AbstractExecutor.php @@ -19,6 +19,8 @@ * . */ +namespace Doctrine\ORM\Query\Exec; + /** * Doctrine_ORM_Query_QueryResult * @@ -28,11 +30,11 @@ * @since 2.0 * @version $Revision$ */ -abstract class Doctrine_ORM_Query_SqlExecutor_Abstract implements Serializable +abstract class AbstractExecutor implements \Serializable { protected $_sqlStatements; - public function __construct(Doctrine_ORM_Query_AST $AST, $sqlWalker) + public function __construct(\Doctrine\ORM\Query\AST\Node $AST, $sqlWalker) { } @@ -52,7 +54,7 @@ abstract class Doctrine_ORM_Query_SqlExecutor_Abstract implements Serializable * @param Doctrine_Connection $conn The database connection that is used to execute the queries. * @param array $params The parameters. */ - abstract public function execute(Doctrine_DBAL_Connection $conn, array $params); + abstract public function execute(\Doctrine\DBAL\Connection $conn, array $params); /** * Factory method. @@ -61,10 +63,10 @@ abstract class Doctrine_ORM_Query_SqlExecutor_Abstract implements Serializable * @param Doctrine_ORM_Query_AST $AST The root node of the AST. * @return Doctrine_ORM_Query_SqlExecutor_Abstract The executor that is suitable for the given AST. */ - public static function create(Doctrine_ORM_Query_AST $AST, $sqlWalker) + public static function create(\Doctrine\ORM\Query\AST\Node $AST, $sqlWalker) { - $isDeleteStatement = $AST instanceof Doctrine_ORM_Query_AST_DeleteStatement; - $isUpdateStatement = $AST instanceof Doctrine_ORM_Query_AST_UpdateStatement; + $isDeleteStatement = $AST instanceof \Doctrine\ORM\Query\AST\DeleteStatement; + $isUpdateStatement = $AST instanceof \Doctrine\ORM\Query\AST\UpdateStatement; if ($isUpdateStatement || $isDeleteStatement) { // TODO: Inspect the $AST and create the proper executor like so (pseudo-code): @@ -77,9 +79,9 @@ abstract class Doctrine_ORM_Query_SqlExecutor_Abstract implements Serializable } } else ... */ - return new Doctrine_ORM_Query_SqlExecutor_SingleTableDeleteUpdate($AST); + return new SingleTableDeleteUpdateExecutor($AST); } else { - return new Doctrine_ORM_Query_SqlExecutor_SingleSelect($AST, $sqlWalker); + return new SingleSelectExecutor($AST, $sqlWalker); } } diff --git a/lib/Doctrine/ORM/Query/SqlExecutor/MultiTableDelete.php b/lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php similarity index 100% rename from lib/Doctrine/ORM/Query/SqlExecutor/MultiTableDelete.php rename to lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php diff --git a/lib/Doctrine/ORM/Query/SqlExecutor/MultiTableUpdate.php b/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php similarity index 100% rename from lib/Doctrine/ORM/Query/SqlExecutor/MultiTableUpdate.php rename to lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php diff --git a/lib/Doctrine/ORM/Query/SqlExecutor/SingleSelect.php b/lib/Doctrine/ORM/Query/Exec/SingleSelectExecutor.php similarity index 85% rename from lib/Doctrine/ORM/Query/SqlExecutor/SingleSelect.php rename to lib/Doctrine/ORM/Query/Exec/SingleSelectExecutor.php index 4a63631fb..e3e7e120c 100644 --- a/lib/Doctrine/ORM/Query/SqlExecutor/SingleSelect.php +++ b/lib/Doctrine/ORM/Query/Exec/SingleSelectExecutor.php @@ -19,6 +19,8 @@ * . */ +namespace Doctrine\ORM\Query\Exec; + /** * Executor that executes the SQL statement for simple DQL SELECT statements. * @@ -28,15 +30,15 @@ * @link www.doctrine-project.org * @since 2.0 */ -class Doctrine_ORM_Query_SqlExecutor_SingleSelect extends Doctrine_ORM_Query_SqlExecutor_Abstract +class SingleSelectExecutor extends AbstractExecutor { - public function __construct(Doctrine_ORM_Query_AST_SelectStatement $AST, $sqlWalker) + public function __construct(\Doctrine\ORM\Query\AST\SelectStatement $AST, $sqlWalker) { parent::__construct($AST, $sqlWalker); $this->_sqlStatements = $sqlWalker->walkSelectStatement($AST); } - public function execute(Doctrine_DBAL_Connection $conn, array $params) + public function execute(\Doctrine\DBAL\Connection $conn, array $params) { return $conn->execute($this->_sqlStatements, $params); } diff --git a/lib/Doctrine/ORM/Query/SqlExecutor/SingleTableDeleteUpdate.php b/lib/Doctrine/ORM/Query/Exec/SingleTableDeleteUpdateExecutor.php similarity index 86% rename from lib/Doctrine/ORM/Query/SqlExecutor/SingleTableDeleteUpdate.php rename to lib/Doctrine/ORM/Query/Exec/SingleTableDeleteUpdateExecutor.php index 1062ddd96..3322e9e5f 100644 --- a/lib/Doctrine/ORM/Query/SqlExecutor/SingleTableDeleteUpdate.php +++ b/lib/Doctrine/ORM/Query/Exec/SingleTableDeleteUpdateExecutor.php @@ -19,6 +19,8 @@ * . */ +namespace Doctrine\ORM\Query\Exec; + /** * Executor that executes the SQL statements for DQL DELETE/UPDATE statements on classes * that are mapped to a single table. @@ -30,15 +32,15 @@ * @since 2.0 * @todo This is exactly the same as SingleSelectExecutor. Unify in SingleStatementExecutor. */ -class Doctrine_ORM_Query_SqlExecutor_SingleTableDeleteUpdate extends Doctrine_ORM_Query_SqlExecutor_Abstract +class SingleTableDeleteUpdateExecutor extends AbstractExecutor { - public function __construct(Doctrine_ORM_Query_AST $AST) + public function __construct(\Doctrine\ORM\Query\AST\Node $AST) { parent::__construct($AST); $this->_sqlStatements = $AST->buildSql(); } - public function execute(Doctrine_Connection $conn, array $params) + public function execute(\Doctrine\DBAL\Connection $conn, array $params) { return $conn->exec($this->_sqlStatements, $params); } diff --git a/lib/Doctrine/ORM/Query/Scanner.php b/lib/Doctrine/ORM/Query/Lexer.php similarity index 79% rename from lib/Doctrine/ORM/Query/Scanner.php rename to lib/Doctrine/ORM/Query/Lexer.php index 6c79f39d8..a7c4868b4 100644 --- a/lib/Doctrine/ORM/Query/Scanner.php +++ b/lib/Doctrine/ORM/Query/Lexer.php @@ -19,32 +19,45 @@ * . */ +namespace Doctrine\ORM\Query; + /** * Scans a DQL query for tokens. * * @author Guilherme Blanco * @author Janne Vanhala + * @author Roman Borschel * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @link www.phpdoctrine.org * @since 2.0 * @version $Revision$ */ -class Doctrine_ORM_Query_Scanner +class Lexer { /** * Array of scanned tokens. * * @var array */ - protected $_tokens = array(); + private $_tokens = array(); /** * @todo Doc */ - protected $_position = 0; + private $_position = 0; /** * @todo Doc */ - protected $_peek = 0; + private $_peek = 0; + + /** + * @var array The next token in the query string. + */ + public $lookahead; + + /** + * @var array The last matched token. + */ + public $token; /** * Creates a new query scanner object. @@ -56,6 +69,55 @@ class Doctrine_ORM_Query_Scanner $this->_scan($input); } + public function isNextToken($token) + { + $la = $this->lookahead; + return ($la['type'] === $token || $la['value'] === $token); + } + + /** + * Moves to the next token in the input string. + * + * A token is an associative array containing three items: + * - 'value' : the string value of the token in the input string + * - 'type' : the type of the token (identifier, numeric, string, input + * parameter, none) + * - 'position' : the position of the token in the input string + * + * @return array|null the next token; null if there is no more tokens left + */ + public function next() + { + $this->token = $this->lookahead; + $this->_peek = 0; + if (isset($this->_tokens[$this->_position])) { + $this->lookahead = $this->_tokens[$this->_position++]; + } else { + $this->lookahead = null; + } + } + + /** + * Returns the next token in the input string. + * + * A token is an associative array containing three items: + * - 'value' : the string value of the token in the input string + * - 'type' : the type of the token (identifier, numeric, string, input + * parameter, none) + * - 'position' : the position of the token in the input string + * + * @return array|null the next token; null if there is no more tokens left + */ + /*public function next() + { + $this->_peek = 0; + if (isset($this->_tokens[$this->_position])) { + return $this->_tokens[$this->_position++]; + } else { + return null; + } + }*/ + /** * Checks if an identifier is a keyword and returns its correct type. * @@ -64,7 +126,7 @@ class Doctrine_ORM_Query_Scanner */ public function _checkLiteral($identifier) { - $name = 'Doctrine_ORM_Query_Token::T_' . strtoupper($identifier); + $name = 'Doctrine\ORM\Query\Token::T_' . strtoupper($identifier); if (defined($name)) { $type = constant($name); @@ -74,7 +136,7 @@ class Doctrine_ORM_Query_Scanner } } - return Doctrine_ORM_Query_Token::T_IDENTIFIER; + return Token::T_IDENTIFIER; } /** @@ -88,7 +150,7 @@ class Doctrine_ORM_Query_Scanner if ( ! isset($regex)) { $patterns = array( - '[a-z_][a-z0-9_]*', + '[a-z_][a-z0-9_\\\]*', '(?:[0-9]+(?:[,\.][0-9]+)*)(?:e[+-]?[0-9]+)?', "'(?:[^']|'')*'", '\?[0-9]+|:[a-z][a-z0-9_]+' @@ -117,23 +179,23 @@ class Doctrine_ORM_Query_Scanner { // $value is referenced because it can be changed if it is numeric. // [TODO] Revisit the _isNumeric and _getNumeric methods to reduce overhead. - $type = Doctrine_ORM_Query_Token::T_NONE; + $type = Token::T_NONE; $newVal = $this->_getNumeric($value); if ($newVal !== false){ $value = $newVal; if (strpos($value, '.') !== false || stripos($value, 'e') !== false) { - $type = Doctrine_ORM_Query_Token::T_FLOAT; + $type = Token::T_FLOAT; } else { - $type = Doctrine_ORM_Query_Token::T_INTEGER; + $type = Token::T_INTEGER; } } if ($value[0] === "'" && $value[strlen($value) - 1] === "'") { - $type = Doctrine_ORM_Query_Token::T_STRING; + $type = Token::T_STRING; } else if (ctype_alpha($value[0]) || $value[0] === '_') { $type = $this->_checkLiteral($value); } else if ($value[0] === '?' || $value[0] === ':') { - $type = Doctrine_ORM_Query_Token::T_INPUT_PARAMETER; + $type = Token::T_INPUT_PARAMETER; } return $type; @@ -212,27 +274,6 @@ class Doctrine_ORM_Query_Scanner $this->_peek = 0; } - /** - * Returns the next token in the input string. - * - * A token is an associative array containing three items: - * - 'value' : the string value of the token in the input string - * - 'type' : the type of the token (identifier, numeric, string, input - * parameter, none) - * - 'position' : the position of the token in the input string - * - * @return array|null the next token; null if there is no more tokens left - */ - public function next() - { - $this->_peek = 0; - if (isset($this->_tokens[$this->_position])) { - return $this->_tokens[$this->_position++]; - } else { - return null; - } - } - /** * @todo Doc */ diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index 1fada861c..825317773 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -20,19 +20,25 @@ * . */ +namespace Doctrine\ORM\Query; + +use Doctrine\ORM\Query\AST; +use Doctrine\ORM\Exceptions\QueryException; +use Doctrine\ORM\Query\Exec; + /** - * An LL(k) parser for the context-free grammar of Doctrine Query Language. - * Parses a DQL query, reports any errors in it, and generates the corresponding - * SQL. + * An LL(*) parser for the context-free grammar of Doctrine Query Language. + * Parses a DQL query, reports any errors in it, and generates an AST. * * @author Guilherme Blanco * @author Janne Vanhala + * @author Roman Borschel * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @link http://www.doctrine-project.org * @since 2.0 * @version $Revision$ */ -class Doctrine_ORM_Query_Parser +class Parser { /** * The minimum number of tokens read after last detected error before @@ -40,7 +46,7 @@ class Doctrine_ORM_Query_Parser * * @var int */ - const MIN_ERROR_DISTANCE = 2; + //const MIN_ERROR_DISTANCE = 2; /** * Path expressions that were encountered during parsing of SelectExpressions @@ -49,20 +55,13 @@ class Doctrine_ORM_Query_Parser * @var array */ private $_pendingPathExpressionsInSelect = array(); - - /** - * DQL string. - * - * @var string - */ - protected $_input; /** * A scanner object. * * @var Doctrine_ORM_Query_Scanner */ - protected $_scanner; + protected $_lexer; /** * The Parser Result object. @@ -74,38 +73,9 @@ class Doctrine_ORM_Query_Parser /** * Keyword symbol table * - * @var Doctrine_ORM_Query_Token + * @var Token */ protected $_keywordTable; - - // Scanner Stuff - - /** - * @var array The next token in the query string. - */ - public $lookahead; - - /** - * @var array The last matched token. - */ - public $token; - - // End of Scanner Stuff - - - // Error management stuff - - /** - * Array containing errors detected in the query string during parsing process. - * - * @var array - */ - protected $_errors; - - /** - * @var int The number of tokens read since last error in the input string. - */ - protected $_errorDistance; /** * The EntityManager. @@ -114,25 +84,21 @@ class Doctrine_ORM_Query_Parser */ protected $_em; - // End of Error management stuff - - /** * Creates a new query parser object. * * @param string $dql DQL to be parsed. * @param Doctrine_Connection $connection The connection to use */ - public function __construct(Doctrine_ORM_Query $query) + public function __construct(\Doctrine\ORM\Query $query) { $this->_em = $query->getEntityManager(); - $this->_input = $query->getDql(); - $this->_scanner = new Doctrine_ORM_Query_Scanner($this->_input); - $this->_keywordTable = new Doctrine_ORM_Query_Token(); + $this->_lexer = new Lexer($query->getDql()); + $this->_keywordTable = new Token(); - $defaultQueryComponent = Doctrine_ORM_Query_ParserRule::DEFAULT_QUERYCOMPONENT; + $defaultQueryComponent = ParserRule::DEFAULT_QUERYCOMPONENT; - $this->_parserResult = new Doctrine_ORM_Query_ParserResult( + $this->_parserResult = new ParserResult( '', array( // queryComponent $defaultQueryComponent => array( @@ -149,7 +115,6 @@ class Doctrine_ORM_Query_Parser ); $this->_parserResult->setEntityManager($this->_em); - $this->free(true); } @@ -166,9 +131,9 @@ class Doctrine_ORM_Query_Parser public function match($token) { if (is_string($token)) { - $isMatch = ($this->lookahead['value'] === $token); + $isMatch = ($this->_lexer->lookahead['value'] === $token); } else { - $isMatch = ($this->lookahead['type'] === $token); + $isMatch = ($this->_lexer->lookahead['type'] === $token); } if ( ! $isMatch) { @@ -176,30 +141,15 @@ class Doctrine_ORM_Query_Parser $this->syntaxError($this->_keywordTable->getLiteral($token)); } - $this->next(); + $this->_lexer->next(); return true; } - - /** - * Moves the parser scanner to next token - * - * @return void - */ - public function next() - { - $this->token = $this->lookahead; - $this->lookahead = $this->_scanner->next(); - $this->_errorDistance++; - } - - public function isA($value, $token) { - return $this->_scanner->isA($value, $token); + return $this->_lexer->isA($value, $token); } - /** * Free this parser enabling it to be reused * @@ -210,18 +160,18 @@ class Doctrine_ORM_Query_Parser public function free($deep = false, $position = 0) { // WARNING! Use this method with care. It resets the scanner! - $this->_scanner->resetPosition($position); + $this->_lexer->resetPosition($position); // Deep = true cleans peek and also any previously defined errors if ($deep) { - $this->_scanner->resetPeek(); - $this->_errors = array(); + $this->_lexer->resetPeek(); + //$this->_errors = array(); } - $this->token = null; - $this->lookahead = null; + $this->_lexer->token = null; + $this->_lexer->lookahead = null; - $this->_errorDistance = self::MIN_ERROR_DISTANCE; + //$this->_errorDistance = self::MIN_ERROR_DISTANCE; } @@ -234,21 +184,16 @@ class Doctrine_ORM_Query_Parser $AST = $this->_QueryLanguage(); // Check for end of string - if ($this->lookahead !== null) { - var_dump($this->lookahead); + if ($this->_lexer->lookahead !== null) { + var_dump($this->_lexer->lookahead); $this->syntaxError('end of string'); } - // Check for semantical errors - if (count($this->_errors) > 0) { - throw new Doctrine_ORM_Query_Exception(implode("\r\n", $this->_errors)); - } - // Create SqlWalker who creates the SQL from the AST - $sqlWalker = new Doctrine_ORM_Query_SqlWalker($this->_em, $this->_parserResult); + $sqlWalker = new SqlWalker($this->_em, $this->_parserResult); // Assign the executor in parser result - $this->_parserResult->setSqlExecutor(Doctrine_ORM_Query_SqlExecutor_Abstract::create($AST, $sqlWalker)); + $this->_parserResult->setSqlExecutor(Exec\AbstractExecutor::create($AST, $sqlWalker)); return $this->_parserResult; } @@ -256,11 +201,11 @@ class Doctrine_ORM_Query_Parser /** * Returns the scanner object associated with this object. * - * @return Doctrine_ORM_Query_Scanner + * @return Doctrine_ORM_Query_Lexer */ - public function getScanner() + public function getLexer() { - return $this->_scanner; + return $this->_lexer; } /** @@ -282,7 +227,7 @@ class Doctrine_ORM_Query_Parser public function syntaxError($expected = '', $token = null) { if ($token === null) { - $token = $this->lookahead; + $token = $this->_lexer->lookahead; } // Formatting message @@ -294,13 +239,13 @@ class Doctrine_ORM_Query_Parser $message .= 'Unexpected '; } - if ($this->lookahead === null) { + if ($this->_lexer->lookahead === null) { $message .= 'end of string.'; } else { - $message .= "'{$this->lookahead['value']}'"; + $message .= "'{$this->_lexer->lookahead['value']}'"; } - throw new Doctrine_ORM_Query_Exception($message); + throw new QueryException($message); } /** @@ -311,13 +256,11 @@ class Doctrine_ORM_Query_Parser */ public function semanticalError($message = '', $token = null) { - $this->_semanticalErrorCount++; - if ($token === null) { - $token = $this->token; + $token = $this->_lexer->token; } - - $this->_logError('Warning: ' . $message, $token); + //TODO: Include $token in $message + throw new QueryException($message); } /** @@ -326,7 +269,7 @@ class Doctrine_ORM_Query_Parser * @param string $message Message to log. * @param array $token Token that it was processing. */ - protected function _logError($message = '', $token) + /*protected function _logError($message = '', $token) { if ($this->_errorDistance >= self::MIN_ERROR_DISTANCE) { $message = 'line 0, col ' . $token['position'] . ': ' . $message; @@ -334,7 +277,7 @@ class Doctrine_ORM_Query_Parser } $this->_errorDistance = 0; - } + }*/ /** * Gets the EntityManager used by the parser. @@ -360,12 +303,6 @@ class Doctrine_ORM_Query_Parser return substr($this->_input, $start, $end); }*/ - private function _isNextToken($token) - { - $la = $this->lookahead; - return ($la['type'] === $token || $la['value'] === $token); - } - /** * Checks if the next-next (after lookahead) token start a function. * @@ -373,8 +310,7 @@ class Doctrine_ORM_Query_Parser */ private function _isFunction() { - $next = $this->_scanner->peek(); - $this->_scanner->resetPeek(); + $next = $this->_lexer->glimpse(); return ($next['value'] === '('); } @@ -385,10 +321,9 @@ class Doctrine_ORM_Query_Parser */ private function _isSubselect() { - $la = $this->lookahead; - $next = $this->_scanner->peek(); - $this->_scanner->resetPeek(); - return ($la['value'] === '(' && $next['type'] === Doctrine_ORM_Query_Token::T_SELECT); + $la = $this->_lexer->lookahead; + $next = $this->_lexer->glimpse(); + return ($la['value'] === '(' && $next['type'] === Token::T_SELECT); } /* Parse methods */ @@ -400,17 +335,17 @@ class Doctrine_ORM_Query_Parser */ private function _QueryLanguage() { - $this->lookahead = $this->_scanner->next(); - switch ($this->lookahead['type']) { - case Doctrine_ORM_Query_Token::T_SELECT: + $this->_lexer->next(); + switch ($this->_lexer->lookahead['type']) { + case Token::T_SELECT: return $this->_SelectStatement(); break; - case Doctrine_ORM_Query_Token::T_UPDATE: + case Token::T_UPDATE: return $this->_UpdateStatement(); break; - case Doctrine_ORM_Query_Token::T_DELETE: + case Token::T_DELETE: return $this->_DeleteStatement(); break; @@ -431,19 +366,19 @@ class Doctrine_ORM_Query_Parser $fromClause = $this->_FromClause(); $this->_processPendingPathExpressionsInSelect(); - $whereClause = $this->_isNextToken(Doctrine_ORM_Query_Token::T_WHERE) ? + $whereClause = $this->_lexer->isNextToken(Token::T_WHERE) ? $this->_WhereClause() : null; - $groupByClause = $this->_isNextToken(Doctrine_ORM_Query_Token::T_GROUP) ? + $groupByClause = $this->_lexer->isNextToken(Token::T_GROUP) ? $this->_GroupByClause() : null; - $havingClause = $this->_isNextToken(Doctrine_ORM_Query_Token::T_HAVING) ? + $havingClause = $this->_lexer->isNextToken(Token::T_HAVING) ? $this->_HavingClause() : null; - $orderByClause = $this->_isNextToken(Doctrine_ORM_Query_Token::T_ORDER) ? + $orderByClause = $this->_lexer->isNextToken(Token::T_ORDER) ? $this->_OrderByClause() : null; - return new Doctrine_ORM_Query_AST_SelectStatement( + return new AST\SelectStatement( $selectClause, $fromClause, $whereClause, $groupByClause, $havingClause, $orderByClause ); } @@ -519,23 +454,23 @@ class Doctrine_ORM_Query_Parser private function _SelectClause() { $isDistinct = false; - $this->match(Doctrine_ORM_Query_Token::T_SELECT); + $this->match(Token::T_SELECT); // Inspecting if we are in a DISTINCT query - if ($this->_isNextToken(Doctrine_ORM_Query_Token::T_DISTINCT)) { - $this->match(Doctrine_ORM_Query_Token::T_DISTINCT); + if ($this->_lexer->isNextToken(Token::T_DISTINCT)) { + $this->match(Token::T_DISTINCT); $isDistinct = true; } // Process SelectExpressions (1..N) $selectExpressions = array(); $selectExpressions[] = $this->_SelectExpression(); - while ($this->_isNextToken(',')) { + while ($this->_lexer->isNextToken(',')) { $this->match(','); $selectExpressions[] = $this->_SelectExpression(); } - return new Doctrine_ORM_Query_AST_SelectClause($selectExpressions, $isDistinct); + return new AST\SelectClause($selectExpressions, $isDistinct); } /** @@ -543,15 +478,15 @@ class Doctrine_ORM_Query_Parser */ private function _FromClause() { - $this->match(Doctrine_ORM_Query_Token::T_FROM); + $this->match(Token::T_FROM); $identificationVariableDeclarations = array(); $identificationVariableDeclarations[] = $this->_IdentificationVariableDeclaration(); - while ($this->_isNextToken(',')) { + while ($this->_lexer->isNextToken(',')) { $this->match(','); $identificationVariableDeclarations[] = $this->_IdentificationVariableDeclaration(); } - return new Doctrine_ORM_Query_AST_FromClause($identificationVariableDeclarations); + return new AST\FromClause($identificationVariableDeclarations); } /** @@ -563,24 +498,23 @@ class Doctrine_ORM_Query_Parser { $expression = null; $fieldIdentificationVariable = null; - $peek = $this->_scanner->peek(); - $this->_scanner->resetPeek(); + $peek = $this->_lexer->glimpse(); // First we recognize for an IdentificationVariable (DQL class alias) - if ($peek['value'] != '.' && $this->lookahead['type'] === Doctrine_ORM_Query_Token::T_IDENTIFIER) { + if ($peek['value'] != '.' && $this->_lexer->lookahead['type'] === Token::T_IDENTIFIER) { $expression = $this->_IdentificationVariable(); } else if (($isFunction = $this->_isFunction()) !== false || $this->_isSubselect()) { $expression = $isFunction ? $this->_AggregateExpression() : $this->_Subselect(); - if ($this->_isNextToken(Doctrine_ORM_Query_Token::T_AS)) { - $this->match(Doctrine_ORM_Query_Token::T_AS); + if ($this->_lexer->isNextToken(Token::T_AS)) { + $this->match(Token::T_AS); $fieldIdentificationVariable = $this->_FieldAliasIdentificationVariable(); - } elseif ($this->_isNextToken(Doctrine_ORM_Query_Token::T_IDENTIFIER)) { + } elseif ($this->_lexer->isNextToken(Token::T_IDENTIFIER)) { $fieldIdentificationVariable = $this->_FieldAliasIdentificationVariable(); } } else { $expression = $this->_PathExpressionInSelect(); } - return new Doctrine_ORM_Query_AST_SelectExpression($expression, $fieldIdentificationVariable); + return new AST\SelectExpression($expression, $fieldIdentificationVariable); } /** @@ -588,8 +522,8 @@ class Doctrine_ORM_Query_Parser */ private function _IdentificationVariable() { - $this->match(Doctrine_ORM_Query_Token::T_IDENTIFIER); - return $this->token['value']; + $this->match(Token::T_IDENTIFIER); + return $this->_lexer->token['value']; } /** @@ -598,18 +532,18 @@ class Doctrine_ORM_Query_Parser private function _IdentificationVariableDeclaration() { $rangeVariableDeclaration = $this->_RangeVariableDeclaration(); - $indexBy = $this->_isNextToken(Doctrine_ORM_Query_Token::T_INDEX) ? + $indexBy = $this->_lexer->isNextToken(Token::T_INDEX) ? $this->_IndexBy() : null; $joinVariableDeclarations = array(); while ( - $this->_isNextToken(Doctrine_ORM_Query_Token::T_LEFT) || - $this->_isNextToken(Doctrine_ORM_Query_Token::T_INNER) || - $this->_isNextToken(Doctrine_ORM_Query_Token::T_JOIN) + $this->_lexer->isNextToken(Token::T_LEFT) || + $this->_lexer->isNextToken(Token::T_INNER) || + $this->_lexer->isNextToken(Token::T_JOIN) ) { $joinVariableDeclarations[] = $this->_JoinVariableDeclaration(); } - return new Doctrine_ORM_Query_AST_IdentificationVariableDeclaration( + return new AST\IdentificationVariableDeclaration( $rangeVariableDeclaration, $indexBy, $joinVariableDeclarations ); } @@ -621,8 +555,8 @@ class Doctrine_ORM_Query_Parser { $abstractSchemaName = $this->_AbstractSchemaName(); - if ($this->_isNextToken(Doctrine_ORM_Query_Token::T_AS)) { - $this->match(Doctrine_ORM_Query_Token::T_AS); + if ($this->_lexer->isNextToken(Token::T_AS)) { + $this->match(Token::T_AS); } $aliasIdentificationVariable = $this->_AliasIdentificationVariable(); $classMetadata = $this->_em->getClassMetadata($abstractSchemaName); @@ -637,7 +571,7 @@ class Doctrine_ORM_Query_Parser ); $this->_parserResult->setQueryComponent($aliasIdentificationVariable, $queryComponent); - return new Doctrine_ORM_Query_AST_RangeVariableDeclaration( + return new AST\RangeVariableDeclaration( $classMetadata, $aliasIdentificationVariable ); } @@ -647,8 +581,8 @@ class Doctrine_ORM_Query_Parser */ private function _AbstractSchemaName() { - $this->match(Doctrine_ORM_Query_Token::T_IDENTIFIER); - return $this->token['value']; + $this->match(Token::T_IDENTIFIER); + return $this->_lexer->token['value']; } /** @@ -656,8 +590,8 @@ class Doctrine_ORM_Query_Parser */ private function _AliasIdentificationVariable() { - $this->match(Doctrine_ORM_Query_Token::T_IDENTIFIER); - return $this->token['value']; + $this->match(Token::T_IDENTIFIER); + return $this->_lexer->token['value']; } /** @@ -665,15 +599,14 @@ class Doctrine_ORM_Query_Parser */ private function _PathExpression() { - $this->match(Doctrine_ORM_Query_Token::T_IDENTIFIER); - $parts = array($this->token['value']); - while ($this->_isNextToken('.')) { + $this->match(Token::T_IDENTIFIER); + $parts = array($this->_lexer->token['value']); + while ($this->_lexer->isNextToken('.')) { $this->match('.'); - $this->match(Doctrine_ORM_Query_Token::T_IDENTIFIER); - $parts[] = $this->token['value']; + $this->match(Token::T_IDENTIFIER); + $parts[] = $this->_lexer->token['value']; } - $pathExpression = new Doctrine_ORM_Query_AST_PathExpression($parts); - + $pathExpression = new AST\PathExpression($parts); return $pathExpression; } @@ -695,9 +628,9 @@ class Doctrine_ORM_Query_Parser private function _JoinVariableDeclaration() { $join = $this->_Join(); - $indexBy = $this->_isNextToken(Doctrine_ORM_Query_Token::T_INDEX) ? + $indexBy = $this->_lexer->isNextToken(Token::T_INDEX) ? $this->_IndexBy() : null; - return new Doctrine_ORM_Query_AST_JoinVariableDeclaration($join, $indexBy); + return new AST\JoinVariableDeclaration($join, $indexBy); } /** @@ -707,25 +640,25 @@ class Doctrine_ORM_Query_Parser private function _Join() { // Check Join type - $joinType = Doctrine_ORM_Query_AST_Join::JOIN_TYPE_INNER; - if ($this->_isNextToken(Doctrine_ORM_Query_Token::T_LEFT)) { - $this->match(Doctrine_ORM_Query_Token::T_LEFT); + $joinType = AST\Join::JOIN_TYPE_INNER; + if ($this->_lexer->isNextToken(Token::T_LEFT)) { + $this->match(Token::T_LEFT); // Possible LEFT OUTER join - if ($this->_isNextToken(Doctrine_ORM_Query_Token::T_OUTER)) { - $this->match(Doctrine_ORM_Query_Token::T_OUTER); - $joinType = Doctrine_ORM_Query_AST_Join::JOIN_TYPE_LEFTOUTER; + if ($this->_lexer->isNextToken(Token::T_OUTER)) { + $this->match(Token::T_OUTER); + $joinType = AST\Join::JOIN_TYPE_LEFTOUTER; } else { - $joinType = Doctrine_ORM_Query_AST_Join::JOIN_TYPE_LEFT; + $joinType = AST\Join::JOIN_TYPE_LEFT; } - } else if ($this->_isNextToken(Doctrine_ORM_Query_Token::T_INNER)) { - $this->match(Doctrine_ORM_Query_Token::T_INNER); + } else if ($this->_lexer->isNextToken(Token::T_INNER)) { + $this->match(Token::T_INNER); } - $this->match(Doctrine_ORM_Query_Token::T_JOIN); + $this->match(Token::T_JOIN); $joinPathExpression = $this->_JoinPathExpression(); - if ($this->_isNextToken(Doctrine_ORM_Query_Token::T_AS)) { - $this->match(Doctrine_ORM_Query_Token::T_AS); + if ($this->_lexer->isNextToken(Token::T_AS)) { + $this->match(Token::T_AS); } $aliasIdentificationVariable = $this->_AliasIdentificationVariable(); @@ -752,18 +685,18 @@ class Doctrine_ORM_Query_Parser $this->_parserResult->setQueryComponent($aliasIdentificationVariable, $joinQueryComponent); // Create AST node - $join = new Doctrine_ORM_Query_AST_Join($joinType, $joinPathExpression, $aliasIdentificationVariable); + $join = new AST\Join($joinType, $joinPathExpression, $aliasIdentificationVariable); // Check Join where type if ( - $this->_isNextToken(Doctrine_ORM_Query_Token::T_ON) || - $this->_isNextToken(Doctrine_ORM_Query_Token::T_WITH) + $this->_lexer->isNextToken(Token::T_ON) || + $this->_lexer->isNextToken(Token::T_WITH) ) { - if ($this->_isNextToken(Doctrine_ORM_Query_Token::T_ON)) { - $this->match(Doctrine_ORM_Query_Token::T_ON); - $join->setWhereType(Doctrine_ORM_Query_AST_Join::JOIN_WHERE_ON); + if ($this->_lexer->isNextToken(Token::T_ON)) { + $this->match(Token::T_ON); + $join->setWhereType(AST\Join::JOIN_WHERE_ON); } else { - $this->match(Doctrine_ORM_Query_Token::T_WITH); + $this->match(Token::T_WITH); } $join->setConditionalExpression($this->_ConditionalExpression()); } @@ -808,9 +741,9 @@ class Doctrine_ORM_Query_Parser { $identificationVariable = $this->_IdentificationVariable(); $this->match('.'); - $this->match(Doctrine_ORM_Query_Token::T_IDENTIFIER); - $assocField = $this->token['value']; - return new Doctrine_ORM_Query_AST_JoinPathExpression( + $this->match(Token::T_IDENTIFIER); + $assocField = $this->_lexer->token['value']; + return new AST\JoinPathExpression( $identificationVariable, $assocField ); } @@ -820,8 +753,8 @@ class Doctrine_ORM_Query_Parser */ private function _IndexBy() { - $this->match(Doctrine_ORM_Query_Token::T_INDEX); - $this->match(Doctrine_ORM_Query_Token::T_BY); + $this->match(Token::T_INDEX); + $this->match(Token::T_BY); $pathExp = $this->_SimpleStateFieldPathExpression(); // Add the INDEX BY info to the query component $qComp = $this->_parserResult->getQueryComponent($pathExp->getIdentificationVariable()); @@ -837,9 +770,9 @@ class Doctrine_ORM_Query_Parser { $identificationVariable = $this->_IdentificationVariable(); $this->match('.'); - $this->match(Doctrine_ORM_Query_Token::T_IDENTIFIER); - $simpleStateField = $this->token['value']; - return new Doctrine_ORM_Query_AST_SimpleStateFieldPathExpression($identificationVariable, $simpleStateField); + $this->match(Token::T_IDENTIFIER); + $simpleStateField = $this->_lexer->token['value']; + return new AST\SimpleStateFieldPathExpression($identificationVariable, $simpleStateField); } /** @@ -860,11 +793,11 @@ class Doctrine_ORM_Query_Parser $class = $qComp['metadata']; - if ( ! $this->_isNextToken('.')) { + if ( ! $this->_lexer->isNextToken('.')) { $this->syntaxError(); } - while ($this->_isNextToken('.')) { + while ($this->_lexer->isNextToken('.')) { if ($stateFieldSeen) $this->syntaxError(); $this->match('.'); $part = $this->_IdentificationVariable(); @@ -880,7 +813,7 @@ class Doctrine_ORM_Query_Parser $parts[] = $part; } - $pathExpr = new Doctrine_ORM_Query_AST_PathExpression($parts); + $pathExpr = new AST\PathExpression($parts); if ($assocSeen) { $pathExpr->setIsSimpleStateFieldAssociationPathExpression(true); @@ -900,26 +833,26 @@ class Doctrine_ORM_Query_Parser { $isDistinct = false; $functionName = ''; - if ($this->_isNextToken(Doctrine_ORM_Query_Token::T_COUNT)) { - $this->match(Doctrine_ORM_Query_Token::T_COUNT); - $functionName = $this->token['value']; + if ($this->_lexer->isNextToken(Token::T_COUNT)) { + $this->match(Token::T_COUNT); + $functionName = $this->_lexer->token['value']; $this->match('('); - if ($this->_isNextToken(Doctrine_ORM_Query_Token::T_DISTINCT)) { - $this->match(Doctrine_ORM_Query_Token::T_DISTINCT); + if ($this->_lexer->isNextToken(Token::T_DISTINCT)) { + $this->match(Token::T_DISTINCT); $isDistinct = true; } // For now we only support a PathExpression here... $pathExp = $this->_PathExpression(); $this->match(')'); - } else if ($this->_isNextToken(Doctrine_ORM_Query_Token::T_AVG)) { - $this->match(Doctrine_ORM_Query_Token::T_AVG); - $functionName = $this->token['value']; + } else if ($this->_lexer->isNextToken(Token::T_AVG)) { + $this->match(Token::T_AVG); + $functionName = $this->_lexer->token['value']; $this->match('('); //... } else { $this->syntaxError('One of: MAX, MIN, AVG, SUM, COUNT'); } - return new Doctrine_ORM_Query_AST_AggregateExpression($functionName, $pathExp, $isDistinct); + return new AST\AggregateExpression($functionName, $pathExp, $isDistinct); } /** @@ -928,15 +861,15 @@ class Doctrine_ORM_Query_Parser */ private function _GroupByClause() { - $this->match(Doctrine_ORM_Query_Token::T_GROUP); - $this->match(Doctrine_ORM_Query_Token::T_BY); + $this->match(Token::T_GROUP); + $this->match(Token::T_BY); $groupByItems = array(); $groupByItems[] = $this->_PathExpression(); - while ($this->_isNextToken(',')) { + while ($this->_lexer->isNextToken(',')) { $this->match(','); $groupByItems[] = $this->_PathExpression(); } - return new Doctrine_ORM_Query_AST_GroupByClause($groupByItems); + return new AST\GroupByClause($groupByItems); } /** @@ -944,8 +877,8 @@ class Doctrine_ORM_Query_Parser */ private function _WhereClause() { - $this->match(Doctrine_ORM_Query_Token::T_WHERE); - return new Doctrine_ORM_Query_AST_WhereClause($this->_ConditionalExpression()); + $this->match(Token::T_WHERE); + return new AST\WhereClause($this->_ConditionalExpression()); } /** @@ -955,11 +888,11 @@ class Doctrine_ORM_Query_Parser { $conditionalTerms = array(); $conditionalTerms[] = $this->_ConditionalTerm(); - while ($this->_isNextToken(Doctrine_ORM_Query_Token::T_OR)) { - $this->match(Doctrine_ORM_Query_Token::T_OR); + while ($this->_lexer->isNextToken(Token::T_OR)) { + $this->match(Token::T_OR); $conditionalTerms[] = $this->_ConditionalTerm(); } - return new Doctrine_ORM_Query_AST_ConditionalExpression($conditionalTerms); + return new AST\ConditionalExpression($conditionalTerms); } /** @@ -969,11 +902,11 @@ class Doctrine_ORM_Query_Parser { $conditionalFactors = array(); $conditionalFactors[] = $this->_ConditionalFactor(); - while ($this->_isNextToken(Doctrine_ORM_Query_Token::T_AND)) { - $this->match(Doctrine_ORM_Query_Token::T_AND); + while ($this->_lexer->isNextToken(Token::T_AND)) { + $this->match(Token::T_AND); $conditionalFactors[] = $this->_ConditionalFactor(); } - return new Doctrine_ORM_Query_AST_ConditionalTerm($conditionalFactors); + return new AST\ConditionalTerm($conditionalFactors); } /** @@ -982,11 +915,11 @@ class Doctrine_ORM_Query_Parser private function _ConditionalFactor() { $not = false; - if ($this->_isNextToken(Doctrine_ORM_Query_Token::T_NOT)) { - $this->match(Doctrine_ORM_Query_Token::T_NOT); + if ($this->_lexer->isNextToken(Token::T_NOT)) { + $this->match(Token::T_NOT); $not = true; } - return new Doctrine_ORM_Query_AST_ConditionalFactor($this->_ConditionalPrimary(), $not); + return new AST\ConditionalFactor($this->_ConditionalPrimary(), $not); } /** @@ -994,19 +927,19 @@ class Doctrine_ORM_Query_Parser */ private function _ConditionalPrimary() { - $condPrimary = new Doctrine_ORM_Query_AST_ConditionalPrimary; - if ($this->_isNextToken('(')) { + $condPrimary = new AST\ConditionalPrimary; + if ($this->_lexer->isNextToken('(')) { $numUnmatched = 1; - $peek = $this->_scanner->peek(); + $peek = $this->_lexer->peek(); while ($numUnmatched > 0) { if ($peek['value'] == ')') { --$numUnmatched; } else if ($peek['value'] == '(') { ++$numUnmatched; } - $peek = $this->_scanner->peek(); + $peek = $this->_lexer->peek(); } - $this->_scanner->resetPeek(); + $this->_lexer->resetPeek(); //TODO: This is not complete, what about LIKE/BETWEEN/...etc? $comparisonOps = array("=", "<", "<=", "<>", ">", ">=", "!="); @@ -1033,39 +966,39 @@ class Doctrine_ORM_Query_Parser */ private function _SimpleConditionalExpression() { - if ($this->_isNextToken(Doctrine_ORM_Query_Token::T_NOT)) { - $token = $this->_scanner->glimpse(); + if ($this->_lexer->isNextToken(Token::T_NOT)) { + $token = $this->_lexer->glimpse(); } else { - $token = $this->lookahead; + $token = $this->_lexer->lookahead; } - if ($token['type'] === Doctrine_ORM_Query_Token::T_EXISTS) { + if ($token['type'] === Token::T_EXISTS) { return $this->_ExistsExpression(); } $stateFieldPathExpr = false; - if ($token['type'] === Doctrine_ORM_Query_Token::T_IDENTIFIER) { + if ($token['type'] === Token::T_IDENTIFIER) { // Peek beyond the PathExpression $stateFieldPathExpr = true; - $peek = $this->_scanner->peek(); + $peek = $this->_lexer->peek(); while ($peek['value'] === '.') { - $this->_scanner->peek(); - $peek = $this->_scanner->peek(); + $this->_lexer->peek(); + $peek = $this->_lexer->peek(); } - $this->_scanner->resetPeek(); + $this->_lexer->resetPeek(); $token = $peek; } if ($stateFieldPathExpr) { switch ($token['type']) { - case Doctrine_ORM_Query_Token::T_BETWEEN: + case Token::T_BETWEEN: return $this->_BetweenExpression(); - case Doctrine_ORM_Query_Token::T_LIKE: + case Token::T_LIKE: return $this->_LikeExpression(); - case Doctrine_ORM_Query_Token::T_IN: + case Token::T_IN: return $this->_InExpression(); - case Doctrine_ORM_Query_Token::T_IS: + case Token::T_IS: return $this->_NullComparisonExpression(); - case Doctrine_ORM_Query_Token::T_NONE: + case Token::T_NONE: return $this->_ComparisonExpression(); default: $this->syntaxError(); @@ -1074,10 +1007,10 @@ class Doctrine_ORM_Query_Parser return $this->_ComparisonExpression(); } else { switch ($token['type']) { - case Doctrine_ORM_Query_Token::T_INTEGER: + case Token::T_INTEGER: // IF it turns out its a ComparisonExpression, then it MUST be ArithmeticExpression break; - case Doctrine_ORM_Query_Token::T_STRING: + case Token::T_STRING: // IF it turns out its a ComparisonExpression, then it MUST be StringExpression break; default: @@ -1094,14 +1027,14 @@ class Doctrine_ORM_Query_Parser { $leftExpr = $this->_ArithmeticExpression(); $operator = $this->_ComparisonOperator(); - if ($this->lookahead['type'] === Doctrine_ORM_Query_Token::T_ALL || - $this->lookahead['type'] === Doctrine_ORM_Query_Token::T_ANY || - $this->lookahead['type'] === Doctrine_ORM_Query_Token::T_SOME) { + if ($this->_lexer->lookahead['type'] === Token::T_ALL || + $this->_lexer->lookahead['type'] === Token::T_ANY || + $this->_lexer->lookahead['type'] === Token::T_SOME) { $rightExpr = $this->_QuantifiedExpression(); } else { $rightExpr = $this->_ArithmeticExpression(); } - return new Doctrine_ORM_Query_AST_ComparisonExpression($leftExpr, $operator, $rightExpr); + return new AST\ComparisonExpression($leftExpr, $operator, $rightExpr); } /** @@ -1109,11 +1042,10 @@ class Doctrine_ORM_Query_Parser */ private function _ArithmeticExpression() { - $expr = new Doctrine_ORM_Query_AST_ArithmeticExpression; - if ($this->lookahead['value'] === '(') { - $peek = $this->_scanner->peek(); - $this->_scanner->resetPeek(); - if ($peek['type'] === Doctrine_ORM_Query_Token::T_SELECT) { + $expr = new AST\ArithmeticExpression; + if ($this->_lexer->lookahead['value'] === '(') { + $peek = $this->_lexer->glimpse(); + if ($peek['type'] === Token::T_SELECT) { $expr->setSubselect($this->_Subselect()); return $expr; } @@ -1129,16 +1061,16 @@ class Doctrine_ORM_Query_Parser { $terms = array(); $terms[] = $this->_ArithmeticTerm(); - while ($this->lookahead['value'] == '+' || $this->lookahead['value'] == '-') { - if ($this->lookahead['value'] == '+') { + while ($this->_lexer->lookahead['value'] == '+' || $this->_lexer->lookahead['value'] == '-') { + if ($this->_lexer->lookahead['value'] == '+') { $this->match('+'); } else { $this->match('-'); } - $terms[] = $this->token['value']; + $terms[] = $this->_lexer->token['value']; $terms[] = $this->_ArithmeticTerm(); } - return new Doctrine_ORM_Query_AST_SimpleArithmeticExpression($terms); + return new AST\SimpleArithmeticExpression($terms); } /** @@ -1148,16 +1080,16 @@ class Doctrine_ORM_Query_Parser { $factors = array(); $factors[] = $this->_ArithmeticFactor(); - while ($this->lookahead['value'] == '*' || $this->lookahead['value'] == '/') { - if ($this->lookahead['value'] == '*') { + while ($this->_lexer->lookahead['value'] == '*' || $this->_lexer->lookahead['value'] == '/') { + if ($this->_lexer->lookahead['value'] == '*') { $this->match('*'); } else { $this->match('/'); } - $factors[] = $this->token['value']; + $factors[] = $this->_lexer->token['value']; $factors[] = $this->_ArithmeticFactor(); } - return new Doctrine_ORM_Query_AST_ArithmeticTerm($factors); + return new AST\ArithmeticTerm($factors); } /** @@ -1166,14 +1098,14 @@ class Doctrine_ORM_Query_Parser private function _ArithmeticFactor() { $pSign = $nSign = false; - if ($this->lookahead['value'] == '+') { + if ($this->_lexer->lookahead['value'] == '+') { $this->match('+'); $pSign = true; - } else if ($this->lookahead['value'] == '-') { + } else if ($this->_lexer->lookahead['value'] == '-') { $this->match('-'); $nSign = true; } - return new Doctrine_ORM_Query_AST_ArithmeticFactor($this->_ArithmeticPrimary(), $pSign, $nSign); + return new AST\ArithmeticFactor($this->_ArithmeticPrimary(), $pSign, $nSign); } /** @@ -1181,23 +1113,30 @@ class Doctrine_ORM_Query_Parser */ private function _ArithmeticPrimary() { - if ($this->lookahead['value'] === '(') { + if ($this->_lexer->lookahead['value'] === '(') { $this->match('('); $expr = $this->_SimpleArithmeticExpression(); $this->match(')'); return $expr; } - switch ($this->lookahead['type']) { - case Doctrine_ORM_Query_Token::T_IDENTIFIER: + switch ($this->_lexer->lookahead['type']) { + case Token::T_IDENTIFIER: + $peek = $this->_lexer->glimpse(); + if ($peek['value'] == '(') { + if ($this->_isAggregateFunction($peek['type'])) { + return $this->_AggregateExpression(); + } + return $this->_FunctionsReturningStrings(); + } return $this->_StateFieldPathExpression(); - case Doctrine_ORM_Query_Token::T_INPUT_PARAMETER: - $this->match($this->lookahead['value']); - return new Doctrine_ORM_Query_AST_InputParameter($this->token['value']); - case Doctrine_ORM_Query_Token::T_STRING: - case Doctrine_ORM_Query_Token::T_INTEGER: - case Doctrine_ORM_Query_Token::T_FLOAT: - $this->match($this->lookahead['value']); - return $this->token['value']; + case Token::T_INPUT_PARAMETER: + $this->match($this->_lexer->lookahead['value']); + return new AST\InputParameter($this->_lexer->token['value']); + case Token::T_STRING: + case Token::T_INTEGER: + case Token::T_FLOAT: + $this->match($this->_lexer->lookahead['value']); + return $this->_lexer->token['value']; default: $this->syntaxError(); } @@ -1205,22 +1144,69 @@ class Doctrine_ORM_Query_Parser //TODO... } + /** + * PortableFunctionsReturningStrings ::= + * "CONCAT" "(" StringPrimary "," StringPrimary ")" | + * "SUBSTRING" "(" StringPrimary "," SimpleArithmeticExpression "," SimpleArithmeticExpression ")" | + * "TRIM" "(" [["LEADING" | "TRAILING" | "BOTH"] [char] "FROM"] StringPrimary ")" | + * "LOWER" "(" StringPrimary ")" | + * "UPPER" "(" StringPrimary ")" + */ + private function _FunctionsReturningStrings() + { + switch (strtoupper($this->_lexer->lookahead['value'])) { + case 'CONCAT': + + break; + case 'SUBSTRING': + + break; + case 'TRIM': + $this->match($this->_lexer->lookahead['value']); + $this->match('('); + //TODO: This is not complete! See BNF + $this->_StringPrimary(); + break; + case 'LOWER': + + break; + case 'UPPER': + + default: + $this->syntaxError('CONCAT, SUBSTRING, TRIM or UPPER'); + } + } + + private function _isAggregateFunction($tokenType) + { + switch ($tokenType) { + case Token::T_AVG: + case Token::T_MIN: + case Token::T_MAX: + case Token::T_SUM: + case Token::T_COUNT: + return true; + default: + return false; + } + } + /** * ComparisonOperator ::= "=" | "<" | "<=" | "<>" | ">" | ">=" | "!=" */ private function _ComparisonOperator() { - switch ($this->lookahead['value']) { + switch ($this->_lexer->lookahead['value']) { case '=': $this->match('='); return '='; case '<': $this->match('<'); $operator = '<'; - if ($this->_isNextToken('=')) { + if ($this->_lexer->isNextToken('=')) { $this->match('='); $operator .= '='; - } else if ($this->_isNextToken('>')) { + } else if ($this->_lexer->isNextToken('>')) { $this->match('>'); $operator .= '>'; } @@ -1228,7 +1214,7 @@ class Doctrine_ORM_Query_Parser case '>': $this->match('>'); $operator = '>'; - if ($this->_isNextToken('=')) { + if ($this->_lexer->isNextToken('=')) { $this->match('='); $operator .= '='; } @@ -1250,21 +1236,21 @@ class Doctrine_ORM_Query_Parser { $stringExpr = $this->_StringExpression(); $isNot = false; - if ($this->lookahead['type'] === Doctrine_ORM_Query_Token::T_NOT) { - $this->match(Doctrine_ORM_Query_Token::T_NOT); + if ($this->_lexer->lookahead['type'] === Token::T_NOT) { + $this->match(Token::T_NOT); $isNot = true; } - $this->match(Doctrine_ORM_Query_Token::T_LIKE); - $this->match(Doctrine_ORM_Query_Token::T_STRING); - $stringPattern = $this->token['value']; + $this->match(Token::T_LIKE); + $this->match(Token::T_STRING); + $stringPattern = $this->_lexer->token['value']; $escapeChar = null; - if ($this->lookahead['type'] === Doctrine_ORM_Query_Token::T_ESCAPE) { - $this->match(Doctrine_ORM_Query_Token::T_ESCAPE); - var_dump($this->lookahead); - //$this->match(Doctrine_ORM_Query_Token::T_) + if ($this->_lexer->lookahead['type'] === Token::T_ESCAPE) { + $this->match(Token::T_ESCAPE); + var_dump($this->_lexer->lookahead); + //$this->match(Token::T_) //$escapeChar = } - return new Doctrine_ORM_Query_AST_LikeExpression($stringExpr, $stringPattern, $isNot, $escapeChar); + return new AST\LikeExpression($stringExpr, $stringPattern, $isNot, $escapeChar); } /** @@ -1272,10 +1258,9 @@ class Doctrine_ORM_Query_Parser */ private function _StringExpression() { - if ($this->lookahead['value'] === '(') { - $peek = $this->_scanner->peek(); - $this->_scanner->resetPeek(); - if ($peek['type'] === Doctrine_ORM_Query_Token::T_SELECT) { + if ($this->_lexer->lookahead['value'] === '(') { + $peek = $this->_lexer->glimpse(); + if ($peek['type'] === Token::T_SELECT) { return $this->_Subselect(); } } @@ -1287,9 +1272,8 @@ class Doctrine_ORM_Query_Parser */ private function _StringPrimary() { - if ($this->lookahead['type'] === Doctrine_ORM_Query_Token::T_IDENTIFIER) { - $peek = $this->_scanner->peek(); - $this->_scanner->resetPeek(); + if ($this->_lexer->lookahead['type'] === Token::T_IDENTIFIER) { + $peek = $this->_lexer->glimpse(); if ($peek['value'] == '.') { return $this->_StateFieldPathExpression(); } else if ($peek['value'] == '(') { @@ -1297,9 +1281,9 @@ class Doctrine_ORM_Query_Parser } else { $this->syntaxError("'.' or '('"); } - } else if ($this->lookahead['type'] === Doctrine_ORM_Query_Token::T_STRING) { + } else if ($this->_lexer->lookahead['type'] === Token::T_STRING) { //TODO... - } else if ($this->lookahead['type'] === Doctrine_ORM_Query_Token::T_INPUT_PARAMETER) { + } else if ($this->_lexer->lookahead['type'] === Token::T_INPUT_PARAMETER) { //TODO... } else { $this->syntaxError('StateFieldPathExpression | string | InputParameter | FunctionsReturningStrings | AggregateExpression'); diff --git a/lib/Doctrine/ORM/Query/ParserResult.php b/lib/Doctrine/ORM/Query/ParserResult.php index 487cf44ff..3569a492f 100644 --- a/lib/Doctrine/ORM/Query/ParserResult.php +++ b/lib/Doctrine/ORM/Query/ParserResult.php @@ -19,6 +19,8 @@ * . */ +namespace Doctrine\ORM\Query; + /** * Doctrine_ORM_Query_ParserResult * @@ -29,7 +31,7 @@ * @since 2.0 * @version $Revision$ */ -class Doctrine_ORM_Query_ParserResult extends Doctrine_ORM_Query_AbstractResult +class ParserResult extends AbstractResult { /** * The EntityManager. @@ -71,7 +73,7 @@ class Doctrine_ORM_Query_ParserResult extends Doctrine_ORM_Query_AbstractResult /** * @nodoc */ - public function setSqlExecutor(Doctrine_ORM_Query_SqlExecutor_Abstract $executor) + public function setSqlExecutor(\Doctrine\ORM\Query\Exec\AbstractExecutor $executor) { $this->_data = $executor; } diff --git a/lib/Doctrine/ORM/Query/ParserResultDummy.php b/lib/Doctrine/ORM/Query/ParserResultDummy.php index 896af3c7e..3261252de 100644 --- a/lib/Doctrine/ORM/Query/ParserResultDummy.php +++ b/lib/Doctrine/ORM/Query/ParserResultDummy.php @@ -1,11 +1,13 @@ . */ +namespace Doctrine\ORM\Query; + /** * An abstract base class for the productions of the Doctrine Query Language * context-free grammar. @@ -30,7 +32,7 @@ * @since 2.0 * @version $Revision$ */ -abstract class Doctrine_ORM_Query_ParserRule +abstract class ParserRule { /** * @nodoc diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index bd66432c9..727e89838 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -4,12 +4,16 @@ * and open the template in the editor. */ +namespace Doctrine\ORM\Query; + +use Doctrine\ORM\Query\AST; + /** * Description of SqlWalker * * @author robo */ -class Doctrine_ORM_Query_SqlWalker +class SqlWalker { /** * A simple array keys representing table aliases and values table alias @@ -30,7 +34,7 @@ class Doctrine_ORM_Query_SqlWalker $sqlToDqlAliasMap = array(); foreach ($parserResult->getQueryComponents() as $dqlAlias => $qComp) { if ($dqlAlias != 'dctrn') { - $sqlAlias = $this->generateTableAlias($qComp['metadata']->getClassName()); + $sqlAlias = $this->generateTableAlias($qComp['metadata']->getTableName()); $sqlToDqlAliasMap[$sqlAlias] = $dqlAlias; } } @@ -40,7 +44,7 @@ class Doctrine_ORM_Query_SqlWalker $this->_dqlToSqlAliasMap = array_flip($sqlToDqlAliasMap); } - public function walkSelectStatement(Doctrine_ORM_Query_AST_SelectStatement $AST) + public function walkSelectStatement(AST\SelectStatement $AST) { $sql = $this->walkSelectClause($AST->getSelectClause()); $sql .= $this->walkFromClause($AST->getFromClause()); @@ -84,8 +88,8 @@ class Doctrine_ORM_Query_SqlWalker { $join = $joinVarDecl->getJoin(); $joinType = $join->getJoinType(); - if ($joinType == Doctrine_ORM_Query_AST_Join::JOIN_TYPE_LEFT || - $joinType == Doctrine_ORM_Query_AST_Join::JOIN_TYPE_LEFTOUTER) { + if ($joinType == AST\Join::JOIN_TYPE_LEFT || + $joinType == AST\Join::JOIN_TYPE_LEFTOUTER) { $sql = ' LEFT JOIN '; } else { $sql = ' INNER JOIN '; @@ -133,7 +137,7 @@ class Doctrine_ORM_Query_SqlWalker public function walkSelectExpression($selectExpression) { $sql = ''; - if ($selectExpression->getExpression() instanceof Doctrine_ORM_Query_AST_PathExpression) { + if ($selectExpression->getExpression() instanceof AST\PathExpression) { $pathExpression = $selectExpression->getExpression(); if ($pathExpression->isSimpleStateFieldPathExpression()) { $parts = $pathExpression->getParts(); @@ -158,7 +162,7 @@ class Doctrine_ORM_Query_SqlWalker throw new Doctrine_ORM_Query_Exception("Encountered invalid PathExpression during SQL construction."); } } - else if ($selectExpression->getExpression() instanceof Doctrine_ORM_Query_AST_AggregateExpression) { + else if ($selectExpression->getExpression() instanceof AST\AggregateExpression) { $aggExpr = $selectExpression->getExpression(); if ( ! $selectExpression->getFieldIdentificationVariable()) { @@ -216,12 +220,12 @@ class Doctrine_ORM_Query_SqlWalker return $this->_dqlToSqlAliasMap[$parts[0]] . '.' . $columnName; } - public function walkUpdateStatement(Doctrine_ORM_Query_AST_UpdateStatement $AST) + public function walkUpdateStatement(AST\UpdateStatement $AST) { } - public function walkDeleteStatement(Doctrine_ORM_Query_AST_DeleteStatement $AST) + public function walkDeleteStatement(AST\DeleteStatement $AST) { } @@ -237,10 +241,8 @@ class Doctrine_ORM_Query_SqlWalker public function walkConditionalTerm($condTerm) { - $sql = ''; - $sql .= implode(' AND ', array_map(array(&$this, 'walkConditionalFactor'), + return implode(' AND ', array_map(array(&$this, 'walkConditionalFactor'), $condTerm->getConditionalFactors())); - return $sql; } public function walkConditionalFactor($factor) @@ -250,10 +252,10 @@ class Doctrine_ORM_Query_SqlWalker $primary = $factor->getConditionalPrimary(); if ($primary->isSimpleConditionalExpression()) { $simpleCond = $primary->getSimpleConditionalExpression(); - if ($simpleCond instanceof Doctrine_ORM_Query_AST_ComparisonExpression) { + if ($simpleCond instanceof AST\ComparisonExpression) { $sql .= $this->walkComparisonExpression($simpleCond); } - else if ($simpleCond instanceof Doctrine_ORM_Query_AST_LikeExpression) { + else if ($simpleCond instanceof AST\LikeExpression) { $sql .= $this->walkLikeExpression($simpleCond); } // else if ... @@ -268,7 +270,7 @@ class Doctrine_ORM_Query_SqlWalker { $sql = ''; $stringExpr = $likeExpr->getStringExpression(); - if ($stringExpr instanceof Doctrine_ORM_Query_AST_PathExpression) { + if ($stringExpr instanceof AST\PathExpression) { $sql .= $this->walkPathExpression($stringExpr); } //TODO else... $sql .= ' LIKE ' . $likeExpr->getStringPattern(); @@ -278,11 +280,11 @@ class Doctrine_ORM_Query_SqlWalker public function walkComparisonExpression($compExpr) { $sql = ''; - if ($compExpr->getLeftExpression() instanceof Doctrine_ORM_Query_AST_ArithmeticExpression) { + if ($compExpr->getLeftExpression() instanceof AST\ArithmeticExpression) { $sql .= $this->walkArithmeticExpression($compExpr->getLeftExpression()); } // else... $sql .= ' ' . $compExpr->getOperator() . ' '; - if ($compExpr->getRightExpression() instanceof Doctrine_ORM_Query_AST_ArithmeticExpression) { + if ($compExpr->getRightExpression() instanceof AST\ArithmeticExpression) { $sql .= $this->walkArithmeticExpression($compExpr->getRightExpression()); } return $sql; @@ -315,15 +317,18 @@ class Doctrine_ORM_Query_SqlWalker $primary = $factor->getArithmeticPrimary(); if (is_numeric($primary)) { $sql .= $primary; - } else if ($primary instanceof Doctrine_ORM_Query_AST_PathExpression) { + } else if (is_string($primary)) { + //TODO: quote string according to platform + $sql .= $primary; + } else if ($primary instanceof AST\PathExpression) { $sql .= $this->walkPathExpression($primary); - } else if ($primary instanceof Doctrine_ORM_Query_AST_InputParameter) { + } else if ($primary instanceof AST\InputParameter) { if ($primary->isNamed()) { $sql .= ':' . $primary->getName(); } else { $sql .= '?'; } - } else if ($primary instanceof Doctrine_ORM_Query_AST_SimpleArithmeticExpression) { + } else if ($primary instanceof AST\SimpleArithmeticExpression) { $sql .= '(' . $this->walkSimpleArithmeticExpression($primary) . ')'; } @@ -379,7 +384,7 @@ class Doctrine_ORM_Query_SqlWalker // We may have a situation where we have all chars are lowercased if ($baseAlias == '') { // We simply grab the first 2 chars of component name - $baseAlias = substr($componentNam, 0, 2); + $baseAlias = substr($componentName, 0, 2); } $alias = $baseAlias; diff --git a/lib/Doctrine/ORM/Query/Token.php b/lib/Doctrine/ORM/Query/Token.php index 53facfbc1..ee330c4c8 100644 --- a/lib/Doctrine/ORM/Query/Token.php +++ b/lib/Doctrine/ORM/Query/Token.php @@ -19,6 +19,8 @@ * . */ +namespace Doctrine\ORM\Query; + /** * Container for token type constants of Doctrine Query Language. * @@ -29,7 +31,7 @@ * @since 2.0 * @version $Revision$ */ -final class Doctrine_ORM_Query_Token +final class Token { const T_NONE = 1; const T_IDENTIFIER = 2; diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index f58c33bbb..5c8bb509a 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -19,10 +19,12 @@ * . */ -#namespace Doctrine\ORM; +namespace Doctrine\ORM; -#use Doctrine\ORM\EntityManager; -#use Doctrine\ORM\Exceptions\UnitOfWorkException; +use Doctrine\ORM\Internal\CommitOrderCalculator; +use Doctrine\ORM\Internal\CommitOrderNode; +use Doctrine\ORM\EntityManager; +use Doctrine\ORM\Exceptions\UnitOfWorkException; /** * The UnitOfWork is responsible for tracking changes to objects during an @@ -30,12 +32,12 @@ * in the correct order. * * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link www.phpdoctrine.org + * @link www.doctrine-project.org * @since 2.0 * @version $Revision$ * @author Roman Borschel */ -class Doctrine_ORM_UnitOfWork +class UnitOfWork { /** * An Entity is in managed state when it has a primary key/identifier (and @@ -52,16 +54,6 @@ class Doctrine_ORM_UnitOfWork */ const STATE_NEW = 2; - /** - * An Entity is temporarily locked during deletes and saves. - * - * This state is used internally to ensure that circular deletes - * and saves will not cause infinite loops. - * @todo Not sure this is a good idea. It is a problematic solution because - * it hides the original state while the locked state is active. - */ - //const STATE_LOCKED = 6; - /** * A detached Entity is an instance with a persistent identity that is not * (or no longer) associated with an EntityManager (and a UnitOfWork). @@ -186,11 +178,11 @@ class Doctrine_ORM_UnitOfWork * * @param Doctrine\ORM\EntityManager $em */ - public function __construct(Doctrine_ORM_EntityManager $em) + public function __construct(EntityManager $em) { $this->_em = $em; //TODO: any benefit with lazy init? - $this->_commitOrderCalculator = new Doctrine_ORM_Internal_CommitOrderCalculator(); + $this->_commitOrderCalculator = new CommitOrderCalculator(); } /** @@ -358,7 +350,7 @@ class Doctrine_ORM_UnitOfWork if ( ! $idGen->isPostInsertGenerator()) { $idValue = $idGen->generate($entry); $this->_entityStates[$oid] = self::STATE_MANAGED; - if ( ! $idGen instanceof Doctrine_ORM_Id_Assigned) { + if ( ! $idGen instanceof \Doctrine\ORM\Id\Assigned) { $this->_entityIdentifiers[$oid] = array($idValue); $targetClass->getSingleIdReflectionProperty()->setValue($entry, $idValue); } else { @@ -377,7 +369,7 @@ class Doctrine_ORM_UnitOfWork $this->_entityChangeSets[$oid] = $data; $this->_originalEntityData[$oid] = $data; } else if ($state == self::STATE_DELETED) { - throw new Doctrine_Exception("Deleted entity in collection detected during flush."); + throw new DoctrineException("Deleted entity in collection detected during flush."); } // MANAGED associated entities are already taken into account // during changeset calculation anyway, since they are in the identity map. @@ -554,11 +546,11 @@ class Doctrine_ORM_UnitOfWork { $oid = spl_object_hash($entity); if ( ! isset($this->_entityIdentifiers[$oid])) { - throw new Doctrine_Exception("Entity without identity " + throw new DoctrineException("Entity without identity " . "can't be registered as dirty."); } if (isset($this->_deletedEntities[$oid])) { - throw new Doctrine_Exception("Removed object can't be registered as dirty."); + throw new DoctrineException("Removed object can't be registered as dirty."); } if ( ! isset($this->_dirtyEntities[$oid]) && ! isset($this->_newEntities[$oid])) { @@ -696,7 +688,7 @@ class Doctrine_ORM_UnitOfWork $classMetadata = $this->_em->getClassMetadata(get_class($entity)); $idHash = $this->getIdentifierHash($this->_entityIdentifiers[spl_object_hash($entity)]); if ($idHash === '') { - throw new Doctrine_Exception("Entity with oid '" . spl_object_hash($entity) + throw new DoctrineException("Entity with oid '" . spl_object_hash($entity) . "' has no identity and therefore can't be added to the identity map."); } $className = $classMetadata->getRootClassName(); @@ -739,7 +731,7 @@ class Doctrine_ORM_UnitOfWork $classMetadata = $this->_em->getClassMetadata(get_class($entity)); $idHash = $this->getIdentifierHash($this->_entityIdentifiers[$oid]); if ($idHash === '') { - throw new Doctrine_Exception("Entity with oid '" . spl_object_hash($entity) + throw new DoctrineException("Entity with oid '" . spl_object_hash($entity) . "' has no identity and therefore can't be removed from the identity map."); } $className = $classMetadata->getRootClassName(); @@ -886,7 +878,7 @@ class Doctrine_ORM_UnitOfWork } else { $idValue = $idGen->generate($entity); $this->_entityStates[$oid] = self::STATE_MANAGED; - if ( ! $idGen instanceof Doctrine_ORM_Id_Assigned) { + if ( ! $idGen instanceof \Doctrine\ORM\Id\Assigned) { $this->_entityIdentifiers[$oid] = array($idValue); $class->getSingleIdReflectionProperty()->setValue($entity, $idValue); } else { @@ -953,10 +945,10 @@ class Doctrine_ORM_UnitOfWork break; case self::STATE_DETACHED: //exception? - throw new Doctrine_Exception("A detached entity can't be deleted."); + throw new DoctrineException("A detached entity can't be deleted."); default: //TODO: throw UnitOfWorkException::invalidEntityState() - throw new Doctrine_Exception("Encountered invalid entity state."); + throw new DoctrineException("Encountered invalid entity state."); } $this->_cascadeDelete($entity, $visited); @@ -1002,7 +994,7 @@ class Doctrine_ORM_UnitOfWork } $relatedEntities = $class->getReflectionProperty($assocMapping->getSourceFieldName()) ->getValue($entity); - if ($relatedEntities instanceof Doctrine_ORM_Collection && + if ($relatedEntities instanceof \Doctrine\ORM\Collection && count($relatedEntities) > 0) { foreach ($relatedEntities as $relatedEntity) { $this->_doDelete($relatedEntity, $visited, $insertNow); @@ -1032,34 +1024,34 @@ class Doctrine_ORM_UnitOfWork $this->_commitOrderCalculator->clear(); } - public function scheduleCollectionUpdate(Doctrine_ORM_Collection $coll) + public function scheduleCollectionUpdate(Doctrine\ORM\Collection $coll) { $this->_collectionUpdates[] = $coll; } - public function isCollectionScheduledForUpdate(Doctrine_ORM_Collection $coll) + public function isCollectionScheduledForUpdate(Doctrine\ORM\Collection $coll) { //... } - public function scheduleCollectionDeletion(Doctrine_ORM_Collection $coll) + public function scheduleCollectionDeletion(Doctrine\ORM\Collection $coll) { //TODO: if $coll is already scheduled for recreation ... what to do? // Just remove $coll from the scheduled recreations? $this->_collectionDeletions[] = $coll; } - public function isCollectionScheduledForDeletion(Doctrine_Collection $coll) + public function isCollectionScheduledForDeletion(Doctrine\ORM\Collection $coll) { //... } - public function scheduleCollectionRecreation(Doctrine_Collection $coll) + public function scheduleCollectionRecreation(Doctrine\ORM\Collection $coll) { $this->_collectionRecreations[] = $coll; } - public function isCollectionScheduledForRecreation(Doctrine_Collection $coll) + public function isCollectionScheduledForRecreation(Doctrine\ORM\Collection $coll) { //... } @@ -1209,7 +1201,7 @@ class Doctrine_ORM_UnitOfWork * * @param Doctrine\ORM\Collection $coll */ - public function addManagedCollection(Doctrine_ORM_Collection $coll) + public function addManagedCollection(\Doctrine\ORM\Collection $coll) { } diff --git a/query-language.txt b/query-language.txt index 7955aadb5..ca82bb493 100644 --- a/query-language.txt +++ b/query-language.txt @@ -202,7 +202,7 @@ ArithmeticExpression ::= SimpleArithmeticExpression | "(" Subselect ")" SimpleArithmeticExpression ::= ArithmeticTerm {("+" | "-") ArithmeticTerm}* ArithmeticTerm ::= ArithmeticFactor {("*" | "/") ArithmeticFactor}* ArithmeticFactor ::= [("+" | "-")] ArithmeticPrimary -ArithmeticPrimary ::= StateFieldPathExpression | Literal | "(" SimpleArithmeticExpression ")" | Function | AggregateExpression +ArithmeticPrimary ::= StateFieldPathExpression | Literal | "(" SimpleArithmeticExpression ")" | FunctionsReturningStrings | AggregateExpression /* diff --git a/tests/AllTests.php b/tests/AllTests.php deleted file mode 100644 index 906cf02f5..000000000 --- a/tests/AllTests.php +++ /dev/null @@ -1,35 +0,0 @@ -addTest(Common_AllTests::suite()); - $suite->addTest(Dbal_AllTests::suite()); - $suite->addTest(Orm_AllTests::suite()); - - return $suite; - } -} - -if (PHPUnit_MAIN_METHOD == 'AllTests::main') { - AllTests::main(); -} \ No newline at end of file diff --git a/tests/Common/AllTests.php b/tests/Common/AllTests.php deleted file mode 100644 index b56dfde07..000000000 --- a/tests/Common/AllTests.php +++ /dev/null @@ -1,30 +0,0 @@ -addTest(Common_Collections_AllTests::suite()); - - return $suite; - } -} - -if (PHPUnit_MAIN_METHOD == 'Common_AllTests::main') { - Common_AllTests::main(); -} \ No newline at end of file diff --git a/tests/Common/Collections/AllTests.php b/tests/Common/Collections/AllTests.php deleted file mode 100644 index 8b8840b4e..000000000 --- a/tests/Common/Collections/AllTests.php +++ /dev/null @@ -1,30 +0,0 @@ -addTestSuite('Common_Collections_CollectionTest'); - - return $suite; - } -} - -if (PHPUnit_MAIN_METHOD == 'Common_Collections_AllTests::main') { - Common_Collections_AllTests::main(); -} \ No newline at end of file diff --git a/tests/Dbal/AllTests.php b/tests/Dbal/AllTests.php deleted file mode 100644 index 4c50cb84d..000000000 --- a/tests/Dbal/AllTests.php +++ /dev/null @@ -1,32 +0,0 @@ -addTest(Dbal_Component_AllTests::suite()); - $suite->addTest(Dbal_Ticket_AllTests::suite()); - - return $suite; - } -} - -if (PHPUnit_MAIN_METHOD == 'Dbal_AllTests::main') { - Dbal_AllTests::main(); -} \ No newline at end of file diff --git a/tests/Dbal/Component/AllTests.php b/tests/Dbal/Component/AllTests.php deleted file mode 100644 index 150106412..000000000 --- a/tests/Dbal/Component/AllTests.php +++ /dev/null @@ -1,30 +0,0 @@ -addTestSuite('Dbal_Component_TestTest'); - - return $suite; - } -} - -if (PHPUnit_MAIN_METHOD == 'Dbal_Component_AllTests::main') { - Dbal_Component_AllTests::main(); -} \ No newline at end of file diff --git a/tests/Dbal/Component/TestTest.php b/tests/Dbal/Component/TestTest.php deleted file mode 100644 index 71fe58b55..000000000 --- a/tests/Dbal/Component/TestTest.php +++ /dev/null @@ -1,10 +0,0 @@ -assertEquals(0, 0); - } -} \ No newline at end of file diff --git a/tests/Dbal/Ticket/1Test.php b/tests/Dbal/Ticket/1Test.php deleted file mode 100644 index 6d2539d97..000000000 --- a/tests/Dbal/Ticket/1Test.php +++ /dev/null @@ -1,10 +0,0 @@ -assertEquals(0, 0); - } -} \ No newline at end of file diff --git a/tests/Dbal/Ticket/AllTests.php b/tests/Dbal/Ticket/AllTests.php deleted file mode 100644 index 2a4a362be..000000000 --- a/tests/Dbal/Ticket/AllTests.php +++ /dev/null @@ -1,30 +0,0 @@ -addTestSuite('Dbal_Ticket_1Test'); - - return $suite; - } -} - -if (PHPUnit_MAIN_METHOD == 'Ticket_AllTests::main') { - Ticket_AllTests::main(); -} \ No newline at end of file diff --git a/tests/Doctrine/Tests/AllTests.php b/tests/Doctrine/Tests/AllTests.php new file mode 100644 index 000000000..64c219aa0 --- /dev/null +++ b/tests/Doctrine/Tests/AllTests.php @@ -0,0 +1,41 @@ +addTest(Common\AllTests::suite()); + $suite->addTest(DBAL\AllTests::suite()); + $suite->addTest(ORM\AllTests::suite()); + + return $suite; + } +} + +if (PHPUnit_MAIN_METHOD == 'AllTests::main') { + AllTests::main(); +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/Common/AllTests.php b/tests/Doctrine/Tests/Common/AllTests.php new file mode 100644 index 000000000..0371ffb2b --- /dev/null +++ b/tests/Doctrine/Tests/Common/AllTests.php @@ -0,0 +1,35 @@ +addTest(Collections\AllTests::suite()); + + return $suite; + } +} + +if (PHPUnit_MAIN_METHOD == 'Common_AllTests::main') { + AllTests::main(); +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/Common/Collections/AllTests.php b/tests/Doctrine/Tests/Common/Collections/AllTests.php new file mode 100644 index 000000000..3b8a5679f --- /dev/null +++ b/tests/Doctrine/Tests/Common/Collections/AllTests.php @@ -0,0 +1,33 @@ +addTestSuite('Doctrine\Tests\Common\Collections\CollectionTest'); + + return $suite; + } +} + +if (PHPUnit_MAIN_METHOD == 'Common_Collections_AllTests::main') { + AllTests::main(); +} \ No newline at end of file diff --git a/tests/Common/Collections/CollectionTest.php b/tests/Doctrine/Tests/Common/Collections/CollectionTest.php similarity index 80% rename from tests/Common/Collections/CollectionTest.php rename to tests/Doctrine/Tests/Common/Collections/CollectionTest.php index 60587ea36..b1c21c6b4 100644 --- a/tests/Common/Collections/CollectionTest.php +++ b/tests/Doctrine/Tests/Common/Collections/CollectionTest.php @@ -1,8 +1,10 @@ _coll = new Doctrine_Common_Collections_Collection; + $this->_coll = new \Doctrine\Common\Collections\Collection; } /*public function testExists() { diff --git a/tests/Doctrine/Tests/DBAL/AllTests.php b/tests/Doctrine/Tests/DBAL/AllTests.php new file mode 100644 index 000000000..5667d729a --- /dev/null +++ b/tests/Doctrine/Tests/DBAL/AllTests.php @@ -0,0 +1,38 @@ +addTest(Component\AllTests::suite()); + $suite->addTest(Ticket\AllTests::suite()); + + return $suite; + } +} + +if (PHPUnit_MAIN_METHOD == 'Dbal_AllTests::main') { + AllTests::main(); +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/DBAL/Component/AllTests.php b/tests/Doctrine/Tests/DBAL/Component/AllTests.php new file mode 100644 index 000000000..157f1aade --- /dev/null +++ b/tests/Doctrine/Tests/DBAL/Component/AllTests.php @@ -0,0 +1,33 @@ +addTestSuite('Doctrine\Tests\DBAL\Component\TestTest'); + + return $suite; + } +} + +if (PHPUnit_MAIN_METHOD == 'Dbal_Component_AllTests::main') { + AllTests::main(); +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/DBAL/Component/TestTest.php b/tests/Doctrine/Tests/DBAL/Component/TestTest.php new file mode 100644 index 000000000..02e87645c --- /dev/null +++ b/tests/Doctrine/Tests/DBAL/Component/TestTest.php @@ -0,0 +1,13 @@ +assertEquals(0, 0); + } +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/DBAL/Ticket/AllTests.php b/tests/Doctrine/Tests/DBAL/Ticket/AllTests.php new file mode 100644 index 000000000..938805457 --- /dev/null +++ b/tests/Doctrine/Tests/DBAL/Ticket/AllTests.php @@ -0,0 +1,33 @@ +addTestSuite('Doctrine\Tests\DBAL\Ticket\Test1'); + + return $suite; + } +} + +if (PHPUnit_MAIN_METHOD == 'Ticket_AllTests::main') { + AllTests::main(); +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/DBAL/Ticket/Test1.php b/tests/Doctrine/Tests/DBAL/Ticket/Test1.php new file mode 100644 index 000000000..ab7b44c44 --- /dev/null +++ b/tests/Doctrine/Tests/DBAL/Ticket/Test1.php @@ -0,0 +1,13 @@ +assertEquals(0, 0); + } +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/DbalTestCase.php b/tests/Doctrine/Tests/DbalTestCase.php new file mode 100644 index 000000000..2478e7bcc --- /dev/null +++ b/tests/Doctrine/Tests/DbalTestCase.php @@ -0,0 +1,10 @@ +_platformMock = new Doctrine_DatabasePlatformMock(); + $this->_platformMock = new DatabasePlatformMock(); $this->_platform = $this->_platformMock; } diff --git a/tests/lib/mocks/Doctrine_DatabasePlatformMock.php b/tests/Doctrine/Tests/Mocks/DatabasePlatformMock.php similarity index 87% rename from tests/lib/mocks/Doctrine_DatabasePlatformMock.php rename to tests/Doctrine/Tests/Mocks/DatabasePlatformMock.php index 42b983d33..b8c036fb4 100644 --- a/tests/lib/mocks/Doctrine_DatabasePlatformMock.php +++ b/tests/Doctrine/Tests/Mocks/DatabasePlatformMock.php @@ -1,10 +1,8 @@ \ No newline at end of file diff --git a/tests/lib/mocks/Doctrine_EntityManagerMock.php b/tests/Doctrine/Tests/Mocks/EntityManagerMock.php similarity index 81% rename from tests/lib/mocks/Doctrine_EntityManagerMock.php rename to tests/Doctrine/Tests/Mocks/EntityManagerMock.php index b17fbeca3..8486d3282 100644 --- a/tests/lib/mocks/Doctrine_EntityManagerMock.php +++ b/tests/Doctrine/Tests/Mocks/EntityManagerMock.php @@ -1,13 +1,11 @@ _idGenerators[$className])) { return $this->_idGenerators[$className]; } + return parent::getIdGenerator($className); } } diff --git a/tests/lib/mocks/Doctrine_EntityPersisterMock.php b/tests/Doctrine/Tests/Mocks/EntityPersisterMock.php similarity index 87% rename from tests/lib/mocks/Doctrine_EntityPersisterMock.php rename to tests/Doctrine/Tests/Mocks/EntityPersisterMock.php index 74aee4bf5..1ba6ac9a7 100644 --- a/tests/lib/mocks/Doctrine_EntityPersisterMock.php +++ b/tests/Doctrine/Tests/Mocks/EntityPersisterMock.php @@ -1,11 +1,11 @@ _inserts[] = $entity; - if ( ! is_null($this->_mockIdGeneratorType) && $this->_mockIdGeneratorType == Doctrine_ORM_Mapping_ClassMetadata::GENERATOR_TYPE_IDENTITY + if ( ! is_null($this->_mockIdGeneratorType) && $this->_mockIdGeneratorType == \Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_IDENTITY || $this->_classMetadata->isIdGeneratorIdentity()) { return $this->_identityColumnValueCounter++; } diff --git a/tests/lib/mocks/Doctrine_HydratorMockStatement.php b/tests/Doctrine/Tests/Mocks/HydratorMockStatement.php similarity index 96% rename from tests/lib/mocks/Doctrine_HydratorMockStatement.php rename to tests/Doctrine/Tests/Mocks/HydratorMockStatement.php index 56714c378..81c9d7ab4 100644 --- a/tests/lib/mocks/Doctrine_HydratorMockStatement.php +++ b/tests/Doctrine/Tests/Mocks/HydratorMockStatement.php @@ -1,6 +1,6 @@ */ -class Doctrine_HydratorMockStatement +class HydratorMockStatement { private $_resultSet; diff --git a/tests/lib/mocks/Doctrine_IdentityIdGeneratorMock.php b/tests/Doctrine/Tests/Mocks/IdentityIdGeneratorMock.php similarity index 65% rename from tests/lib/mocks/Doctrine_IdentityIdGeneratorMock.php rename to tests/Doctrine/Tests/Mocks/IdentityIdGeneratorMock.php index 2c56d8026..e0ed9357d 100644 --- a/tests/lib/mocks/Doctrine_IdentityIdGeneratorMock.php +++ b/tests/Doctrine/Tests/Mocks/IdentityIdGeneratorMock.php @@ -1,13 +1,13 @@ addTestSuite('Doctrine\Tests\ORM\UnitOfWorkTest'); + $suite->addTestSuite('Doctrine\Tests\ORM\EntityManagerTest'); + $suite->addTestSuite('Doctrine\Tests\ORM\EntityPersisterTest'); + $suite->addTestSuite('Doctrine\Tests\ORM\CommitOrderCalculatorTest'); + + $suite->addTest(Query\AllTests::suite()); + $suite->addTest(Hydration\AllTests::suite()); + $suite->addTest(Entity\AllTests::suite()); + $suite->addTest(Associations\AllTests::suite()); + $suite->addTest(Mapping\AllTests::suite()); + $suite->addTest(Functional\AllTests::suite()); + + return $suite; + } +} + +if (PHPUnit_MAIN_METHOD == 'Orm_AllTests::main') { + AllTests::main(); +} diff --git a/tests/Doctrine/Tests/ORM/Associations/AllTests.php b/tests/Doctrine/Tests/ORM/Associations/AllTests.php new file mode 100644 index 000000000..2906403cb --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Associations/AllTests.php @@ -0,0 +1,30 @@ +addTestSuite('Doctrine\Tests\ORM\Associations\OneToOneMappingTest'); + + return $suite; + } +} + +if (PHPUnit_MAIN_METHOD == 'Orm_Associations_AllTests::main') { + AllTests::main(); +} diff --git a/tests/Orm/Associations/CascadeTest.php b/tests/Doctrine/Tests/ORM/Associations/CascadeTest.php similarity index 100% rename from tests/Orm/Associations/CascadeTest.php rename to tests/Doctrine/Tests/ORM/Associations/CascadeTest.php diff --git a/tests/Orm/Associations/OneToOneMappingTest.php b/tests/Doctrine/Tests/ORM/Associations/OneToOneMappingTest.php similarity index 80% rename from tests/Orm/Associations/OneToOneMappingTest.php rename to tests/Doctrine/Tests/ORM/Associations/OneToOneMappingTest.php index 65a4f839b..efa0f31f1 100644 --- a/tests/Orm/Associations/OneToOneMappingTest.php +++ b/tests/Doctrine/Tests/ORM/Associations/OneToOneMappingTest.php @@ -1,7 +1,10 @@ 'Person', // This is normally filled by ClassMetadata ); - $oneToOneMapping = new Doctrine_ORM_Mapping_OneToOneMapping($owningSideMapping); + $oneToOneMapping = new \Doctrine\ORM\Mapping\OneToOneMapping($owningSideMapping); $this->assertEquals(array('address_id' => 'id'), $oneToOneMapping->getSourceToTargetKeyColumns()); $this->assertEquals(array('id' => 'address_id'), $oneToOneMapping->getTargetToSourceKeyColumns()); @@ -29,7 +32,7 @@ class Orm_Associations_OneToOneMappingTest extends Doctrine_OrmTestCase 'mappedBy' => 'address' ); - $oneToOneMapping = new Doctrine_ORM_Mapping_OneToOneMapping($inverseSideMapping); + $oneToOneMapping = new \Doctrine\ORM\Mapping\OneToOneMapping($inverseSideMapping); $this->assertEquals('address', $oneToOneMapping->getMappedByFieldName()); $this->assertEquals('Address', $oneToOneMapping->getSourceEntityName()); $this->assertEquals('Person', $oneToOneMapping->getTargetEntityName()); @@ -38,4 +41,3 @@ class Orm_Associations_OneToOneMappingTest extends Doctrine_OrmTestCase } } -?> \ No newline at end of file diff --git a/tests/Orm/CommitOrderCalculatorTest.php b/tests/Doctrine/Tests/ORM/CommitOrderCalculatorTest.php similarity index 80% rename from tests/Orm/CommitOrderCalculatorTest.php rename to tests/Doctrine/Tests/ORM/CommitOrderCalculatorTest.php index 21a1161f3..fe56fe8f9 100644 --- a/tests/Orm/CommitOrderCalculatorTest.php +++ b/tests/Doctrine/Tests/ORM/CommitOrderCalculatorTest.php @@ -1,5 +1,8 @@ _calc = new Doctrine_ORM_Internal_CommitOrderCalculator(); + $this->_calc = new \Doctrine\ORM\Internal\CommitOrderCalculator(); } /** Helper to create an array of nodes */ @@ -22,7 +25,7 @@ class Orm_CommitOrderCalculatorTest extends Doctrine_OrmTestCase { $nodes = array(); foreach ($names as $name) { - $node = new Doctrine_ORM_Internal_CommitOrderNode($name, $this->_calc); + $node = new \Doctrine\ORM\Internal\CommitOrderNode($name, $this->_calc); $nodes[$name] = $node; $this->_calc->addNode($node->getClass(), $node); } diff --git a/tests/Orm/Entity/AccessorTest.php b/tests/Doctrine/Tests/ORM/Entity/AccessorTest.php similarity index 100% rename from tests/Orm/Entity/AccessorTest.php rename to tests/Doctrine/Tests/ORM/Entity/AccessorTest.php diff --git a/tests/Doctrine/Tests/ORM/Entity/AllTests.php b/tests/Doctrine/Tests/ORM/Entity/AllTests.php new file mode 100644 index 000000000..d61f2cd90 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Entity/AllTests.php @@ -0,0 +1,32 @@ +addTestSuite('Orm_Entity_AccessorTest'); + $suite->addTestSuite('Doctrine\Tests\ORM\Entity\ConstructorTest'); + + return $suite; + } +} + +if (PHPUnit_MAIN_METHOD == 'Orm_Entity_AllTests::main') { + AllTests::main(); +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Entity/ConstructorTest.php b/tests/Doctrine/Tests/ORM/Entity/ConstructorTest.php new file mode 100644 index 000000000..a29e6c30c --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Entity/ConstructorTest.php @@ -0,0 +1,28 @@ +assertEquals("romanb", $entity->username); + } +} + +class ConstructorTestEntity1 +{ + private $id; + public $username; + + public function __construct($username = null) + { + if ($username !== null) { + $this->username = $username; + } + } +} + diff --git a/tests/Orm/EntityManagerTest.php b/tests/Doctrine/Tests/ORM/EntityManagerTest.php similarity index 68% rename from tests/Orm/EntityManagerTest.php rename to tests/Doctrine/Tests/ORM/EntityManagerTest.php index ed05be45d..97d099dbf 100644 --- a/tests/Orm/EntityManagerTest.php +++ b/tests/Doctrine/Tests/ORM/EntityManagerTest.php @@ -1,12 +1,13 @@ _em->setFlushMode('foobar'); $this->fail("Setting invalid flushmode did not trigger exception."); - } catch (Doctrine_ORM_Exceptions_EntityManagerException $expected) {} + } catch (\Doctrine\ORM\Exceptions\EntityManagerException $expected) {} $this->_em->setFlushMode($prev); } } \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/EntityPersisterTest.php b/tests/Doctrine/Tests/ORM/EntityPersisterTest.php new file mode 100644 index 000000000..e06c8f582 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/EntityPersisterTest.php @@ -0,0 +1,87 @@ +_connMock = new ConnectionMock(array()); + $this->_emMock = EntityManagerMock::create($this->_connMock, 'persisterMockEM'); + $this->_uowMock = new UnitOfWorkMock($this->_emMock); + $this->_emMock->setUnitOfWork($this->_uowMock); + $this->_idGenMock = new SequenceMock($this->_emMock); + $this->_emMock->setIdGenerator('Doctrine\Tests\Models\Forum\ForumUser', $this->_idGenMock); + + $this->_emMock->activate(); + } + + public function testSimpleInsert() { + $userPersister = new \Doctrine\ORM\Persisters\StandardEntityPersister( + $this->_emMock, $this->_emMock->getClassMetadata("Doctrine\Tests\Models\Forum\ForumUser")); + $avatarPersister = new \Doctrine\ORM\Persisters\StandardEntityPersister( + $this->_emMock, $this->_emMock->getClassMetadata("Doctrine\Tests\Models\Forum\ForumAvatar")); + + $user = new ForumUser(); + $user->username = "romanb"; + $user->avatar = new ForumAvatar(); + + $this->_uowMock->setDataChangeSet($user, array( + 'username' => array('' => 'romanb'), + 'avatar' => array('' => $user->avatar))); + + + //insert + $avatarPersister->insert($user->avatar); + $inserts = $this->_connMock->getInserts(); + //check + $this->assertEquals(1, count($inserts)); + $this->assertTrue(isset($inserts['forum_avatars'])); + $this->assertEquals(1, count($inserts['forum_avatars'])); + $this->assertEquals(null, $user->avatar->id); + $user->avatar->id = 0; // Fake that we got an id + + //insert + $userPersister->insert($user); + $inserts = $this->_connMock->getInserts(); + //check + $this->assertEquals(2, count($inserts)); + $this->assertEquals(null, $user->id); + $this->assertTrue(isset($inserts['forum_users'])); + $this->assertEquals(1, count($inserts['forum_users'])); + $this->assertEquals(3, count($inserts['forum_users'][0])); + //username column + $this->assertTrue(isset($inserts['forum_users'][0]['username'])); + $this->assertEquals('romanb', $inserts['forum_users'][0]['username']); + //avatar_id join column + $this->assertTrue(isset($inserts['forum_users'][0]['avatar_id'])); + $this->assertEquals(0, $inserts['forum_users'][0]['avatar_id']); + //dtype discriminator column + $this->assertTrue(isset($inserts['forum_users'][0]['dtype'])); + $this->assertEquals('user', $inserts['forum_users'][0]['dtype']); + } + +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Functional/AllTests.php b/tests/Doctrine/Tests/ORM/Functional/AllTests.php new file mode 100644 index 000000000..10c8bcc4f --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/AllTests.php @@ -0,0 +1,32 @@ +addTestSuite('Doctrine\Tests\ORM\Functional\BasicCRUDTest'); + + //$suite->addTest(Orm_Functional_Ticket_AllTests::suite()); + + return $suite; + } +} + +if (PHPUnit_MAIN_METHOD == 'Orm_Functional_AllTests::main') { + AllTests::main(); +} \ No newline at end of file diff --git a/tests/Orm/Functional/BasicCRUDTest.php b/tests/Doctrine/Tests/ORM/Functional/BasicCRUDTest.php similarity index 70% rename from tests/Orm/Functional/BasicCRUDTest.php rename to tests/Doctrine/Tests/ORM/Functional/BasicCRUDTest.php index 73351f350..1613a50fc 100644 --- a/tests/Orm/Functional/BasicCRUDTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/BasicCRUDTest.php @@ -1,21 +1,27 @@ _em; - $exporter = new Doctrine_ORM_Export_ClassExporter($this->_em); + $exporter = new ClassExporter($this->_em); $exporter->exportClasses(array( - $this->_em->getClassMetadata('CmsUser'), - $this->_em->getClassMetadata('CmsPhonenumber') + $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), + $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber') )); // Create @@ -26,7 +32,7 @@ class Orm_Functional_BasicCRUDTest extends Doctrine_OrmFunctionalTestCase { $this->assertTrue($em->contains($user)); // Read - $user2 = $em->find('CmsUser', $user->id); + $user2 = $em->find('Doctrine\Tests\Models\CMS\CmsUser', $user->id); $this->assertTrue($user === $user2); // Add a phonenumber diff --git a/tests/Orm/Functional/Ticket/1Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/1Test.php similarity index 100% rename from tests/Orm/Functional/Ticket/1Test.php rename to tests/Doctrine/Tests/ORM/Functional/Ticket/1Test.php diff --git a/tests/Orm/Functional/Ticket/AllTests.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/AllTests.php similarity index 100% rename from tests/Orm/Functional/Ticket/AllTests.php rename to tests/Doctrine/Tests/ORM/Functional/Ticket/AllTests.php diff --git a/tests/Doctrine/Tests/ORM/Hydration/AllTests.php b/tests/Doctrine/Tests/ORM/Hydration/AllTests.php new file mode 100644 index 000000000..bad26e993 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Hydration/AllTests.php @@ -0,0 +1,34 @@ +addTestSuite('Doctrine\Tests\ORM\Hydration\ObjectHydratorTest'); + $suite->addTestSuite('Doctrine\Tests\ORM\Hydration\ArrayHydratorTest'); + $suite->addTestSuite('Doctrine\Tests\ORM\Hydration\ScalarHydratorTest'); + $suite->addTestSuite('Doctrine\Tests\ORM\Hydration\SingleScalarHydratorTest'); + + return $suite; + } +} + +if (PHPUnit_MAIN_METHOD == 'Orm_Hydration_AllTests::main') { + AllTests::main(); +} diff --git a/tests/Orm/Hydration/ArrayHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/ArrayHydratorTest.php similarity index 83% rename from tests/Orm/Hydration/ArrayHydratorTest.php rename to tests/Doctrine/Tests/ORM/Hydration/ArrayHydratorTest.php index 6fc35a82b..2e5f9ac3e 100644 --- a/tests/Orm/Hydration/ArrayHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/ArrayHydratorTest.php @@ -1,23 +1,27 @@ array( - 'metadata' => $this->_em->getClassMetadata('CmsUser'), + 'metadata' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), 'parent' => null, 'relation' => null, 'map' => null @@ -42,8 +46,8 @@ class Orm_Hydration_ArrayHydratorTest extends Orm_Hydration_HydrationTest ); - $stmt = new Doctrine_HydratorMockStatement($resultSet); - $hydrator = new Doctrine_ORM_Internal_Hydration_ArrayHydrator($this->_em); + $stmt = new HydratorMockStatement($resultSet); + $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $this->_createParserResult( $queryComponents, $tableAliasMap)); @@ -68,16 +72,16 @@ class Orm_Hydration_ArrayHydratorTest extends Orm_Hydration_HydrationTest // Faked query components $queryComponents = array( 'u' => array( - 'metadata' => $this->_em->getClassMetadata('CmsUser'), + 'metadata' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), 'parent' => null, 'relation' => null, 'map' => null, 'agg' => array('0' => 'nameUpper') ), 'p' => array( - 'metadata' => $this->_em->getClassMetadata('CmsPhonenumber'), + 'metadata' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber'), 'parent' => 'u', - 'relation' => $this->_em->getClassMetadata('CmsUser')->getAssociationMapping('phonenumbers'), + 'relation' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser')->getAssociationMapping('phonenumbers'), 'map' => null ) ); @@ -111,8 +115,8 @@ class Orm_Hydration_ArrayHydratorTest extends Orm_Hydration_HydrationTest ) ); - $stmt = new Doctrine_HydratorMockStatement($resultSet); - $hydrator = new Doctrine_ORM_Internal_Hydration_ArrayHydrator($this->_em); + $stmt = new HydratorMockStatement($resultSet); + $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $this->_createParserResult( $queryComponents, $tableAliasMap, true)); @@ -146,15 +150,15 @@ class Orm_Hydration_ArrayHydratorTest extends Orm_Hydration_HydrationTest // Faked query components $queryComponents = array( 'u' => array( - 'metadata' => $this->_em->getClassMetadata('CmsUser'), + 'metadata' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), 'parent' => null, 'relation' => null, 'map' => null ), 'p' => array( - 'metadata' => $this->_em->getClassMetadata('CmsPhonenumber'), + 'metadata' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber'), 'parent' => 'u', - 'relation' => $this->_em->getClassMetadata('CmsUser')->getAssociationMapping('phonenumbers'), + 'relation' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser')->getAssociationMapping('phonenumbers'), 'map' => null, 'agg' => array('0' => 'numPhones') ) @@ -181,8 +185,8 @@ class Orm_Hydration_ArrayHydratorTest extends Orm_Hydration_HydrationTest ) ); - $stmt = new Doctrine_HydratorMockStatement($resultSet); - $hydrator = new Doctrine_ORM_Internal_Hydration_ArrayHydrator($this->_em); + $stmt = new HydratorMockStatement($resultSet); + $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $this->_createParserResult( $queryComponents, $tableAliasMap, true)); @@ -209,16 +213,16 @@ class Orm_Hydration_ArrayHydratorTest extends Orm_Hydration_HydrationTest // Faked query components $queryComponents = array( 'u' => array( - 'metadata' => $this->_em->getClassMetadata('CmsUser'), + 'metadata' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), 'parent' => null, 'relation' => null, 'agg' => array('0' => 'nameUpper'), 'map' => 'id' ), 'p' => array( - 'metadata' => $this->_em->getClassMetadata('CmsPhonenumber'), + 'metadata' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber'), 'parent' => 'u', - 'relation' => $this->_em->getClassMetadata('CmsUser')->getAssociationMapping('phonenumbers'), + 'relation' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser')->getAssociationMapping('phonenumbers'), 'map' => 'phonenumber' ) ); @@ -253,8 +257,8 @@ class Orm_Hydration_ArrayHydratorTest extends Orm_Hydration_HydrationTest ); - $stmt = new Doctrine_HydratorMockStatement($resultSet); - $hydrator = new Doctrine_ORM_Internal_Hydration_ArrayHydrator($this->_em); + $stmt = new HydratorMockStatement($resultSet); + $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $this->_createParserResult( $queryComponents, $tableAliasMap, true)); @@ -293,22 +297,22 @@ class Orm_Hydration_ArrayHydratorTest extends Orm_Hydration_HydrationTest // Faked query components $queryComponents = array( 'u' => array( - 'metadata' => $this->_em->getClassMetadata('CmsUser'), + 'metadata' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), 'parent' => null, 'relation' => null, 'map' => null, 'agg' => array('0' => 'nameUpper') ), 'p' => array( - 'metadata' => $this->_em->getClassMetadata('CmsPhonenumber'), + 'metadata' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber'), 'parent' => 'u', - 'relation' => $this->_em->getClassMetadata('CmsUser')->getAssociationMapping('phonenumbers'), + 'relation' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser')->getAssociationMapping('phonenumbers'), 'map' => null ), 'a' => array( - 'metadata' => $this->_em->getClassMetadata('CmsArticle'), + 'metadata' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsArticle'), 'parent' => 'u', - 'relation' => $this->_em->getClassMetadata('CmsUser')->getAssociationMapping('articles'), + 'relation' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser')->getAssociationMapping('articles'), 'map' => null ), ); @@ -373,8 +377,8 @@ class Orm_Hydration_ArrayHydratorTest extends Orm_Hydration_HydrationTest ), ); - $stmt = new Doctrine_HydratorMockStatement($resultSet); - $hydrator = new Doctrine_ORM_Internal_Hydration_ArrayHydrator($this->_em); + $stmt = new HydratorMockStatement($resultSet); + $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $this->_createParserResult( $queryComponents, $tableAliasMap, true)); @@ -422,28 +426,28 @@ class Orm_Hydration_ArrayHydratorTest extends Orm_Hydration_HydrationTest // Faked query components $queryComponents = array( 'u' => array( - 'metadata' => $this->_em->getClassMetadata('CmsUser'), + 'metadata' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), 'parent' => null, 'relation' => null, 'map' => null, 'agg' => array('0' => 'nameUpper') ), 'p' => array( - 'metadata' => $this->_em->getClassMetadata('CmsPhonenumber'), + 'metadata' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber'), 'parent' => 'u', - 'relation' => $this->_em->getClassMetadata('CmsUser')->getAssociationMapping('phonenumbers'), + 'relation' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser')->getAssociationMapping('phonenumbers'), 'map' => null ), 'a' => array( - 'metadata' => $this->_em->getClassMetadata('CmsArticle'), + 'metadata' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsArticle'), 'parent' => 'u', - 'relation' => $this->_em->getClassMetadata('CmsUser')->getAssociationMapping('articles'), + 'relation' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser')->getAssociationMapping('articles'), 'map' => null ), 'c' => array( - 'metadata' => $this->_em->getClassMetadata('CmsComment'), + 'metadata' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsComment'), 'parent' => 'a', - 'relation' => $this->_em->getClassMetadata('CmsArticle')->getAssociationMapping('comments'), + 'relation' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsArticle')->getAssociationMapping('comments'), 'map' => null ), ); @@ -521,8 +525,8 @@ class Orm_Hydration_ArrayHydratorTest extends Orm_Hydration_HydrationTest ), ); - $stmt = new Doctrine_HydratorMockStatement($resultSet); - $hydrator = new Doctrine_ORM_Internal_Hydration_ArrayHydrator($this->_em); + $stmt = new HydratorMockStatement($resultSet); + $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $this->_createParserResult( $queryComponents, $tableAliasMap, true)); @@ -570,7 +574,7 @@ class Orm_Hydration_ArrayHydratorTest extends Orm_Hydration_HydrationTest * * DQL: * select c.id, c.position, c.name, b.id, b.position - * from ForumCategory c inner join c.boards b + * from \Doctrine\Tests\Models\Forum\ForumCategory c inner join c.boards b * order by c.position asc, b.position asc * * Checks whether the boards are correctly assigned to the categories. @@ -588,15 +592,15 @@ class Orm_Hydration_ArrayHydratorTest extends Orm_Hydration_HydrationTest // Faked query components $queryComponents = array( 'c' => array( - 'metadata' => $this->_em->getClassMetadata('ForumCategory'), + 'metadata' => $this->_em->getClassMetadata('Doctrine\Tests\Models\Forum\ForumCategory'), 'parent' => null, 'relation' => null, 'map' => null ), 'b' => array( - 'metadata' => $this->_em->getClassMetadata('ForumBoard'), + 'metadata' => $this->_em->getClassMetadata('Doctrine\Tests\Models\Forum\ForumBoard'), 'parent' => 'c', - 'relation' => $this->_em->getClassMetadata('ForumCategory')->getAssociationMapping('boards'), + 'relation' => $this->_em->getClassMetadata('Doctrine\Tests\Models\Forum\ForumCategory')->getAssociationMapping('boards'), 'map' => null ), ); @@ -643,8 +647,8 @@ class Orm_Hydration_ArrayHydratorTest extends Orm_Hydration_HydrationTest ) ); - $stmt = new Doctrine_HydratorMockStatement($resultSet); - $hydrator = new Doctrine_ORM_Internal_Hydration_ArrayHydrator($this->_em); + $stmt = new HydratorMockStatement($resultSet); + $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $this->_createParserResult( $queryComponents, $tableAliasMap)); @@ -663,7 +667,7 @@ class Orm_Hydration_ArrayHydratorTest extends Orm_Hydration_HydrationTest // Faked query components $queryComponents = array( 'u' => array( - 'metadata' => $this->_em->getClassMetadata('CmsUser'), + 'metadata' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), 'parent' => null, 'relation' => null, 'map' => null @@ -688,8 +692,8 @@ class Orm_Hydration_ArrayHydratorTest extends Orm_Hydration_HydrationTest ); - $stmt = new Doctrine_HydratorMockStatement($resultSet); - $hydrator = new Doctrine_ORM_Internal_Hydration_ArrayHydrator($this->_em); + $stmt = new HydratorMockStatement($resultSet); + $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); $iterableResult = $hydrator->iterate($stmt, $this->_createParserResult( $queryComponents, $tableAliasMap)); diff --git a/tests/Orm/Hydration/HydrationTest.php b/tests/Doctrine/Tests/ORM/Hydration/HydrationTest.php similarity index 71% rename from tests/Orm/Hydration/HydrationTest.php rename to tests/Doctrine/Tests/ORM/Hydration/HydrationTest.php index b770df679..624007205 100644 --- a/tests/Orm/Hydration/HydrationTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/HydrationTest.php @@ -1,14 +1,15 @@ setQueryComponents($queryComponents); $parserResult->setTableToClassAliasMap($tableToClassAliasMap); $parserResult->setMixedQuery($isMixedQuery); diff --git a/tests/Orm/Hydration/ObjectHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/ObjectHydratorTest.php similarity index 76% rename from tests/Orm/Hydration/ObjectHydratorTest.php rename to tests/Doctrine/Tests/ORM/Hydration/ObjectHydratorTest.php index 899dbfcc2..8e325de18 100644 --- a/tests/Orm/Hydration/ObjectHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/ObjectHydratorTest.php @@ -1,23 +1,27 @@ array( - 'metadata' => $this->_em->getClassMetadata('CmsUser'), + 'metadata' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), 'parent' => null, 'relation' => null, 'map' => null @@ -42,16 +46,16 @@ class Orm_Hydration_ObjectHydratorTest extends Orm_Hydration_HydrationTest ); - $stmt = new Doctrine_HydratorMockStatement($resultSet); - $hydrator = new Doctrine_ORM_Internal_Hydration_ObjectHydrator($this->_em); + $stmt = new HydratorMockStatement($resultSet); + $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $this->_createParserResult( $queryComponents, $tableAliasMap)); $this->assertEquals(2, count($result)); - $this->assertTrue($result instanceof Doctrine_ORM_Collection); - $this->assertTrue($result[0] instanceof CmsUser); - $this->assertTrue($result[1] instanceof CmsUser); + $this->assertTrue($result instanceof \Doctrine\ORM\Collection); + $this->assertTrue($result[0] instanceof \Doctrine\Tests\Models\CMS\CmsUser); + $this->assertTrue($result[1] instanceof \Doctrine\Tests\Models\CMS\CmsUser); $this->assertEquals(1, $result[0]->id); $this->assertEquals('romanb', $result[0]->name); $this->assertEquals(2, $result[1]->id); @@ -70,16 +74,16 @@ class Orm_Hydration_ObjectHydratorTest extends Orm_Hydration_HydrationTest // Faked query components $queryComponents = array( 'u' => array( - 'metadata' => $this->_em->getClassMetadata('CmsUser'), + 'metadata' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), 'parent' => null, 'relation' => null, 'map' => null, 'agg' => array('0' => 'nameUpper') ), 'p' => array( - 'metadata' => $this->_em->getClassMetadata('CmsPhonenumber'), + 'metadata' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber'), 'parent' => 'u', - 'relation' => $this->_em->getClassMetadata('CmsUser')->getAssociationMapping('phonenumbers'), + 'relation' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser')->getAssociationMapping('phonenumbers'), 'map' => null ) ); @@ -113,8 +117,8 @@ class Orm_Hydration_ObjectHydratorTest extends Orm_Hydration_HydrationTest ) ); - $stmt = new Doctrine_HydratorMockStatement($resultSet); - $hydrator = new Doctrine_ORM_Internal_Hydration_ObjectHydrator($this->_em); + $stmt = new HydratorMockStatement($resultSet); + $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $this->_createParserResult( $queryComponents, $tableAliasMap, true)); @@ -124,12 +128,12 @@ class Orm_Hydration_ObjectHydratorTest extends Orm_Hydration_HydrationTest $this->assertTrue(is_array($result[0])); $this->assertTrue(is_array($result[1])); - $this->assertTrue($result[0][0] instanceof CmsUser); - $this->assertTrue($result[0][0]->phonenumbers instanceof Doctrine_ORM_Collection); - $this->assertTrue($result[0][0]->phonenumbers[0] instanceof CmsPhonenumber); - $this->assertTrue($result[0][0]->phonenumbers[1] instanceof CmsPhonenumber); - $this->assertTrue($result[1][0] instanceof CmsUser); - $this->assertTrue($result[1][0]->phonenumbers instanceof Doctrine_ORM_Collection); + $this->assertTrue($result[0][0] instanceof \Doctrine\Tests\Models\CMS\CmsUser); + $this->assertTrue($result[0][0]->phonenumbers instanceof \Doctrine\ORM\Collection); + $this->assertTrue($result[0][0]->phonenumbers[0] instanceof \Doctrine\Tests\Models\CMS\CmsPhonenumber); + $this->assertTrue($result[0][0]->phonenumbers[1] instanceof \Doctrine\Tests\Models\CMS\CmsPhonenumber); + $this->assertTrue($result[1][0] instanceof \Doctrine\Tests\Models\CMS\CmsUser); + $this->assertTrue($result[1][0]->phonenumbers instanceof \Doctrine\ORM\Collection); // first user => 2 phonenumbers $this->assertEquals(2, count($result[0][0]->phonenumbers)); @@ -155,15 +159,15 @@ class Orm_Hydration_ObjectHydratorTest extends Orm_Hydration_HydrationTest // Faked query components $queryComponents = array( 'u' => array( - 'metadata' => $this->_em->getClassMetadata('CmsUser'), + 'metadata' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), 'parent' => null, 'relation' => null, 'map' => null ), 'p' => array( - 'metadata' => $this->_em->getClassMetadata('CmsPhonenumber'), + 'metadata' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber'), 'parent' => 'u', - 'relation' => $this->_em->getClassMetadata('CmsUser')->getAssociationMapping('phonenumbers'), + 'relation' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser')->getAssociationMapping('phonenumbers'), 'map' => null, 'agg' => array('0' => 'numPhones') ) @@ -190,8 +194,8 @@ class Orm_Hydration_ObjectHydratorTest extends Orm_Hydration_HydrationTest ) ); - $stmt = new Doctrine_HydratorMockStatement($resultSet); - $hydrator = new Doctrine_ORM_Internal_Hydration_ObjectHydrator($this->_em); + $stmt = new HydratorMockStatement($resultSet); + $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $this->_createParserResult( $queryComponents, $tableAliasMap, true)); @@ -204,8 +208,8 @@ class Orm_Hydration_ObjectHydratorTest extends Orm_Hydration_HydrationTest $this->assertEquals(2, $result[0]['numPhones']); // second user => 1 phonenumber $this->assertEquals(1, $result[1]['numPhones']); - $this->assertTrue($result[0][0] instanceof CmsUser); - $this->assertTrue($result[1][0] instanceof CmsUser); + $this->assertTrue($result[0][0] instanceof \Doctrine\Tests\Models\CMS\CmsUser); + $this->assertTrue($result[1][0] instanceof \Doctrine\Tests\Models\CMS\CmsUser); } /** @@ -220,16 +224,16 @@ class Orm_Hydration_ObjectHydratorTest extends Orm_Hydration_HydrationTest // Faked query components $queryComponents = array( 'u' => array( - 'metadata' => $this->_em->getClassMetadata('CmsUser'), + 'metadata' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), 'parent' => null, 'relation' => null, 'agg' => array('0' => 'nameUpper'), 'map' => 'id' ), 'p' => array( - 'metadata' => $this->_em->getClassMetadata('CmsPhonenumber'), + 'metadata' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber'), 'parent' => 'u', - 'relation' => $this->_em->getClassMetadata('CmsUser')->getAssociationMapping('phonenumbers'), + 'relation' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser')->getAssociationMapping('phonenumbers'), 'map' => 'phonenumber' ) ); @@ -264,8 +268,8 @@ class Orm_Hydration_ObjectHydratorTest extends Orm_Hydration_HydrationTest ); - $stmt = new Doctrine_HydratorMockStatement($resultSet); - $hydrator = new Doctrine_ORM_Internal_Hydration_ObjectHydrator($this->_em); + $stmt = new HydratorMockStatement($resultSet); + $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $this->_createParserResult( $queryComponents, $tableAliasMap, true)); @@ -279,9 +283,9 @@ class Orm_Hydration_ObjectHydratorTest extends Orm_Hydration_HydrationTest $this->assertEquals('ROMANB', $result[0]['nameUpper']); $this->assertEquals('JWAGE', $result[1]['nameUpper']); - $this->assertTrue($result[0]['1'] instanceof CmsUser); - $this->assertTrue($result[1]['2'] instanceof CmsUser); - $this->assertTrue($result[0]['1']->phonenumbers instanceof Doctrine_ORM_Collection); + $this->assertTrue($result[0]['1'] instanceof \Doctrine\Tests\Models\CMS\CmsUser); + $this->assertTrue($result[1]['2'] instanceof \Doctrine\Tests\Models\CMS\CmsUser); + $this->assertTrue($result[0]['1']->phonenumbers instanceof \Doctrine\ORM\Collection); // first user => 2 phonenumbers. notice the custom indexing by user id $this->assertEquals(2, count($result[0]['1']->phonenumbers)); // second user => 1 phonenumber. notice the custom indexing by user id @@ -308,22 +312,22 @@ class Orm_Hydration_ObjectHydratorTest extends Orm_Hydration_HydrationTest // Faked query components $queryComponents = array( 'u' => array( - 'metadata' => $this->_em->getClassMetadata('CmsUser'), + 'metadata' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), 'parent' => null, 'relation' => null, 'map' => null, 'agg' => array('0' => 'nameUpper') ), 'p' => array( - 'metadata' => $this->_em->getClassMetadata('CmsPhonenumber'), + 'metadata' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber'), 'parent' => 'u', - 'relation' => $this->_em->getClassMetadata('CmsUser')->getAssociationMapping('phonenumbers'), + 'relation' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser')->getAssociationMapping('phonenumbers'), 'map' => null ), 'a' => array( - 'metadata' => $this->_em->getClassMetadata('CmsArticle'), + 'metadata' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsArticle'), 'parent' => 'u', - 'relation' => $this->_em->getClassMetadata('CmsUser')->getAssociationMapping('articles'), + 'relation' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser')->getAssociationMapping('articles'), 'map' => null ), ); @@ -388,8 +392,8 @@ class Orm_Hydration_ObjectHydratorTest extends Orm_Hydration_HydrationTest ), ); - $stmt = new Doctrine_HydratorMockStatement($resultSet); - $hydrator = new Doctrine_ORM_Internal_Hydration_ObjectHydrator($this->_em); + $stmt = new HydratorMockStatement($resultSet); + $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $this->_createParserResult( $queryComponents, $tableAliasMap, true)); @@ -399,18 +403,18 @@ class Orm_Hydration_ObjectHydratorTest extends Orm_Hydration_HydrationTest $this->assertTrue(is_array($result[0])); $this->assertTrue(is_array($result[1])); - $this->assertTrue($result[0][0] instanceof CmsUser); - $this->assertTrue($result[0][0]->phonenumbers instanceof Doctrine_ORM_Collection); - $this->assertTrue($result[0][0]->phonenumbers[0] instanceof CmsPhonenumber); - $this->assertTrue($result[0][0]->phonenumbers[1] instanceof CmsPhonenumber); - $this->assertTrue($result[0][0]->articles instanceof Doctrine_ORM_Collection); - $this->assertTrue($result[0][0]->articles[0] instanceof CmsArticle); - $this->assertTrue($result[0][0]->articles[1] instanceof CmsArticle); - $this->assertTrue($result[1][0] instanceof CmsUser); - $this->assertTrue($result[1][0]->phonenumbers instanceof Doctrine_ORM_Collection); - $this->assertTrue($result[1][0]->phonenumbers[0] instanceof CmsPhonenumber); - $this->assertTrue($result[1][0]->articles[0] instanceof CmsArticle); - $this->assertTrue($result[1][0]->articles[1] instanceof CmsArticle); + $this->assertTrue($result[0][0] instanceof \Doctrine\Tests\Models\CMS\CmsUser); + $this->assertTrue($result[0][0]->phonenumbers instanceof \Doctrine\ORM\Collection); + $this->assertTrue($result[0][0]->phonenumbers[0] instanceof \Doctrine\Tests\Models\CMS\CmsPhonenumber); + $this->assertTrue($result[0][0]->phonenumbers[1] instanceof \Doctrine\Tests\Models\CMS\CmsPhonenumber); + $this->assertTrue($result[0][0]->articles instanceof \Doctrine\ORM\Collection); + $this->assertTrue($result[0][0]->articles[0] instanceof \Doctrine\Tests\Models\CMS\CmsArticle); + $this->assertTrue($result[0][0]->articles[1] instanceof \Doctrine\Tests\Models\CMS\CmsArticle); + $this->assertTrue($result[1][0] instanceof \Doctrine\Tests\Models\CMS\CmsUser); + $this->assertTrue($result[1][0]->phonenumbers instanceof \Doctrine\ORM\Collection); + $this->assertTrue($result[1][0]->phonenumbers[0] instanceof \Doctrine\Tests\Models\CMS\CmsPhonenumber); + $this->assertTrue($result[1][0]->articles[0] instanceof \Doctrine\Tests\Models\CMS\CmsArticle); + $this->assertTrue($result[1][0]->articles[1] instanceof \Doctrine\Tests\Models\CMS\CmsArticle); } /** @@ -433,28 +437,28 @@ class Orm_Hydration_ObjectHydratorTest extends Orm_Hydration_HydrationTest // Faked query components $queryComponents = array( 'u' => array( - 'metadata' => $this->_em->getClassMetadata('CmsUser'), + 'metadata' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), 'parent' => null, 'relation' => null, 'map' => null, 'agg' => array('0' => 'nameUpper') ), 'p' => array( - 'metadata' => $this->_em->getClassMetadata('CmsPhonenumber'), + 'metadata' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber'), 'parent' => 'u', - 'relation' => $this->_em->getClassMetadata('CmsUser')->getAssociationMapping('phonenumbers'), + 'relation' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser')->getAssociationMapping('phonenumbers'), 'map' => null ), 'a' => array( - 'metadata' => $this->_em->getClassMetadata('CmsArticle'), + 'metadata' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsArticle'), 'parent' => 'u', - 'relation' => $this->_em->getClassMetadata('CmsUser')->getAssociationMapping('articles'), + 'relation' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser')->getAssociationMapping('articles'), 'map' => null ), 'c' => array( - 'metadata' => $this->_em->getClassMetadata('CmsComment'), + 'metadata' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsComment'), 'parent' => 'a', - 'relation' => $this->_em->getClassMetadata('CmsArticle')->getAssociationMapping('comments'), + 'relation' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsArticle')->getAssociationMapping('comments'), 'map' => null ), ); @@ -532,8 +536,8 @@ class Orm_Hydration_ObjectHydratorTest extends Orm_Hydration_HydrationTest ), ); - $stmt = new Doctrine_HydratorMockStatement($resultSet); - $hydrator = new Doctrine_ORM_Internal_Hydration_ObjectHydrator($this->_em); + $stmt = new HydratorMockStatement($resultSet); + $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $this->_createParserResult( $queryComponents, $tableAliasMap, true)); @@ -543,29 +547,29 @@ class Orm_Hydration_ObjectHydratorTest extends Orm_Hydration_HydrationTest $this->assertTrue(is_array($result[0])); $this->assertTrue(is_array($result[1])); - $this->assertTrue($result[0][0] instanceof CmsUser); - $this->assertTrue($result[1][0] instanceof CmsUser); + $this->assertTrue($result[0][0] instanceof \Doctrine\Tests\Models\CMS\CmsUser); + $this->assertTrue($result[1][0] instanceof \Doctrine\Tests\Models\CMS\CmsUser); // phonenumbers - $this->assertTrue($result[0][0]->phonenumbers instanceof Doctrine_ORM_Collection); - $this->assertTrue($result[0][0]->phonenumbers[0] instanceof CmsPhonenumber); - $this->assertTrue($result[0][0]->phonenumbers[1] instanceof CmsPhonenumber); - $this->assertTrue($result[1][0]->phonenumbers instanceof Doctrine_ORM_Collection); - $this->assertTrue($result[1][0]->phonenumbers[0] instanceof CmsPhonenumber); + $this->assertTrue($result[0][0]->phonenumbers instanceof \Doctrine\ORM\Collection); + $this->assertTrue($result[0][0]->phonenumbers[0] instanceof \Doctrine\Tests\Models\CMS\CmsPhonenumber); + $this->assertTrue($result[0][0]->phonenumbers[1] instanceof \Doctrine\Tests\Models\CMS\CmsPhonenumber); + $this->assertTrue($result[1][0]->phonenumbers instanceof \Doctrine\ORM\Collection); + $this->assertTrue($result[1][0]->phonenumbers[0] instanceof \Doctrine\Tests\Models\CMS\CmsPhonenumber); // articles - $this->assertTrue($result[0][0]->articles instanceof Doctrine_ORM_Collection); - $this->assertTrue($result[0][0]->articles[0] instanceof CmsArticle); - $this->assertTrue($result[0][0]->articles[1] instanceof CmsArticle); - $this->assertTrue($result[1][0]->articles[0] instanceof CmsArticle); - $this->assertTrue($result[1][0]->articles[1] instanceof CmsArticle); + $this->assertTrue($result[0][0]->articles instanceof \Doctrine\ORM\Collection); + $this->assertTrue($result[0][0]->articles[0] instanceof \Doctrine\Tests\Models\CMS\CmsArticle); + $this->assertTrue($result[0][0]->articles[1] instanceof \Doctrine\Tests\Models\CMS\CmsArticle); + $this->assertTrue($result[1][0]->articles[0] instanceof \Doctrine\Tests\Models\CMS\CmsArticle); + $this->assertTrue($result[1][0]->articles[1] instanceof \Doctrine\Tests\Models\CMS\CmsArticle); // article comments - $this->assertTrue($result[0][0]->articles[0]->comments instanceof Doctrine_ORM_Collection); - $this->assertTrue($result[0][0]->articles[0]->comments[0] instanceof CmsComment); + $this->assertTrue($result[0][0]->articles[0]->comments instanceof \Doctrine\ORM\Collection); + $this->assertTrue($result[0][0]->articles[0]->comments[0] instanceof \Doctrine\Tests\Models\CMS\CmsComment); // empty comment collections - $this->assertTrue($result[0][0]->articles[1]->comments instanceof Doctrine_ORM_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_ORM_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_ORM_Collection); + $this->assertTrue($result[1][0]->articles[1]->comments instanceof \Doctrine\ORM\Collection); $this->assertEquals(0, count($result[1][0]->articles[1]->comments)); } @@ -575,7 +579,7 @@ class Orm_Hydration_ObjectHydratorTest extends Orm_Hydration_HydrationTest * * DQL: * select c.id, c.position, c.name, b.id, b.position - * from ForumCategory c inner join c.boards b + * from \Doctrine\Tests\Models\Forum\ForumCategory c inner join c.boards b * order by c.position asc, b.position asc * * Checks whether the boards are correctly assigned to the categories. @@ -593,15 +597,15 @@ class Orm_Hydration_ObjectHydratorTest extends Orm_Hydration_HydrationTest // Faked query components $queryComponents = array( 'c' => array( - 'metadata' => $this->_em->getClassMetadata('ForumCategory'), + 'metadata' => $this->_em->getClassMetadata('Doctrine\Tests\Models\Forum\ForumCategory'), 'parent' => null, 'relation' => null, 'map' => null ), 'b' => array( - 'metadata' => $this->_em->getClassMetadata('ForumBoard'), + 'metadata' => $this->_em->getClassMetadata('Doctrine\Tests\Models\Forum\ForumBoard'), 'parent' => 'c', - 'relation' => $this->_em->getClassMetadata('ForumCategory')->getAssociationMapping('boards'), + 'relation' => $this->_em->getClassMetadata('Doctrine\Tests\Models\Forum\ForumCategory')->getAssociationMapping('boards'), 'map' => null ), ); @@ -648,16 +652,16 @@ class Orm_Hydration_ObjectHydratorTest extends Orm_Hydration_HydrationTest ) ); - $stmt = new Doctrine_HydratorMockStatement($resultSet); - $hydrator = new Doctrine_ORM_Internal_Hydration_ObjectHydrator($this->_em); + $stmt = new HydratorMockStatement($resultSet); + $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $this->_createParserResult( $queryComponents, $tableAliasMap)); $this->assertEquals(2, count($result)); - $this->assertTrue($result instanceof Doctrine_ORM_Collection); - $this->assertTrue($result[0] instanceof ForumCategory); - $this->assertTrue($result[1] instanceof ForumCategory); + $this->assertTrue($result instanceof \Doctrine\ORM\Collection); + $this->assertTrue($result[0] instanceof \Doctrine\Tests\Models\Forum\ForumCategory); + $this->assertTrue($result[1] instanceof \Doctrine\Tests\Models\Forum\ForumCategory); $this->assertEquals(1, $result[0]->getId()); $this->assertEquals(2, $result[1]->getId()); $this->assertTrue(isset($result[0]->boards)); @@ -671,7 +675,7 @@ class Orm_Hydration_ObjectHydratorTest extends Orm_Hydration_HydrationTest // Faked query components $queryComponents = array( 'u' => array( - 'metadata' => $this->_em->getClassMetadata('CmsUser'), + 'metadata' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), 'parent' => null, 'relation' => null, 'map' => null @@ -696,8 +700,8 @@ class Orm_Hydration_ObjectHydratorTest extends Orm_Hydration_HydrationTest ); - $stmt = new Doctrine_HydratorMockStatement($resultSet); - $hydrator = new Doctrine_ORM_Internal_Hydration_ObjectHydrator($this->_em); + $stmt = new HydratorMockStatement($resultSet); + $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); $iterableResult = $hydrator->iterate($stmt, $this->_createParserResult( $queryComponents, $tableAliasMap)); @@ -705,7 +709,7 @@ class Orm_Hydration_ObjectHydratorTest extends Orm_Hydration_HydrationTest $rowNum = 0; while (($row = $iterableResult->next()) !== false) { $this->assertEquals(1, count($row)); - $this->assertTrue($row[0] instanceof CmsUser); + $this->assertTrue($row[0] instanceof \Doctrine\Tests\Models\CMS\CmsUser); if ($rowNum == 0) { $this->assertEquals(1, $row[0]->id); $this->assertEquals('romanb', $row[0]->name); @@ -731,7 +735,7 @@ class Orm_Hydration_ObjectHydratorTest extends Orm_Hydration_HydrationTest // Faked query components $queryComponents = array( 'u' => array( - 'metadata' => $this->_em->getClassMetadata('CmsUser'), + 'metadata' => $this->_em->getClassMetadata('\Doctrine\Tests\Models\CMS\CmsUser'), 'parent' => null, 'relation' => null, 'map' => null, @@ -740,7 +744,7 @@ class Orm_Hydration_ObjectHydratorTest extends Orm_Hydration_HydrationTest 'p' => array( 'metadata' => $this->_em->getClassMetadata('CmsPhonenumber'), 'parent' => 'u', - 'relation' => $this->_em->getClassMetadata('CmsUser')->getAssociationMapping('phonenumbers'), + 'relation' => $this->_em->getClassMetadata('\Doctrine\Tests\Models\CMS\CmsUser')->getAssociationMapping('phonenumbers'), 'map' => null ) ); diff --git a/tests/Orm/Hydration/ScalarHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/ScalarHydratorTest.php similarity index 74% rename from tests/Orm/Hydration/ScalarHydratorTest.php rename to tests/Doctrine/Tests/ORM/Hydration/ScalarHydratorTest.php index e41bc4abe..3f4c04543 100644 --- a/tests/Orm/Hydration/ScalarHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/ScalarHydratorTest.php @@ -1,13 +1,17 @@ array( - 'metadata' => $this->_em->getClassMetadata('CmsUser'), + 'metadata' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), 'parent' => null, 'relation' => null, 'map' => null @@ -42,8 +46,8 @@ class Orm_Hydration_ScalarHydratorTest extends Orm_Hydration_HydrationTest ); - $stmt = new Doctrine_HydratorMockStatement($resultSet); - $hydrator = new Doctrine_ORM_Internal_Hydration_ScalarHydrator($this->_em); + $stmt = new HydratorMockStatement($resultSet); + $hydrator = new \Doctrine\ORM\Internal\Hydration\ScalarHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $this->_createParserResult( $queryComponents, $tableAliasMap)); diff --git a/tests/Orm/Hydration/SingleScalarHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/SingleScalarHydratorTest.php similarity index 82% rename from tests/Orm/Hydration/SingleScalarHydratorTest.php rename to tests/Doctrine/Tests/ORM/Hydration/SingleScalarHydratorTest.php index 9d51d92bf..d9ff8e318 100644 --- a/tests/Orm/Hydration/SingleScalarHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/SingleScalarHydratorTest.php @@ -1,13 +1,17 @@ array( - 'metadata' => $this->_em->getClassMetadata('CmsUser'), + 'metadata' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), 'parent' => null, 'relation' => null, 'map' => null @@ -69,8 +73,8 @@ class Orm_Hydration_SingleScalarHydratorTest extends Orm_Hydration_HydrationTest 'u' => 'u' ); - $stmt = new Doctrine_HydratorMockStatement($resultSet); - $hydrator = new Doctrine_ORM_Internal_Hydration_SingleScalarHydrator($this->_em); + $stmt = new HydratorMockStatement($resultSet); + $hydrator = new \Doctrine\ORM\Internal\Hydration\SingleScalarHydrator($this->_em); if ($name == 'result1') { $result = $hydrator->hydrateAll($stmt, $this->_createParserResult( @@ -85,7 +89,7 @@ class Orm_Hydration_SingleScalarHydratorTest extends Orm_Hydration_HydrationTest $result = $hydrator->hydrateall($stmt, $this->_createParserResult( $queryComponents, $tableAliasMap)); $this->fail(); - } catch (Doctrine_ORM_Exceptions_HydrationException $ex) {} + } catch (\Doctrine\ORM\Exceptions\HydrationException $ex) {} } } diff --git a/tests/Doctrine/Tests/ORM/Mapping/AllTests.php b/tests/Doctrine/Tests/ORM/Mapping/AllTests.php new file mode 100644 index 000000000..8c32e19e0 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/AllTests.php @@ -0,0 +1,31 @@ +addTestSuite('Doctrine\Tests\ORM\Mapping\ClassMetadataTest'); + $suite->addTestSuite('Doctrine\Tests\ORM\Mapping\ClassMetadataFactoryTest'); + + return $suite; + } +} + +if (PHPUnit_MAIN_METHOD == 'Orm_Mapping_AllTests::main') { + AllTests::main(); +} diff --git a/tests/Orm/Mapping/ClassMetadataFactoryTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php similarity index 69% rename from tests/Orm/Mapping/ClassMetadataFactoryTest.php rename to tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php index 1b93ad84a..1bb89c8b3 100644 --- a/tests/Orm/Mapping/ClassMetadataFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php @@ -4,22 +4,27 @@ * and open the template in the editor. */ -require_once 'lib/DoctrineTestInit.php'; -require_once 'lib/mocks/Doctrine_MetadataDriverMock.php'; +namespace Doctrine\Tests\ORM\Mapping; + +use Doctrine\Tests\Mocks\MetadataDriverMock; +use Doctrine\Tests\Mocks\DatabasePlatformMock; +use Doctrine\ORM\Mapping\ClassMetadata; + +require_once dirname(__FILE__) . '/../../TestInit.php'; /** * Description of ClassMetadataFactoryTest * * @author robo */ -class Orm_Mapping_ClassMetadataFactoryTest extends Doctrine_OrmTestCase { +class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase { public function testGetMetadataForSingleClass() { - $mockPlatform = new Doctrine_DatabasePlatformMock(); - $mockDriver = new Doctrine_MetadataDriverMock(); + $mockPlatform = new DatabasePlatformMock(); + $mockDriver = new MetadataDriverMock(); // Self-made metadata - $cm1 = new Doctrine_ORM_Mapping_ClassMetadata('CMFTest_Entity1'); + $cm1 = new ClassMetadata('Doctrine\Tests\ORM\Mapping\TestEntity1'); // Add a mapped field $cm1->mapField(array('fieldName' => 'name', 'type' => 'varchar')); // and a mapped association @@ -29,7 +34,7 @@ class Orm_Mapping_ClassMetadataFactoryTest extends Doctrine_OrmTestCase { // SUT $cmf = new ClassMetadataFactoryTestSubject($mockDriver, $mockPlatform); - $cmf->setMetadataForClass('CMFTest_Entity1', $cm1); + $cmf->setMetadataForClass('Doctrine\Tests\ORM\Mapping\TestEntity1', $cm1); // Prechecks $this->assertEquals(array(), $cm1->getParentClasses()); @@ -39,7 +44,7 @@ class Orm_Mapping_ClassMetadataFactoryTest extends Doctrine_OrmTestCase { $this->assertEquals('auto', $cm1->getIdGeneratorType()); // Go - $cm1 = $cmf->getMetadataFor('CMFTest_Entity1'); + $cm1 = $cmf->getMetadataFor('Doctrine\Tests\ORM\Mapping\TestEntity1'); $this->assertEquals(array(), $cm1->getParentClasses()); $this->assertTrue($cm1->hasField('name')); @@ -48,12 +53,12 @@ class Orm_Mapping_ClassMetadataFactoryTest extends Doctrine_OrmTestCase { } public function testGetMetadataForClassInHierarchy() { - $mockPlatform = new Doctrine_DatabasePlatformMock(); + $mockPlatform = new DatabasePlatformMock(); $mockPlatform->setPrefersIdentityColumns(true); - $mockDriver = new Doctrine_MetadataDriverMock(); + $mockDriver = new MetadataDriverMock(); // Self-made metadata - $cm1 = new Doctrine_ORM_Mapping_ClassMetadata('CMFTest_Entity1'); + $cm1 = new ClassMetadata('Doctrine\Tests\ORM\Mapping\TestEntity1'); $cm1->setInheritanceType('singleTable'); // Add a mapped field $cm1->mapField(array('fieldName' => 'name', 'type' => 'varchar')); @@ -62,14 +67,14 @@ class Orm_Mapping_ClassMetadataFactoryTest extends Doctrine_OrmTestCase { // and an id generator type $cm1->setIdGeneratorType('auto'); - $cm2 = new Doctrine_ORM_Mapping_ClassMetadata('CMFTest_Entity2'); - $cm3 = new Doctrine_ORM_Mapping_ClassMetadata('CMFTest_Entity3'); + $cm2 = new ClassMetadata('Doctrine\Tests\ORM\Mapping\TestEntity2'); + $cm3 = new ClassMetadata('Doctrine\Tests\ORM\Mapping\TestEntity3'); $cmf = new ClassMetadataFactoryTestSubject($mockDriver, $mockPlatform); // Set self-made metadata - $cmf->setMetadataForClass('CMFTest_Entity1', $cm1); - $cmf->setMetadataForClass('CMFTest_Entity2', $cm2); - $cmf->setMetadataForClass('CMFTest_Entity3', $cm3); + $cmf->setMetadataForClass('Doctrine\Tests\ORM\Mapping\TestEntity1', $cm1); + $cmf->setMetadataForClass('Doctrine\Tests\ORM\Mapping\TestEntity2', $cm2); + $cmf->setMetadataForClass('Doctrine\Tests\ORM\Mapping\TestEntity3', $cm3); // Prechecks $this->assertEquals(array(), $cm1->getParentClasses()); @@ -86,15 +91,15 @@ class Orm_Mapping_ClassMetadataFactoryTest extends Doctrine_OrmTestCase { $this->assertEquals('none', $cm3->getIdGeneratorType()); // Go - $cm3 = $cmf->getMetadataFor('CMFTest_Entity3'); + $cm3 = $cmf->getMetadataFor('Doctrine\Tests\ORM\Mapping\TestEntity3'); // Metadata gathering should start at the root of the hierarchy, from there on downwards - $this->assertEquals(array('CMFTest_Entity1', 'CMFTest_Entity2', 'CMFTest_Entity3'), $cmf->getRequestedClasses()); + $this->assertEquals(array('Doctrine\Tests\ORM\Mapping\TestEntity1', 'Doctrine\Tests\ORM\Mapping\TestEntity2', 'Doctrine\Tests\ORM\Mapping\TestEntity3'), $cmf->getRequestedClasses()); // Parent classes should be assigned by factory - $this->assertEquals(array('CMFTest_Entity2', 'CMFTest_Entity1'), $cm3->getParentClasses()); - $this->assertEquals('CMFTest_Entity1', $cm3->getRootClassName()); - $this->assertEquals('CMFTest_Entity1', $cm2->getRootClassName()); - $this->assertEquals('CMFTest_Entity1', $cm1->getRootClassName()); + $this->assertEquals(array('Doctrine\Tests\ORM\Mapping\TestEntity2', 'Doctrine\Tests\ORM\Mapping\TestEntity1'), $cm3->getParentClasses()); + $this->assertEquals('Doctrine\Tests\ORM\Mapping\TestEntity1', $cm3->getRootClassName()); + $this->assertEquals('Doctrine\Tests\ORM\Mapping\TestEntity1', $cm2->getRootClassName()); + $this->assertEquals('Doctrine\Tests\ORM\Mapping\TestEntity1', $cm1->getRootClassName()); // Inheritance type should be inherited to Entity2 $this->assertEquals('singleTable', $cm2->getInheritanceType()); $this->assertEquals('singleTable', $cm3->getInheritanceType()); @@ -115,7 +120,7 @@ class Orm_Mapping_ClassMetadataFactoryTest extends Doctrine_OrmTestCase { } /* Test subject class with overriden factory method for mocking purposes */ -class ClassMetadataFactoryTestSubject extends Doctrine_ORM_Mapping_ClassMetadataFactory { +class ClassMetadataFactoryTestSubject extends \Doctrine\ORM\Mapping\ClassMetadataFactory { private $_mockMetadata = array(); private $_requestedClasses = array(); /** @override */ @@ -134,10 +139,10 @@ class ClassMetadataFactoryTestSubject extends Doctrine_ORM_Mapping_ClassMetadata /* Test classes */ -class CMFTest_Entity1 { +class TestEntity1 { protected $name; protected $other; } -class CMFTest_Entity2 extends CMFTest_Entity1 {} -class CMFTest_Entity3 extends CMFTest_Entity2 {} +class TestEntity2 extends TestEntity1 {} +class TestEntity3 extends TestEntity2 {} diff --git a/tests/Orm/Mapping/ClassMetadataTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php similarity index 68% rename from tests/Orm/Mapping/ClassMetadataTest.php rename to tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php index 0f79072f0..1c0bb6e64 100644 --- a/tests/Orm/Mapping/ClassMetadataTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php @@ -1,19 +1,21 @@ assertTrue(count($cm->getReflectionProperties()) == 0); - $this->assertTrue($cm->getReflectionClass() instanceof ReflectionClass); - $this->assertEquals('CmsUser', $cm->getClassName()); - $this->assertEquals('CmsUser', $cm->getRootClassName()); + $this->assertTrue($cm->getReflectionClass() instanceof \ReflectionClass); + $this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $cm->getClassName()); + $this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $cm->getRootClassName()); $this->assertEquals(array(), $cm->getSubclasses()); $this->assertEquals(array(), $cm->getParentClasses()); @@ -23,7 +25,7 @@ class Orm_Mapping_ClassMetadataTest extends Doctrine_OrmTestCase $cm->setCustomRepositoryClass("UserRepository"); $cm->setDiscriminatorColumn(array('name' => 'disc', 'type' => 'integer')); $cm->mapOneToOne(array('fieldName' => 'phonenumbers', 'targetEntity' => 'Bar', 'mappedBy' => 'foo')); - $this->assertTrue($cm->getAssociationMapping('phonenumbers') instanceof Doctrine_ORM_Mapping_OneToOneMapping); + $this->assertTrue($cm->getAssociationMapping('phonenumbers') instanceof \Doctrine\ORM\Mapping\OneToOneMapping); $this->assertEquals(1, count($cm->getAssociationMappings())); $serialized = serialize($cm); @@ -31,14 +33,14 @@ class Orm_Mapping_ClassMetadataTest extends Doctrine_OrmTestCase // Check state $this->assertTrue(count($cm->getReflectionProperties()) > 0); - $this->assertTrue($cm->getReflectionClass() instanceof ReflectionClass); - $this->assertEquals('CmsUser', $cm->getClassName()); + $this->assertTrue($cm->getReflectionClass() instanceof \ReflectionClass); + $this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $cm->getClassName()); $this->assertEquals('UserParent', $cm->getRootClassName()); $this->assertEquals(array('One', 'Two', 'Three'), $cm->getSubclasses()); $this->assertEquals(array('UserParent'), $cm->getParentClasses()); $this->assertEquals('UserRepository', $cm->getCustomRepositoryClass()); $this->assertEquals(array('name' => 'disc', 'type' => 'integer'), $cm->getDiscriminatorColumn()); - $this->assertTrue($cm->getAssociationMapping('phonenumbers') instanceof Doctrine_ORM_Mapping_OneToOneMapping); + $this->assertTrue($cm->getAssociationMapping('phonenumbers') instanceof \Doctrine\ORM\Mapping\OneToOneMapping); $this->assertEquals(1, count($cm->getAssociationMappings())); $oneOneMapping = $cm->getAssociationMapping('phonenumbers'); $this->assertEquals('phonenumbers', $oneOneMapping->getSourceFieldName()); diff --git a/tests/Doctrine/Tests/ORM/Performance/AllTests.php b/tests/Doctrine/Tests/ORM/Performance/AllTests.php new file mode 100644 index 000000000..ddf689d21 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Performance/AllTests.php @@ -0,0 +1,30 @@ +addTestSuite('Orm_Performance_xxxTest'); + + return $suite; + } +} + +if (PHPUnit_MAIN_METHOD == 'Orm_Performance_AllTests::main') { + Orm_Performance_AllTests::main(); +} diff --git a/tests/Orm/Query/AllTests.php b/tests/Doctrine/Tests/ORM/Query/AllTests.php old mode 100755 new mode 100644 similarity index 64% rename from tests/Orm/Query/AllTests.php rename to tests/Doctrine/Tests/ORM/Query/AllTests.php index ea6034886..e1ec65e7f --- a/tests/Orm/Query/AllTests.php +++ b/tests/Doctrine/Tests/ORM/Query/AllTests.php @@ -1,11 +1,16 @@ addTestSuite('Orm_Query_IdentifierRecognitionTest'); - $suite->addTestSuite('Orm_Query_SelectSqlGenerationTest'); + $suite->addTestSuite('Doctrine\Tests\ORM\Query\IdentifierRecognitionTest'); + $suite->addTestSuite('Doctrine\Tests\ORM\Query\SelectSqlGenerationTest'); /* $suite->addTestSuite('Orm_Query_LanguageRecognitionTest'); $suite->addTestSuite('Orm_Query_ScannerTest'); @@ -38,5 +43,5 @@ class Orm_Query_AllTests } if (PHPUnit_MAIN_METHOD == 'Orm_Query_AllTests::main') { - Orm_Query_AllTests::main(); + AllTests::main(); } diff --git a/tests/Orm/Query/DeleteSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/DeleteSqlGenerationTest.php old mode 100755 new mode 100644 similarity index 100% rename from tests/Orm/Query/DeleteSqlGenerationTest.php rename to tests/Doctrine/Tests/ORM/Query/DeleteSqlGenerationTest.php diff --git a/tests/Orm/Query/DqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/DqlGenerationTest.php old mode 100755 new mode 100644 similarity index 100% rename from tests/Orm/Query/DqlGenerationTest.php rename to tests/Doctrine/Tests/ORM/Query/DqlGenerationTest.php diff --git a/tests/Orm/Query/IdentifierRecognitionTest.php b/tests/Doctrine/Tests/ORM/Query/IdentifierRecognitionTest.php old mode 100755 new mode 100644 similarity index 68% rename from tests/Orm/Query/IdentifierRecognitionTest.php rename to tests/Doctrine/Tests/ORM/Query/IdentifierRecognitionTest.php index 47166bc68..81899ded4 --- a/tests/Orm/Query/IdentifierRecognitionTest.php +++ b/tests/Doctrine/Tests/ORM/Query/IdentifierRecognitionTest.php @@ -19,7 +19,9 @@ * . */ -require_once 'lib/DoctrineTestInit.php'; +namespace Doctrine\Tests\ORM\Query; + +require_once dirname(__FILE__) . '/../../TestInit.php'; /** * Test case for testing the saving and referencing of query identifiers. @@ -32,7 +34,7 @@ require_once 'lib/DoctrineTestInit.php'; * @since 2.0 * @version $Revision$ */ -class Orm_Query_IdentifierRecognitionTest extends Doctrine_OrmTestCase +class IdentifierRecognitionTest extends \Doctrine\Tests\OrmTestCase { private $_em; @@ -44,12 +46,12 @@ class Orm_Query_IdentifierRecognitionTest extends Doctrine_OrmTestCase public function testSingleAliasDeclarationIsSupported() { $entityManager = $this->_em; - $query = $entityManager->createQuery('SELECT u FROM CmsUser u'); + $query = $entityManager->createQuery('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u'); $parserResult = $query->parse(); $decl = $parserResult->getQueryComponent('u'); - $this->assertTrue($decl['metadata'] instanceof Doctrine_ORM_Mapping_ClassMetadata); + $this->assertTrue($decl['metadata'] instanceof \Doctrine\ORM\Mapping\ClassMetadata); $this->assertEquals(null, $decl['relation']); $this->assertEquals(null, $decl['parent']); $this->assertEquals(null, $decl['scalar']); @@ -59,12 +61,12 @@ class Orm_Query_IdentifierRecognitionTest extends Doctrine_OrmTestCase public function testSingleAliasDeclarationWithIndexByIsSupported() { $entityManager = $this->_em; - $query = $entityManager->createQuery('SELECT u FROM CmsUser u INDEX BY u.id'); + $query = $entityManager->createQuery('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u INDEX BY u.id'); $parserResult = $query->parse(); $decl = $parserResult->getQueryComponent('u'); - $this->assertTrue($decl['metadata'] instanceof Doctrine_ORM_Mapping_ClassMetadata); + $this->assertTrue($decl['metadata'] instanceof \Doctrine\ORM\Mapping\ClassMetadata); $this->assertEquals(null, $decl['relation']); $this->assertEquals(null, $decl['parent']); $this->assertEquals(null, $decl['scalar']); @@ -74,12 +76,12 @@ class Orm_Query_IdentifierRecognitionTest extends Doctrine_OrmTestCase public function testQueryParserSupportsMultipleAliasDeclarations() { $entityManager = $this->_em; - $query = $entityManager->createQuery('SELECT u FROM CmsUser u INDEX BY u.id LEFT JOIN u.phonenumbers p'); + $query = $entityManager->createQuery('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u INDEX BY u.id LEFT JOIN u.phonenumbers p'); $parserResult = $query->parse(); $decl = $parserResult->getQueryComponent('u'); - $this->assertTrue($decl['metadata'] instanceof Doctrine_ORM_Mapping_ClassMetadata); + $this->assertTrue($decl['metadata'] instanceof \Doctrine\ORM\Mapping\ClassMetadata); $this->assertEquals(null, $decl['relation']); $this->assertEquals(null, $decl['parent']); $this->assertEquals(null, $decl['scalar']); @@ -87,8 +89,8 @@ class Orm_Query_IdentifierRecognitionTest extends Doctrine_OrmTestCase $decl = $parserResult->getQueryComponent('p'); - $this->assertTrue($decl['metadata'] instanceof Doctrine_ORM_Mapping_ClassMetadata); - $this->assertTrue($decl['relation'] instanceof Doctrine_ORM_Mapping_AssociationMapping); + $this->assertTrue($decl['metadata'] instanceof \Doctrine\ORM\Mapping\ClassMetadata); + $this->assertTrue($decl['relation'] instanceof \Doctrine\ORM\Mapping\AssociationMapping); $this->assertEquals('u', $decl['parent']); $this->assertEquals(null, $decl['scalar']); $this->assertEquals(null, $decl['map']); @@ -98,12 +100,12 @@ class Orm_Query_IdentifierRecognitionTest extends Doctrine_OrmTestCase public function testQueryParserSupportsMultipleAliasDeclarationsWithIndexBy() { $entityManager = $this->_em; - $query = $entityManager->createQuery('SELECT u FROM CmsUser u INDEX BY u.id LEFT JOIN u.articles a INNER JOIN u.phonenumbers pn INDEX BY pn.phonenumber'); + $query = $entityManager->createQuery('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u INDEX BY u.id LEFT JOIN u.articles a INNER JOIN u.phonenumbers pn INDEX BY pn.phonenumber'); $parserResult = $query->parse(); $decl = $parserResult->getQueryComponent('u'); - $this->assertTrue($decl['metadata'] instanceof Doctrine_ORM_Mapping_ClassMetadata); + $this->assertTrue($decl['metadata'] instanceof \Doctrine\ORM\Mapping\ClassMetadata); $this->assertEquals(null, $decl['relation']); $this->assertEquals(null, $decl['parent']); $this->assertEquals(null, $decl['scalar']); @@ -111,16 +113,16 @@ class Orm_Query_IdentifierRecognitionTest extends Doctrine_OrmTestCase $decl = $parserResult->getQueryComponent('a'); - $this->assertTrue($decl['metadata'] instanceof Doctrine_ORM_Mapping_ClassMetadata); - $this->assertTrue($decl['relation'] instanceof Doctrine_ORM_Mapping_AssociationMapping); + $this->assertTrue($decl['metadata'] instanceof \Doctrine\ORM\Mapping\ClassMetadata); + $this->assertTrue($decl['relation'] instanceof \Doctrine\ORM\Mapping\AssociationMapping); $this->assertEquals('u', $decl['parent']); $this->assertEquals(null, $decl['scalar']); $this->assertEquals(null, $decl['map']); $decl = $parserResult->getQueryComponent('pn'); - $this->assertTrue($decl['metadata'] instanceof Doctrine_ORM_Mapping_ClassMetadata); - $this->assertTrue($decl['relation'] instanceof Doctrine_ORM_Mapping_AssociationMapping); + $this->assertTrue($decl['metadata'] instanceof \Doctrine\ORM\Mapping\ClassMetadata); + $this->assertTrue($decl['relation'] instanceof \Doctrine\ORM\Mapping\AssociationMapping); $this->assertEquals('u', $decl['parent']); $this->assertEquals(null, $decl['scalar']); $this->assertEquals('phonenumber', $decl['map']); diff --git a/tests/Orm/Query/LanguageRecognitionTest.php b/tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php old mode 100755 new mode 100644 similarity index 100% rename from tests/Orm/Query/LanguageRecognitionTest.php rename to tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php diff --git a/tests/Orm/Query/ScannerTest.php b/tests/Doctrine/Tests/ORM/Query/ScannerTest.php old mode 100755 new mode 100644 similarity index 100% rename from tests/Orm/Query/ScannerTest.php rename to tests/Doctrine/Tests/ORM/Query/ScannerTest.php diff --git a/tests/Orm/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php old mode 100755 new mode 100644 similarity index 58% rename from tests/Orm/Query/SelectSqlGenerationTest.php rename to tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index 07e2e7093..b2045a0be --- a/tests/Orm/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -18,7 +18,11 @@ * and is licensed under the LGPL. For more information, see * . */ -require_once 'lib/DoctrineTestInit.php'; + +namespace Doctrine\Tests\ORM\Query; + +require_once dirname(__FILE__) . '/../../TestInit.php'; + /** * Test case for testing the saving and referencing of query identifiers. * @@ -35,7 +39,7 @@ require_once 'lib/DoctrineTestInit.php'; * testcases later since we'll have a lot of them and we might want to have special SQL * generation tests for some dbms specific SQL syntaxes. */ -class Orm_Query_SelectSqlGenerationTest extends Doctrine_OrmTestCase +class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase { private $_em; @@ -60,93 +64,93 @@ class Orm_Query_SelectSqlGenerationTest extends Doctrine_OrmTestCase public function testPlainFromClauseWithoutAlias() { $this->assertSqlGeneration( - 'SELECT u FROM CmsUser u', - 'SELECT cu.id AS cu__id, cu.status AS cu__status, cu.username AS cu__username, cu.name AS cu__name FROM CmsUser cu' + 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u', + 'SELECT cm.id AS cm__id, cm.status AS cm__status, cm.username AS cm__username, cm.name AS cm__name FROM cms_users cm' ); $this->assertSqlGeneration( - 'SELECT u.id FROM CmsUser u', - 'SELECT cu.id AS cu__id FROM CmsUser cu' + 'SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u', + 'SELECT cm.id AS cm__id FROM cms_users cm' ); } public function testSelectSingleComponentWithMultipleColumns() { $this->assertSqlGeneration( - 'SELECT u.username, u.name FROM CmsUser u', - 'SELECT cu.username AS cu__username, cu.name AS cu__name FROM CmsUser cu' + 'SELECT u.username, u.name FROM Doctrine\Tests\Models\CMS\CmsUser u', + 'SELECT cm.username AS cm__username, cm.name AS cm__name FROM cms_users cm' ); } public function testSelectWithCollectionAssociationJoin() { $this->assertSqlGeneration( - 'SELECT u, p FROM CmsUser u JOIN u.phonenumbers p', - 'SELECT cu.id AS cu__id, cu.status AS cu__status, cu.username AS cu__username, cu.name AS cu__name, cp.phonenumber AS cp__phonenumber FROM CmsUser cu INNER JOIN CmsPhonenumber cp ON cu.id = cp.user_id' + 'SELECT u, p FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.phonenumbers p', + 'SELECT cm.id AS cm__id, cm.status AS cm__status, cm.username AS cm__username, cm.name AS cm__name, cm1.phonenumber AS cm1__phonenumber FROM cms_users cm INNER JOIN cms_phonenumbers cm1 ON cm.id = cm1.user_id' ); } public function testSelectWithSingleValuedAssociationJoin() { $this->assertSqlGeneration( - 'SELECT u, a FROM ForumUser u JOIN u.avatar a', - 'SELECT fu.id AS fu__id, fu.username AS fu__username, fa.id AS fa__id FROM ForumUser fu INNER JOIN ForumAvatar fa ON fu.avatar_id = fa.id' + 'SELECT u, a FROM Doctrine\Tests\Models\Forum\ForumUser u JOIN u.avatar a', + 'SELECT fo.id AS fo__id, fo.username AS fo__username, fo1.id AS fo1__id FROM forum_users fo INNER JOIN forum_avatars fo1 ON fo.avatar_id = fo1.id' ); } public function testSelectDistinctIsSupported() { $this->assertSqlGeneration( - 'SELECT DISTINCT u.name FROM CmsUser u', - 'SELECT DISTINCT cu.name AS cu__name FROM CmsUser cu' + 'SELECT DISTINCT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u', + 'SELECT DISTINCT cm.name AS cm__name FROM cms_users cm' ); } public function testAggregateFunctionInSelect() { $this->assertSqlGeneration( - 'SELECT COUNT(u.id) FROM CmsUser u GROUP BY u.id', - 'SELECT COUNT(cu.id) AS dctrn__0 FROM CmsUser cu GROUP BY cu.id' + 'SELECT COUNT(u.id) FROM Doctrine\Tests\Models\CMS\CmsUser u GROUP BY u.id', + 'SELECT COUNT(cm.id) AS dctrn__0 FROM cms_users cm GROUP BY cm.id' ); } public function testWhereClauseInSelectWithPositionalParameter() { $this->assertSqlGeneration( - 'select u from ForumUser u where u.id = ?1', - 'SELECT fu.id AS fu__id, fu.username AS fu__username FROM ForumUser fu WHERE fu.id = ?' + 'select u from Doctrine\Tests\Models\Forum\ForumUser u where u.id = ?1', + 'SELECT fo.id AS fo__id, fo.username AS fo__username FROM forum_users fo WHERE fo.id = ?' ); } public function testWhereClauseInSelectWithNamedParameter() { $this->assertSqlGeneration( - 'select u from ForumUser u where u.username = :name', - 'SELECT fu.id AS fu__id, fu.username AS fu__username FROM ForumUser fu WHERE fu.username = :name' + 'select u from Doctrine\Tests\Models\Forum\ForumUser u where u.username = :name', + 'SELECT fo.id AS fo__id, fo.username AS fo__username FROM forum_users fo WHERE fo.username = :name' ); } public function testWhereANDClauseInSelectWithNamedParameter() { $this->assertSqlGeneration( - 'select u from ForumUser u where u.username = :name and u.username = :name2', - 'SELECT fu.id AS fu__id, fu.username AS fu__username FROM ForumUser fu WHERE fu.username = :name AND fu.username = :name2' + 'select u from Doctrine\Tests\Models\Forum\ForumUser u where u.username = :name and u.username = :name2', + 'SELECT fo.id AS fo__id, fo.username AS fo__username FROM forum_users fo WHERE fo.username = :name AND fo.username = :name2' ); } public function testCombinedWhereClauseInSelectWithNamedParameter() { $this->assertSqlGeneration( - 'select u from ForumUser u where (u.username = :name OR u.username = :name2) AND u.id = :id', - 'SELECT fu.id AS fu__id, fu.username AS fu__username FROM ForumUser fu WHERE (fu.username = :name OR fu.username = :name2) AND fu.id = :id' + 'select u from Doctrine\Tests\Models\Forum\ForumUser u where (u.username = :name OR u.username = :name2) AND u.id = :id', + 'SELECT fo.id AS fo__id, fo.username AS fo__username FROM forum_users fo WHERE (fo.username = :name OR fo.username = :name2) AND fo.id = :id' ); } public function testAggregateFunctionWithDistinctInSelect() { $this->assertSqlGeneration( - 'SELECT COUNT(DISTINCT u.name) FROM CmsUser u', - 'SELECT COUNT(DISTINCT cu.name) AS dctrn__0 FROM CmsUser cu' + 'SELECT COUNT(DISTINCT u.name) FROM Doctrine\Tests\Models\CMS\CmsUser u', + 'SELECT COUNT(DISTINCT cm.name) AS dctrn__0 FROM cms_users cm' ); } @@ -154,50 +158,49 @@ class Orm_Query_SelectSqlGenerationTest extends Doctrine_OrmTestCase public function testKeywordUsageInStringParam() { $this->assertSqlGeneration( - "SELECT u.name FROM CmsUser u WHERE u.name LIKE '%foo OR bar%'", - "SELECT cu.name AS cu__name FROM CmsUser cu WHERE cu.name LIKE '%foo OR bar%'" + "SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name LIKE '%foo OR bar%'", + "SELECT cm.name AS cm__name FROM cms_users cm WHERE cm.name LIKE '%foo OR bar%'" ); } public function testArithmeticExpressionsSupportedInWherePart() { $this->assertSqlGeneration( - 'SELECT u FROM CmsUser u WHERE ((u.id + 5000) * u.id + 3) < 10000000', - 'SELECT cu.id AS cu__id, cu.status AS cu__status, cu.username AS cu__username, cu.name AS cu__name FROM CmsUser cu WHERE ((cu.id + 5000) * cu.id + 3) < 10000000' + 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE ((u.id + 5000) * u.id + 3) < 10000000', + 'SELECT cm.id AS cm__id, cm.status AS cm__status, cm.username AS cm__username, cm.name AS cm__name FROM cms_users cm WHERE ((cm.id + 5000) * cm.id + 3) < 10000000' ); } public function testPlainJoinWithoutClause() { $this->assertSqlGeneration( - 'SELECT u.id, a.id from CmsUser u LEFT JOIN u.articles a', - 'SELECT cu.id AS cu__id, ca.id AS ca__id FROM CmsUser cu LEFT JOIN CmsArticle ca ON cu.id = ca.user_id' + 'SELECT u.id, a.id from Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.articles a', + 'SELECT cm.id AS cm__id, cm1.id AS cm1__id FROM cms_users cm LEFT JOIN cms_articles cm1 ON cm.id = cm1.user_id' ); $this->assertSqlGeneration( - 'SELECT u.id, a.id from CmsUser u JOIN u.articles a', - 'SELECT cu.id AS cu__id, ca.id AS ca__id FROM CmsUser cu INNER JOIN CmsArticle ca ON cu.id = ca.user_id' + 'SELECT u.id, a.id from Doctrine\Tests\Models\CMS\CmsUser u JOIN u.articles a', + 'SELECT cm.id AS cm__id, cm1.id AS cm1__id FROM cms_users cm INNER JOIN cms_articles cm1 ON cm.id = cm1.user_id' ); } public function testDeepJoin() { $this->assertSqlGeneration( - 'SELECT u.id, a.id, p, c.id from CmsUser u JOIN u.articles a JOIN u.phonenumbers p JOIN a.comments c', - 'SELECT cu.id AS cu__id, ca.id AS ca__id, cp.phonenumber AS cp__phonenumber, cc.id AS cc__id FROM CmsUser cu INNER JOIN CmsArticle ca ON cu.id = ca.user_id INNER JOIN CmsPhonenumber cp ON cu.id = cp.user_id INNER JOIN CmsComment cc ON ca.id = cc.article_id' + 'SELECT u.id, a.id, p, c.id from Doctrine\Tests\Models\CMS\CmsUser u JOIN u.articles a JOIN u.phonenumbers p JOIN a.comments c', + 'SELECT cm.id AS cm__id, cm1.id AS cm1__id, cm2.phonenumber AS cm2__phonenumber, cm3.id AS cm3__id FROM cms_users cm INNER JOIN cms_articles cm1 ON cm.id = cm1.user_id INNER JOIN cms_phonenumbers cm2 ON cm.id = cm2.user_id INNER JOIN cms_comments cm3 ON cm1.id = cm3.article_id' ); } -/* - public function testFunctionalExpressionsSupportedInWherePart() + /*public function testFunctionalExpressionsSupportedInWherePart() { $this->assertSqlGeneration( "SELECT u.name FROM CmsUser u WHERE TRIM(u.name) = 'someone'", // String quoting in the SQL usually depends on the database platform. // This test works with a mock connection which uses ' for string quoting. - "SELECT cu.name AS cu__name FROM cms_user cu WHERE TRIM(cu.name) = 'someone'" + "SELECT cu.name AS cu__name FROM CmsUser cu WHERE TRIM(cu.name) = 'someone'" ); - } -*/ + }*/ + /* // Ticket #973 diff --git a/tests/Orm/Query/UpdateSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/UpdateSqlGenerationTest.php old mode 100755 new mode 100644 similarity index 100% rename from tests/Orm/Query/UpdateSqlGenerationTest.php rename to tests/Doctrine/Tests/ORM/Query/UpdateSqlGenerationTest.php diff --git a/tests/Orm/Ticket/1Test.php b/tests/Doctrine/Tests/ORM/Ticket/1Test.php similarity index 100% rename from tests/Orm/Ticket/1Test.php rename to tests/Doctrine/Tests/ORM/Ticket/1Test.php diff --git a/tests/Orm/Ticket/AllTests.php b/tests/Doctrine/Tests/ORM/Ticket/AllTests.php similarity index 100% rename from tests/Orm/Ticket/AllTests.php rename to tests/Doctrine/Tests/ORM/Ticket/AllTests.php diff --git a/tests/Orm/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php similarity index 67% rename from tests/Orm/UnitOfWorkTest.php rename to tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index b24ba73bf..80812d067 100644 --- a/tests/Orm/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -1,17 +1,27 @@ _connectionMock = new Doctrine_ConnectionMock(array()); - $this->_emMock = Doctrine_EntityManagerMock::create($this->_connectionMock, "uowMockEm"); + $this->_connectionMock = new ConnectionMock(array()); + $this->_emMock = EntityManagerMock::create($this->_connectionMock, "uowMockEm"); // SUT - $this->_unitOfWork = new Doctrine_UnitOfWorkMock($this->_emMock); + $this->_unitOfWork = new UnitOfWorkMock($this->_emMock); $this->_emMock->setUnitOfWork($this->_unitOfWork); } @@ -47,11 +57,11 @@ class Orm_UnitOfWorkTest extends Doctrine_OrmTestCase public function testSavingSingleEntityWithIdentityColumnForcesInsert() { // Setup fake persister and id generator for identity generation - $userPersister = new Doctrine_EntityPersisterMock($this->_emMock, $this->_emMock->getClassMetadata("ForumUser")); - $this->_emMock->setEntityPersister('ForumUser', $userPersister); - $idGeneratorMock = new Doctrine_IdentityIdGeneratorMock($this->_emMock); - $this->_emMock->setIdGenerator('ForumUser', $idGeneratorMock); - $userPersister->setMockIdGeneratorType(Doctrine_ORM_Mapping_ClassMetadata::GENERATOR_TYPE_IDENTITY); + $userPersister = new EntityPersisterMock($this->_emMock, $this->_emMock->getClassMetadata("Doctrine\Tests\Models\Forum\ForumUser")); + $this->_emMock->setEntityPersister('Doctrine\Tests\Models\Forum\ForumUser', $userPersister); + $idGeneratorMock = new IdentityIdGeneratorMock($this->_emMock); + $this->_emMock->setIdGenerator('Doctrine\Tests\Models\Forum\ForumUser', $idGeneratorMock); + $userPersister->setMockIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_IDENTITY); // Test $user = new ForumUser(); @@ -88,17 +98,17 @@ class Orm_UnitOfWorkTest extends Doctrine_OrmTestCase { // Setup fake persister and id generator for identity generation //ForumUser - $userPersister = new Doctrine_EntityPersisterMock($this->_emMock, $this->_emMock->getClassMetadata("ForumUser")); - $this->_emMock->setEntityPersister('ForumUser', $userPersister); - $userIdGeneratorMock = new Doctrine_IdentityIdGeneratorMock($this->_emMock); - $this->_emMock->setIdGenerator('ForumUser', $userIdGeneratorMock); - $userPersister->setMockIdGeneratorType(Doctrine_ORM_Mapping_ClassMetadata::GENERATOR_TYPE_IDENTITY); + $userPersister = new EntityPersisterMock($this->_emMock, $this->_emMock->getClassMetadata("Doctrine\Tests\Models\Forum\ForumUser")); + $this->_emMock->setEntityPersister('Doctrine\Tests\Models\Forum\ForumUser', $userPersister); + $userIdGeneratorMock = new IdentityIdGeneratorMock($this->_emMock); + $this->_emMock->setIdGenerator('Doctrine\Tests\Models\Forum\ForumUser', $userIdGeneratorMock); + $userPersister->setMockIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_IDENTITY); // ForumAvatar - $avatarPersister = new Doctrine_EntityPersisterMock($this->_emMock, $this->_emMock->getClassMetadata("ForumAvatar")); - $this->_emMock->setEntityPersister('ForumAvatar', $avatarPersister); - $avatarIdGeneratorMock = new Doctrine_IdentityIdGeneratorMock($this->_emMock); - $this->_emMock->setIdGenerator('ForumAvatar', $avatarIdGeneratorMock); - $avatarPersister->setMockIdGeneratorType(Doctrine_ORM_Mapping_ClassMetadata::GENERATOR_TYPE_IDENTITY); + $avatarPersister = new EntityPersisterMock($this->_emMock, $this->_emMock->getClassMetadata("Doctrine\Tests\Models\Forum\ForumAvatar")); + $this->_emMock->setEntityPersister('Doctrine\Tests\Models\Forum\ForumAvatar', $avatarPersister); + $avatarIdGeneratorMock = new IdentityIdGeneratorMock($this->_emMock); + $this->_emMock->setIdGenerator('Doctrine\Tests\Models\Forum\ForumAvatar', $avatarIdGeneratorMock); + $avatarPersister->setMockIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_IDENTITY); // Test $user = new ForumUser(); @@ -124,21 +134,21 @@ class Orm_UnitOfWorkTest extends Doctrine_OrmTestCase // We need an ID generator for ForumAvatar, because we attach a NEW ForumAvatar // to a (faked) MANAGED instance. During changeset computation this will result // in the UnitOfWork requesting the Id generator of ForumAvatar. - $avatarIdGeneratorMock = new Doctrine_IdentityIdGeneratorMock($this->_emMock); - $this->_emMock->setIdGenerator('ForumAvatar', $avatarIdGeneratorMock); + $avatarIdGeneratorMock = new IdentityIdGeneratorMock($this->_emMock); + $this->_emMock->setIdGenerator('Doctrine\Tests\Models\Forum\ForumAvatar', $avatarIdGeneratorMock); $user1 = new ForumUser(); $user1->id = 1; $user1->username = "romanb"; $user1->avatar = new ForumAvatar(); // Fake managed state - $this->_unitOfWork->setEntityState($user1, Doctrine_ORM_UnitOfWork::STATE_MANAGED); + $this->_unitOfWork->setEntityState($user1, \Doctrine\ORM\UnitOfWork::STATE_MANAGED); $user2 = new ForumUser(); $user2->id = 2; $user2->username = "jwage"; // Fake managed state - $this->_unitOfWork->setEntityState($user2, Doctrine_ORM_UnitOfWork::STATE_MANAGED); + $this->_unitOfWork->setEntityState($user2, \Doctrine\ORM\UnitOfWork::STATE_MANAGED); // Fake original entity date $this->_unitOfWork->setOriginalEntityData($user1, array( diff --git a/tests/lib/Doctrine_OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php similarity index 92% rename from tests/lib/Doctrine_OrmFunctionalTestCase.php rename to tests/Doctrine/Tests/OrmFunctionalTestCase.php index 238d41f50..29dac2567 100644 --- a/tests/lib/Doctrine_OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -1,12 +1,12 @@ sharedFixture['conn'])) { echo " --- CREATE CONNECTION ----"; - $this->sharedFixture['conn'] = Doctrine_TestUtil::getConnection(); + $this->sharedFixture['conn'] = TestUtil::getConnection(); } if ( ! $this->_em) { $this->_em = $this->_getEntityManager(); @@ -120,9 +120,9 @@ class Doctrine_OrmFunctionalTestCase extends Doctrine_OrmTestCase } protected function _getEntityManager($config = null, $eventManager = null) { - $config = new Doctrine_ORM_Configuration(); - $eventManager = new Doctrine_Common_EventManager(); + $config = new \Doctrine\ORM\Configuration(); + $eventManager = new \Doctrine\Common\EventManager(); $conn = $this->sharedFixture['conn']; - return Doctrine_ORM_EntityManager::create($conn, 'em', $config, $eventManager); + return \Doctrine\ORM\EntityManager::create($conn, 'em', $config, $eventManager); } } \ No newline at end of file diff --git a/tests/lib/Doctrine_OrmFunctionalTestSuite.php b/tests/Doctrine/Tests/OrmFunctionalTestSuite.php similarity index 73% rename from tests/lib/Doctrine_OrmFunctionalTestSuite.php rename to tests/Doctrine/Tests/OrmFunctionalTestSuite.php index 435b2f753..d281ed785 100644 --- a/tests/lib/Doctrine_OrmFunctionalTestSuite.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestSuite.php @@ -1,6 +1,6 @@ sharedFixture['conn'])) { - $this->sharedFixture['conn'] = Doctrine_TestUtil::getConnection(); + $this->sharedFixture['conn'] = TestUtil::getConnection(); } } diff --git a/tests/Doctrine/Tests/OrmTestCase.php b/tests/Doctrine/Tests/OrmTestCase.php new file mode 100644 index 000000000..e870c6c6f --- /dev/null +++ b/tests/Doctrine/Tests/OrmTestCase.php @@ -0,0 +1,26 @@ + 'Doctrine\Tests\Mocks\DriverMock', + 'wrapperClass' => 'Doctrine\Tests\Mocks\ConnectionMock', + 'user' => 'john', + 'password' => 'wayne' + ); + return \Doctrine\ORM\EntityManager::create($connectionOptions, 'mockEM', $config, $eventManager); + } +} diff --git a/tests/lib/Doctrine_OrmTestSuite.php b/tests/Doctrine/Tests/OrmTestSuite.php similarity index 51% rename from tests/lib/Doctrine_OrmTestSuite.php rename to tests/Doctrine/Tests/OrmTestSuite.php index 4461e315f..b387b71dc 100644 --- a/tests/lib/Doctrine_OrmTestSuite.php +++ b/tests/Doctrine/Tests/OrmTestSuite.php @@ -1,10 +1,10 @@ setCheckFileExists(true); +//$classLoader->setCheckFileExists(true); $classLoader->register(); $modelDir = dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'models'; set_include_path( get_include_path() - . PATH_SEPARATOR . dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'lib' + . PATH_SEPARATOR . dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'lib' . PATH_SEPARATOR . $modelDir . DIRECTORY_SEPARATOR . 'cms' . PATH_SEPARATOR . $modelDir . DIRECTORY_SEPARATOR . 'company' . PATH_SEPARATOR . $modelDir . DIRECTORY_SEPARATOR . 'ecommerce' @@ -23,12 +24,12 @@ set_include_path( ); // Some of these classes depend on Doctrine_* classes -require_once 'Doctrine_TestCase.php'; -require_once 'Doctrine_TestUtil.php'; -require_once 'Doctrine_DbalTestCase.php'; -require_once 'Doctrine_OrmTestCase.php'; -require_once 'Doctrine_OrmFunctionalTestCase.php'; -require_once 'Doctrine_TestSuite.php'; -require_once 'Doctrine_OrmTestSuite.php'; -require_once 'Doctrine_OrmFunctionalTestSuite.php'; -require_once 'Doctrine_DbalTestSuite.php'; +/*require_once 'DoctrineTestCase.php'; +require_once 'TestUtil.php'; +require_once 'DbalTestCase.php'; +require_once 'OrmTestCase.php'; +require_once 'OrmFunctionalTestCase.php'; +require_once 'DoctrineTestSuite.php'; +require_once 'OrmTestSuite.php'; +require_once 'OrmFunctionalTestSuite.php'; +require_once 'DbalTestSuite.php';*/ diff --git a/tests/lib/Doctrine_TestUtil.php b/tests/Doctrine/Tests/TestUtil.php similarity index 86% rename from tests/lib/Doctrine_TestUtil.php rename to tests/Doctrine/Tests/TestUtil.php index ba282c0f4..44d1d43f9 100644 --- a/tests/lib/Doctrine_TestUtil.php +++ b/tests/Doctrine/Tests/TestUtil.php @@ -1,8 +1,8 @@ addTestSuite('Orm_UnitOfWorkTest'); - $suite->addTestSuite('Orm_EntityManagerTest'); - $suite->addTestSuite('Orm_EntityPersisterTest'); - $suite->addTestSuite('Orm_CommitOrderCalculatorTest'); - - $suite->addTest(Orm_Query_AllTests::suite()); - $suite->addTest(Orm_Hydration_AllTests::suite()); - $suite->addTest(Orm_Entity_AllTests::suite()); - $suite->addTest(Orm_Ticket_AllTests::suite()); - $suite->addTest(Orm_Associations_AllTests::suite()); - $suite->addTest(Orm_Mapping_AllTests::suite()); - $suite->addTest(Orm_Functional_AllTests::suite()); - - return $suite; - } -} - -if (PHPUnit_MAIN_METHOD == 'Orm_AllTests::main') { - Orm_AllTests::main(); -} diff --git a/tests/Orm/Associations/AllTests.php b/tests/Orm/Associations/AllTests.php deleted file mode 100644 index dab2eb871..000000000 --- a/tests/Orm/Associations/AllTests.php +++ /dev/null @@ -1,30 +0,0 @@ -addTestSuite('Orm_Associations_OneToOneMappingTest'); - - return $suite; - } -} - -if (PHPUnit_MAIN_METHOD == 'Orm_Associations_AllTests::main') { - Orm_Associations_AllTests::main(); -} diff --git a/tests/Orm/Entity/AllTests.php b/tests/Orm/Entity/AllTests.php deleted file mode 100644 index 71b43a114..000000000 --- a/tests/Orm/Entity/AllTests.php +++ /dev/null @@ -1,32 +0,0 @@ -addTestSuite('Orm_Entity_AccessorTest'); - $suite->addTestSuite('Orm_Entity_ConstructorTest'); - - return $suite; - } -} - -if (PHPUnit_MAIN_METHOD == 'Orm_Entity_AllTests::main') { - Orm_Entity_AllTests::main(); -} \ No newline at end of file diff --git a/tests/Orm/Entity/ConstructorTest.php b/tests/Orm/Entity/ConstructorTest.php deleted file mode 100644 index 184d2e4d2..000000000 --- a/tests/Orm/Entity/ConstructorTest.php +++ /dev/null @@ -1,47 +0,0 @@ -assertEquals("romanb", $entity->username); - } -} - -class ConstructorTestEntity1 -{ - private $id; - public $username; - - public function __construct($username = null) - { - if ($username !== null) { - $this->username = $username; - } - } - - /* The mapping definition */ - public static function initMetadata($mapping) - { - /* - $mapping->addFieldMetadata('id', array( - 'doctrine.id' => true, - 'doctrine.validator.constraints' => array('notnull', 'unique') - )); - */ - - $mapping->mapField(array( - 'fieldName' => 'id', - 'type' => 'integer', - 'id' => true - )); - $mapping->mapField(array( - 'fieldName' => 'username', - 'type' => 'string', - 'length' => 50 - )); - } -} - diff --git a/tests/Orm/EntityPersisterTest.php b/tests/Orm/EntityPersisterTest.php deleted file mode 100644 index 911fae216..000000000 --- a/tests/Orm/EntityPersisterTest.php +++ /dev/null @@ -1,75 +0,0 @@ -_connMock = new Doctrine_ConnectionMock(array()); - $this->_emMock = Doctrine_EntityManagerMock::create($this->_connMock, 'persisterMockEM'); - $this->_uowMock = new Doctrine_UnitOfWorkMock($this->_emMock); - $this->_emMock->setUnitOfWork($this->_uowMock); - $this->_idGenMock = new Doctrine_SequenceMock($this->_emMock); - $this->_emMock->setIdGenerator('ForumUser', $this->_idGenMock); - - $this->_emMock->activate(); - } - - public function testSimpleInsert() { - $userPersister = new Doctrine_ORM_Persisters_StandardEntityPersister( - $this->_emMock, $this->_emMock->getClassMetadata("ForumUser")); - $avatarPersister = new Doctrine_ORM_Persisters_StandardEntityPersister( - $this->_emMock, $this->_emMock->getClassMetadata("ForumAvatar")); - - $user = new ForumUser(); - $user->username = "romanb"; - $user->avatar = new ForumAvatar(); - - $this->_uowMock->setDataChangeSet($user, array( - 'username' => array('' => 'romanb'), - 'avatar' => array('' => $user->avatar))); - - - //insert - $avatarPersister->insert($user->avatar); - $inserts = $this->_connMock->getInserts(); - //check - $this->assertEquals(1, count($inserts)); - $this->assertTrue(isset($inserts['ForumAvatar'])); - $this->assertEquals(1, count($inserts['ForumAvatar'])); - $this->assertEquals(null, $user->avatar->id); - $user->avatar->id = 0; // Fake that we got an id - - //insert - $userPersister->insert($user); - $inserts = $this->_connMock->getInserts(); - //check - $this->assertEquals(2, count($inserts)); - $this->assertEquals(null, $user->id); - $this->assertTrue(isset($inserts['ForumUser'])); - $this->assertEquals(1, count($inserts['ForumUser'])); - $this->assertEquals(3, count($inserts['ForumUser'][0])); - //username column - $this->assertTrue(isset($inserts['ForumUser'][0]['username'])); - $this->assertEquals('romanb', $inserts['ForumUser'][0]['username']); - //avatar_id join column - $this->assertTrue(isset($inserts['ForumUser'][0]['avatar_id'])); - $this->assertEquals(0, $inserts['ForumUser'][0]['avatar_id']); - //dtype discriminator column - $this->assertTrue(isset($inserts['ForumUser'][0]['dtype'])); - $this->assertEquals('user', $inserts['ForumUser'][0]['dtype']); - } - -} \ No newline at end of file diff --git a/tests/Orm/Functional/AllTests.php b/tests/Orm/Functional/AllTests.php deleted file mode 100644 index c39bd43af..000000000 --- a/tests/Orm/Functional/AllTests.php +++ /dev/null @@ -1,35 +0,0 @@ -addTestSuite('Orm_Functional_BasicCRUDTest'); - - $suite->addTest(Orm_Functional_Ticket_AllTests::suite()); - - return $suite; - } -} - -if (PHPUnit_MAIN_METHOD == 'Orm_Functional_AllTests::main') { - Orm_Functional_AllTests::main(); -} \ No newline at end of file diff --git a/tests/Orm/Hydration/AllTests.php b/tests/Orm/Hydration/AllTests.php deleted file mode 100644 index 431b57ba2..000000000 --- a/tests/Orm/Hydration/AllTests.php +++ /dev/null @@ -1,37 +0,0 @@ -addTestSuite('Orm_Hydration_ObjectHydratorTest'); - $suite->addTestSuite('Orm_Hydration_ArrayHydratorTest'); - $suite->addTestSuite('Orm_Hydration_ScalarHydratorTest'); - $suite->addTestSuite('Orm_Hydration_SingleScalarHydratorTest'); - - return $suite; - } -} - -if (PHPUnit_MAIN_METHOD == 'Orm_Hydration_AllTests::main') { - Orm_Hydration_AllTests::main(); -} diff --git a/tests/Orm/Mapping/AllTests.php b/tests/Orm/Mapping/AllTests.php deleted file mode 100644 index 55f3ef8c6..000000000 --- a/tests/Orm/Mapping/AllTests.php +++ /dev/null @@ -1,32 +0,0 @@ -addTestSuite('Orm_Mapping_ClassMetadataTest'); - $suite->addTestSuite('Orm_Mapping_ClassMetadataFactoryTest'); - - return $suite; - } -} - -if (PHPUnit_MAIN_METHOD == 'Orm_Mapping_AllTests::main') { - Orm_Mapping_AllTests::main(); -} diff --git a/tests/lib/Doctrine_DbalTestCase.php b/tests/lib/Doctrine_DbalTestCase.php deleted file mode 100644 index a339d97c5..000000000 --- a/tests/lib/Doctrine_DbalTestCase.php +++ /dev/null @@ -1,10 +0,0 @@ - 'Doctrine_DriverMock', - 'wrapperClass' => 'Doctrine_ConnectionMock', - 'user' => 'john', - 'password' => 'wayne' - ); - return Doctrine_ORM_EntityManager::create($connectionOptions, 'mockEM', $config, $eventManager); - } -} diff --git a/tests/lib/Doctrine_TestCase.php b/tests/lib/Doctrine_TestCase.php deleted file mode 100644 index 36a415bf2..000000000 --- a/tests/lib/Doctrine_TestCase.php +++ /dev/null @@ -1,10 +0,0 @@ -