diff --git a/lib/Doctrine/Common/Annotations/Annotation.php b/lib/Doctrine/Common/Annotations/Annotation.php index ba7704be0..e2bf42bb5 100644 --- a/lib/Doctrine/Common/Annotations/Annotation.php +++ b/lib/Doctrine/Common/Annotations/Annotation.php @@ -27,7 +27,8 @@ namespace Doctrine\Common\Annotations; * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @link www.doctrine-project.org * @since 2.0 - * @version $Revision: 3938 $ + * @version $Revision$ + * @author Benjamin Eberlei * @author Guilherme Blanco * @author Jonathan Wage * @author Roman Borschel @@ -52,14 +53,29 @@ class Annotation $this->$key = $value; } } - + + /** + * Error handler for unknown property accessor in Annotation class. + * + * @param string $name Unknown property name + */ public function __get($name) { - throw new \BadMethodCallException("Unknown annotation property '$name' on annotation '".get_class($this)."'."); + throw new \BadMethodCallException( + sprintf("Unknown property '%s' on annotation '%s'.", $name, get_class($this)) + ); } + /** + * Error handler for unknown property mutator in Annotation class. + * + * @param string $name Unkown property name + * @param mixed $value Property value + */ public function __set($name, $value) { - throw new \BadMethodCallException("Unknown annotation property '$name' on annotation '".get_class($this)."'."); + throw new \BadMethodCallException( + sprintf("Unknown property '%s' on annotation '%s'.", $name, get_class($this)) + ); } } \ No newline at end of file diff --git a/lib/Doctrine/Common/Annotations/AnnotationException.php b/lib/Doctrine/Common/Annotations/AnnotationException.php index 7610b16ef..bdee49420 100644 --- a/lib/Doctrine/Common/Annotations/AnnotationException.php +++ b/lib/Doctrine/Common/Annotations/AnnotationException.php @@ -27,20 +27,32 @@ namespace Doctrine\Common\Annotations; * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @link www.doctrine-project.org * @since 2.0 - * @version $Revision: 3938 $ + * @version $Revision$ + * @author Benjamin Eberlei * @author Guilherme Blanco * @author Jonathan Wage * @author Roman Borschel */ -class AnnotationException extends \Doctrine\Common\CommonException +class AnnotationException extends \Exception { + /** + * Creates a new AnnotationException describing a Syntax error. + * + * @param string $message Exception message + * @return AnnotationException + */ public static function syntaxError($message) { return new self('[Syntax Error] ' . $message); } - - public static function semanticalError($message) + /** + * Creates a new AnnotationException describing a Semantical error. + * + * @param string $message Exception message + * @return AnnotationException + */ + public static function semanticalError($message) { return new self('[Semantical Error] ' . $message); } diff --git a/lib/Doctrine/Common/Annotations/AnnotationReader.php b/lib/Doctrine/Common/Annotations/AnnotationReader.php index 0863ea94f..966078e8c 100644 --- a/lib/Doctrine/Common/Annotations/AnnotationReader.php +++ b/lib/Doctrine/Common/Annotations/AnnotationReader.php @@ -41,7 +41,7 @@ class AnnotationReader * @var string * @static */ - private static $CACHE_SALT = "@"; + private static $CACHE_SALT = '@'; /** * Annotations Parser @@ -51,15 +51,14 @@ class AnnotationReader private $_parser; /** - * Cache machanism to store processed Annotations + * Cache mechanism to store processed Annotations * * @var Doctrine\Common\Cache\Cache */ private $_cache; /** - * Constructor. Initializes a new AnnotationReader that uses the given - * Cache provider. + * Constructor. Initializes a new AnnotationReader that uses the given Cache provider. * * @param Cache $cache The cache provider to use. If none is provided, ArrayCache is used. */ @@ -107,7 +106,7 @@ class AnnotationReader return $data; } - $annotations = $this->_parser->parse($class->getDocComment(), "class ".$class->getName()); + $annotations = $this->_parser->parse($class->getDocComment(), 'class ' . $class->getName()); $this->_cache->save($cacheKey, $annotations, null); return $annotations; @@ -123,6 +122,7 @@ class AnnotationReader public function getClassAnnotation(ReflectionClass $class, $annotation) { $annotations = $this->getClassAnnotations($class); + return isset($annotations[$annotation]) ? $annotations[$annotation] : null; } @@ -143,7 +143,7 @@ class AnnotationReader return $data; } - $context = "property ".$property->getDeclaringClass()->getName()."::\$".$property->getName(); + $context = 'property ' . $property->getDeclaringClass()->getName() . "::\$" . $property->getName(); $annotations = $this->_parser->parse($property->getDocComment(), $context); $this->_cache->save($cacheKey, $annotations, null); @@ -160,6 +160,7 @@ class AnnotationReader public function getPropertyAnnotation(ReflectionProperty $property, $annotation) { $annotations = $this->getPropertyAnnotations($property); + return isset($annotations[$annotation]) ? $annotations[$annotation] : null; } @@ -180,7 +181,7 @@ class AnnotationReader return $data; } - $context = "method ".$method->getDeclaringClass()->getName()."::".$method->getName()."()"; + $context = 'method ' . $method->getDeclaringClass()->getName() . '::' . $method->getName() . '()'; $annotations = $this->_parser->parse($method->getDocComment(), $context); $this->_cache->save($cacheKey, $annotations, null); @@ -197,6 +198,7 @@ class AnnotationReader public function getMethodAnnotation(ReflectionMethod $method, $annotation) { $annotations = $this->getMethodAnnotations($method); + return isset($annotations[$annotation]) ? $annotations[$annotation] : null; } } \ No newline at end of file diff --git a/lib/Doctrine/Common/Annotations/Lexer.php b/lib/Doctrine/Common/Annotations/Lexer.php index cb32f0cc2..a6b8c0675 100644 --- a/lib/Doctrine/Common/Annotations/Lexer.php +++ b/lib/Doctrine/Common/Annotations/Lexer.php @@ -27,7 +27,8 @@ namespace Doctrine\Common\Annotations; * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @link www.doctrine-project.org * @since 2.0 - * @version $Revision: 3938 $ + * @version $Revision$ + * @author Benjamin Eberlei * @author Guilherme Blanco * @author Jonathan Wage * @author Roman Borschel @@ -80,7 +81,7 @@ class Lexer extends \Doctrine\Common\Lexer $newVal = $this->_getNumeric($value); // Checking numeric value - if ($newVal !== false){ + if ($newVal !== false) { $value = $newVal; return (strpos($value, '.') !== false || stripos($value, 'e') !== false) @@ -93,16 +94,34 @@ class Lexer extends \Doctrine\Common\Lexer return self::T_STRING; } else { switch (strtolower($value)) { - case '@': return self::T_AT; - case ',': return self::T_COMMA; - case '(': return self::T_OPEN_PARENTHESIS; - case ')': return self::T_CLOSE_PARENTHESIS; - case '{': return self::T_OPEN_CURLY_BRACES; + case '@': + return self::T_AT; + + case ',': + return self::T_COMMA; + + case '(': + return self::T_OPEN_PARENTHESIS; + + case ')': + return self::T_CLOSE_PARENTHESIS; + + case '{': + return self::T_OPEN_CURLY_BRACES; + case '}': return self::T_CLOSE_CURLY_BRACES; - case '=': return self::T_EQUALS; - case '\\': return self::T_NAMESPACE_SEPARATOR; - case 'true': return self::T_TRUE; - case 'false': return self::T_FALSE; + case '=': + return self::T_EQUALS; + + case '\\': + return self::T_NAMESPACE_SEPARATOR; + + case 'true': + return self::T_TRUE; + + case 'false': + return self::T_FALSE; + default: if (ctype_alpha($value[0]) || $value[0] === '_') { return self::T_IDENTIFIER; @@ -126,6 +145,7 @@ class Lexer extends \Doctrine\Common\Lexer if ( ! is_scalar($value)) { return false; } + // Checking for valid numeric numbers: 1.234, -1.234e-2 if (is_numeric($value)) { return $value; diff --git a/lib/Doctrine/Common/Annotations/Parser.php b/lib/Doctrine/Common/Annotations/Parser.php index a90d1f361..c421a7cd7 100644 --- a/lib/Doctrine/Common/Annotations/Parser.php +++ b/lib/Doctrine/Common/Annotations/Parser.php @@ -23,10 +23,10 @@ namespace Doctrine\Common\Annotations; * A simple parser for docblock annotations. * * @since 2.0 + * @author Benjamin Eberlei * @author Guilherme Blanco * @author Jonathan Wage * @author Roman Borschel - * @author Benjamin Eberlei */ class Parser { @@ -168,9 +168,10 @@ class Parser $message .= "'{$token['value']}' at position {$token['position']}"; } - if(strlen($this->_context)) { - $message .= ' in '.$this->_context; + if (strlen($this->_context)) { + $message .= ' in ' . $this->_context; } + $message .= '.'; throw AnnotationException::syntaxError($message); @@ -406,6 +407,7 @@ class Parser foreach ($values as $value) { list ($key, $val) = $value; + if ($key !== null) { $array[$key] = $val; } else { diff --git a/lib/Doctrine/DBAL/Tools/Console/Command/RunSqlCommand.php b/lib/Doctrine/DBAL/Tools/Console/Command/RunSqlCommand.php index 0e6c05c82..a4fdaccd0 100644 --- a/lib/Doctrine/DBAL/Tools/Console/Command/RunSqlCommand.php +++ b/lib/Doctrine/DBAL/Tools/Console/Command/RunSqlCommand.php @@ -78,7 +78,7 @@ EOT if (preg_match('/^select/i', $sql)) { $resultSet = $conn->fetchAll($sql); } else { - $resultSet = $em->getConnection()->executeUpdate($sql); + $resultSet = $conn->executeUpdate($sql); } \Doctrine\Common\Util\Debug::dump($resultSet, (int) $depth); diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index e2db2b0d0..c4aa9bb55 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -440,7 +440,8 @@ class EntityManager * * @param object $entity The entity to copy. * @return object The new entity. - * @todo Implementation or remove. + * @todo Implementation need. This is necessary since $e2 = clone $e1; throws an E_FATAL when access anything on $e: + * Fatal error: Maximum function nesting level of '100' reached, aborting! */ public function copy($entity, $deep = false) { diff --git a/lib/Doctrine/ORM/Mapping/Driver/PhpDriver.php b/lib/Doctrine/ORM/Mapping/Driver/PhpDriver.php deleted file mode 100644 index 6b6954b83..000000000 --- a/lib/Doctrine/ORM/Mapping/Driver/PhpDriver.php +++ /dev/null @@ -1,71 +0,0 @@ -. - */ - -namespace Doctrine\ORM\Mapping\Driver; - -use Doctrine\Common\Cache\ArrayCache, - Doctrine\Common\Annotations\AnnotationReader, - Doctrine\DBAL\Schema\AbstractSchemaManager, - Doctrine\ORM\Mapping\ClassMetadataInfo, - Doctrine\ORM\Mapping\MappingException, - Doctrine\Common\Util\Inflector, - Doctrine\ORM\Mapping\Driver\AbstractFileDriver; - -/** - * The PhpDriver includes php files which just populate ClassMetadataInfo - * instances with plain php code - * - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link www.doctrine-project.org - * @since 2.0 - * @version $Revision$ - * @author Benjamin Eberlei - * @author Guilherme Blanco - * @author Jonathan H. Wage - * @author Roman Borschel - * @todo Rename: PHPDriver - */ -class PhpDriver extends AbstractFileDriver -{ - /** - * {@inheritdoc} - */ - protected $_fileExtension = '.php'; - protected $_metadata; - - /** - * {@inheritdoc} - */ - public function loadMetadataForClass($className, ClassMetadataInfo $metadata) - { - $this->_metadata = $metadata; - $this->_loadMappingFile($this->_findMappingFile($className)); - } - - /** - * {@inheritdoc} - */ - protected function _loadMappingFile($file) - { - $metadata = $this->_metadata; - include $file; - } -} \ No newline at end of file diff --git a/lib/Doctrine/ORM/Mapping/Driver/StaticPHPDriver.php b/lib/Doctrine/ORM/Mapping/Driver/StaticPHPDriver.php new file mode 100644 index 000000000..01edab71b --- /dev/null +++ b/lib/Doctrine/ORM/Mapping/Driver/StaticPHPDriver.php @@ -0,0 +1,122 @@ +. + */ + +namespace Doctrine\ORM\Mapping\Driver; + +use Doctrine\ORM\Mapping\ClassMetadataInfo, + Doctrine\ORM\Mapping\MappingException; + +/** + * The StaticPHPDriver calls a static loadMetadata() method on your entity + * classes where you can manually populate the ClassMetadata instance. + * + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @link www.doctrine-project.org + * @since 2.0 + * @version $Revision$ + * @author Benjamin Eberlei + * @author Guilherme Blanco + * @author Jonathan H. Wage + * @author Roman Borschel + */ +class StaticPHPDriver implements Driver +{ + private $_paths = array(); + + public function __construct($paths) + { + $this->addPaths((array) $paths); + } + + public function addPaths(array $paths) + { + $this->_paths = array_unique(array_merge($this->_paths, $paths)); + } + + /** + * {@inheritdoc} + */ + public function loadMetadataForClass($className, ClassMetadataInfo $metadata) + { + call_user_func_array(array($className, 'loadMetadata'), array($metadata)); + } + + /** + * {@inheritDoc} + * @todo Same code exists in AnnotationDriver, should we re-use it somehow or not worry about it? + */ + public function getAllClassNames() + { + if ($this->_classNames !== null) { + return $this->_classNames; + } + + if (!$this->_paths) { + throw MappingException::pathRequired(); + } + + $classes = array(); + $includedFiles = array(); + + foreach ($this->_paths as $path) { + if ( ! is_dir($path)) { + throw MappingException::fileMappingDriversRequireConfiguredDirectoryPath(); + } + + $iterator = new \RecursiveIteratorIterator( + new \RecursiveDirectoryIterator($path), + \RecursiveIteratorIterator::LEAVES_ONLY + ); + + foreach ($iterator as $file) { + if (($fileName = $file->getBasename($this->_fileExtension)) == $file->getBasename()) { + continue; + } + + $sourceFile = realpath($file->getPathName()); + require_once $sourceFile; + $includedFiles[] = $sourceFile; + } + } + + $declared = get_declared_classes(); + + foreach ($declared as $className) { + $rc = new \ReflectionClass($className); + $sourceFile = $rc->getFileName(); + if (in_array($sourceFile, $includedFiles) && ! $this->isTransient($className)) { + $classes[] = $className; + } + } + + $this->_classNames = $classes; + + return $classes; + } + + /** + * {@inheritdoc} + */ + public function isTransient($className) + { + return method_exists($className, 'loadMetadata') ? false : true; + } +} \ No newline at end of file diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index 960ae426d..b15248689 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -203,12 +203,15 @@ class Parser // Process any deferred validations of some nodes in the AST. // This also allows post-processing of the AST for modification purposes. $this->_processDeferredIdentificationVariables(); + if ($this->_deferredPartialObjectExpressions) { $this->_processDeferredPartialObjectExpressions(); } + if ($this->_deferredPathExpressions) { $this->_processDeferredPathExpressions($AST); } + if ($this->_deferredResultVariables) { $this->_processDeferredResultVariables(); } @@ -456,7 +459,7 @@ class Parser // Check if IdentificationVariable exists in queryComponents if ( ! isset($this->_queryComponents[$identVariable])) { $this->semanticalError( - "'$identVariable' is not defined.", $deferredItem['token'] + "'$identVariable' is not defined.", $deferredItem['token'] ); } @@ -465,14 +468,14 @@ class Parser // Check if queryComponent points to an AbstractSchemaName or a ResultVariable if ( ! isset($qComp['metadata'])) { $this->semanticalError( - "'$identVariable' does not point to a Class.", $deferredItem['token'] + "'$identVariable' does not point to a Class.", $deferredItem['token'] ); } // Validate if identification variable nesting level is lower or equal than the current one if ($qComp['nestingLevel'] > $deferredItem['nestingLevel']) { $this->semanticalError( - "'$identVariable' is used outside the scope of its declaration.", $deferredItem['token'] + "'$identVariable' is used outside the scope of its declaration.", $deferredItem['token'] ); } } @@ -486,15 +489,15 @@ class Parser foreach ($expr->partialFieldSet as $field) { if ( ! isset($class->fieldMappings[$field])) { $this->semanticalError( - "There is no mapped field named '$field' on class " . $class->name . ".", - $deferredItem['token'] + "There is no mapped field named '$field' on class " . $class->name . ".", + $deferredItem['token'] ); } } if (array_intersect($class->identifier, $expr->partialFieldSet) != $class->identifier) { $this->semanticalError( - "The partial field selection of class " . $class->name . " must contain the identifier.", - $deferredItem['token'] + "The partial field selection of class " . $class->name . " must contain the identifier.", + $deferredItem['token'] ); } } @@ -514,7 +517,7 @@ class Parser // Check if ResultVariable exists in queryComponents if ( ! isset($this->_queryComponents[$resultVariable])) { $this->semanticalError( - "'$resultVariable' is not defined.", $deferredItem['token'] + "'$resultVariable' is not defined.", $deferredItem['token'] ); } @@ -523,14 +526,14 @@ class Parser // Check if queryComponent points to an AbstractSchemaName or a ResultVariable if ( ! isset($qComp['resultVariable'])) { $this->semanticalError( - "'$identVariable' does not point to a ResultVariable.", $deferredItem['token'] + "'$identVariable' does not point to a ResultVariable.", $deferredItem['token'] ); } // Validate if identification variable nesting level is lower or equal than the current one if ($qComp['nestingLevel'] > $deferredItem['nestingLevel']) { $this->semanticalError( - "'$resultVariable' is used outside the scope of its declaration.", $deferredItem['token'] + "'$resultVariable' is used outside the scope of its declaration.", $deferredItem['token'] ); } } @@ -625,6 +628,7 @@ class Parser ), null ); + $AST->fromClause->identificationVariableDeclarations[0]->joinVariableDeclarations[] = $joinVariableDeclaration; $this->_queryComponents[$aliasIdentificationVariable . '.' . $field] = $joinQueryComponent; diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 1cbb9fd6b..af9b81afb 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -473,8 +473,12 @@ class SqlWalker implements TreeWalker if (count($assoc->sourceToTargetKeyColumns) > 1) { throw QueryException::associationPathCompositeKeyNotSupported(); } - $sql .= $this->getSqlTableAlias($class->table['name'], $dqlAlias) . '.' - . reset($assoc->targetToSourceKeyColumns); + + if ($this->_useSqlTableAliases) { + $sql .= $this->getSqlTableAlias($class->table['name'], $dqlAlias) . '.'; + } + + $sql .= reset($assoc->targetToSourceKeyColumns); } else { // 2- Inverse side: NOT (YET?) SUPPORTED throw QueryException::associationPathInverseSideNotSupported(); diff --git a/lib/Doctrine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php index ccb29cf14..7565442ca 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php @@ -113,7 +113,7 @@ EOT ); } - if ( count($metadatas)) { + if (count($metadatas)) { // Create EntityGenerator $entityGenerator = new EntityGenerator(); diff --git a/lib/vendor/Symfony/Components/Console/Application.php b/lib/vendor/Symfony/Components/Console/Application.php index e26319be7..929bc6bc0 100644 --- a/lib/vendor/Symfony/Components/Console/Application.php +++ b/lib/vendor/Symfony/Components/Console/Application.php @@ -488,7 +488,7 @@ class Application { // namespace $namespace = ''; - if (false !== $pos = strpos($name, ':')) + if (false !== $pos = strrpos($name, ':')) { $namespace = $this->findNamespace(substr($name, 0, $pos)); $name = substr($name, $pos + 1); diff --git a/lib/vendor/Symfony/Components/Console/Command/Command.php b/lib/vendor/Symfony/Components/Console/Command/Command.php index bbde5f94e..b0e3d863a 100644 --- a/lib/vendor/Symfony/Components/Console/Command/Command.php +++ b/lib/vendor/Symfony/Components/Console/Command/Command.php @@ -276,7 +276,7 @@ class Command */ public function setName($name) { - if (false !== $pos = strpos($name, ':')) + if (false !== $pos = strrpos($name, ':')) { $namespace = substr($name, 0, $pos); $name = substr($name, $pos + 1); @@ -375,6 +375,28 @@ class Command return $this->help; } + /** + * Returns the processed help for the command replacing the %command.name% and + * %command.full_name% patterns with the real values dynamically. + * + * @return string The processed help for the command + */ + public function getProcessedHelp() + { + $name = $this->namespace.':'.$this->name; + + $placeholders = array( + '%command.name%', + '%command.full_name%' + ); + $replacements = array( + $name, + $_SERVER['PHP_SELF'].' '.$name + ); + + return str_replace($placeholders, $replacements, $this->getHelp()); + } + /** * Sets the aliases for the command. * @@ -457,7 +479,7 @@ class Command $messages[] = $this->definition->asText(); - if ($help = $this->getHelp()) + if ($help = $this->getProcessedHelp()) { $messages[] = 'Help:'; $messages[] = ' '.implode("\n ", explode("\n", $help))."\n"; diff --git a/lib/vendor/Symfony/Components/Console/Input/ArgvInput.php b/lib/vendor/Symfony/Components/Console/Input/ArgvInput.php index a140219bf..7a78003f7 100644 --- a/lib/vendor/Symfony/Components/Console/Input/ArgvInput.php +++ b/lib/vendor/Symfony/Components/Console/Input/ArgvInput.php @@ -70,7 +70,7 @@ class ArgvInput extends Input protected function parse() { $this->parsed = $this->tokens; - while ($token = array_shift($this->parsed)) + while (null !== ($token = array_shift($this->parsed))) { if ('--' === substr($token, 0, 2)) { diff --git a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php index 8b29c6bad..1fdf4a33c 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\ORM\Mapping; use Doctrine\ORM\Mapping\ClassMetadata, + Doctrine\ORM\Mapping\ClassMetadataInfo, Doctrine\ORM\Mapping\Driver\XmlDriver, Doctrine\ORM\Mapping\Driver\YamlDriver; @@ -264,4 +265,109 @@ class User { } + + public static function loadMetadata(ClassMetadataInfo $metadata) + { + $metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_NONE); + $metadata->setPrimaryTable(array( + 'name' => 'cms_users', + )); + $metadata->setChangeTrackingPolicy(ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT); + $metadata->addLifecycleCallback('doStuffOnPrePersist', 'prePersist'); + $metadata->addLifecycleCallback('doOtherStuffOnPrePersistToo', 'prePersist'); + $metadata->addLifecycleCallback('doStuffOnPostPersist', 'postPersist'); + $metadata->mapField(array( + 'id' => true, + 'fieldName' => 'id', + 'type' => 'integer', + 'columnName' => 'id', + )); + $metadata->mapField(array( + 'fieldName' => 'name', + 'type' => 'string', + 'length' => 50, + 'unique' => true, + 'nullable' => true, + 'columnName' => 'name', + )); + $metadata->mapField(array( + 'fieldName' => 'email', + 'type' => 'string', + 'columnName' => 'user_email', + 'columnDefinition' => 'CHAR(32) NOT NULL', + )); + $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO); + $metadata->mapOneToOne(array( + 'fieldName' => 'address', + 'targetEntity' => 'Doctrine\\Tests\\ORM\\Mapping\\Address', + 'cascade' => + array( + 0 => 'remove', + ), + 'mappedBy' => NULL, + 'inversedBy' => 'user', + 'joinColumns' => + array( + 0 => + array( + 'name' => 'address_id', + 'referencedColumnName' => 'id', + 'onDelete' => 'CASCADE', + 'onUpdate' => 'CASCADE' + ), + ), + 'orphanRemoval' => false, + )); + $metadata->mapOneToMany(array( + 'fieldName' => 'phonenumbers', + 'targetEntity' => 'Doctrine\\Tests\\ORM\\Mapping\\Phonenumber', + 'cascade' => + array( + 1 => 'persist', + ), + 'mappedBy' => 'user', + 'orphanRemoval' => false, + 'orderBy' => + array( + 'number' => 'ASC', + ), + )); + $metadata->mapManyToMany(array( + 'fieldName' => 'groups', + 'targetEntity' => 'Doctrine\\Tests\\ORM\\Mapping\\Group', + 'cascade' => + array( + 0 => 'remove', + 1 => 'persist', + 2 => 'refresh', + 3 => 'merge', + 4 => 'detach', + ), + 'mappedBy' => NULL, + 'joinTable' => + array( + 'name' => 'cms_users_groups', + 'joinColumns' => + array( + 0 => + array( + 'name' => 'user_id', + 'referencedColumnName' => 'id', + 'unique' => false, + 'nullable' => false, + ), + ), + 'inverseJoinColumns' => + array( + 0 => + array( + 'name' => 'group_id', + 'referencedColumnName' => 'id', + 'columnDefinition' => 'INT NULL', + ), + ), + ), + 'orderBy' => NULL, + )); + } } \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/AllTests.php b/tests/Doctrine/Tests/ORM/Mapping/AllTests.php index db9ceb0e2..06bfe498f 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AllTests.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AllTests.php @@ -23,7 +23,8 @@ class AllTests $suite->addTestSuite('Doctrine\Tests\ORM\Mapping\XmlMappingDriverTest'); $suite->addTestSuite('Doctrine\Tests\ORM\Mapping\YamlMappingDriverTest'); $suite->addTestSuite('Doctrine\Tests\ORM\Mapping\AnnotationDriverTest'); - $suite->addTestSuite('Doctrine\Tests\ORM\Mapping\PhpMappingDriverTest'); + //$suite->addTestSuite('Doctrine\Tests\ORM\Mapping\PHPMappingDriverTest'); FILE MISSING!!! + $suite->addTestSuite('Doctrine\Tests\ORM\Mapping\StaticPHPMappingDriverTest'); $suite->addTestSuite('Doctrine\Tests\ORM\Mapping\ClassMetadataFactoryTest'); $suite->addTestSuite('Doctrine\Tests\ORM\Mapping\ClassMetadataLoadEventTest'); $suite->addTestSuite('Doctrine\Tests\ORM\Mapping\BasicInheritanceMappingTest'); diff --git a/tests/Doctrine/Tests/ORM/Mapping/PhpMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/PhpMappingDriverTest.php deleted file mode 100644 index 50bfcb819..000000000 --- a/tests/Doctrine/Tests/ORM/Mapping/PhpMappingDriverTest.php +++ /dev/null @@ -1,31 +0,0 @@ -addMappingSource(__DIR__ . DIRECTORY_SEPARATOR . 'yaml'); - - $exporter = $cme->getExporter('php', $path); - $exporter->setMetadatas($cme->getMetadatas()); - $exporter->export(); - */ - - return new PhpDriver($path); - } -} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/StaticPHPMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/StaticPHPMappingDriverTest.php new file mode 100644 index 000000000..1a5a2074e --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/StaticPHPMappingDriverTest.php @@ -0,0 +1,17 @@ +assertSqlGeneration( + "UPDATE Doctrine\Tests\Models\CMS\CmsPhonenumber p SET p.phonenumber = 1234 WHERE p.user = ?1", + "UPDATE cms_phonenumbers SET phonenumber = 1234 WHERE user_id = ?" + ); + } } diff --git a/tools/sandbox/cli-config.php b/tools/sandbox/cli-config.php index 5c69499b0..afe1296e6 100644 --- a/tools/sandbox/cli-config.php +++ b/tools/sandbox/cli-config.php @@ -23,7 +23,7 @@ $connectionOptions = array( $em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config); -$helperSet = new \Symfony\Components\Console\Helper\HelperSet(array( +$helpers = array( 'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()), 'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em) -)); \ No newline at end of file +); \ No newline at end of file diff --git a/tools/sandbox/doctrine.php b/tools/sandbox/doctrine.php index 152a9932e..3b4a856de 100644 --- a/tools/sandbox/doctrine.php +++ b/tools/sandbox/doctrine.php @@ -13,7 +13,10 @@ require __DIR__ . '/cli-config.php'; $cli = new \Symfony\Components\Console\Application('Doctrine Command Line Interface', Doctrine\Common\Version::VERSION); $cli->setCatchExceptions(true); -$cli->setHelperSet($helperSet); +$helperSet = $cli->getHelperSet(); +foreach ($helpers as $name => $helper) { + $helperSet->set($helper, $name); +} $cli->addCommands(array( // DBAL Commands new \Doctrine\DBAL\Tools\Console\Command\RunSqlCommand(),