Commit a56689be authored by guilhermeblanco's avatar guilhermeblanco

[2.0] Reverted wrong changeset of commit related to 7246

parent fc5960c4
...@@ -52,7 +52,7 @@ class Configuration extends \Doctrine\DBAL\Configuration ...@@ -52,7 +52,7 @@ class Configuration extends \Doctrine\DBAL\Configuration
'namedNativeQueries' => array(), 'namedNativeQueries' => array(),
'autoGenerateProxyClasses' => true, 'autoGenerateProxyClasses' => true,
'proxyNamespace' => null, 'proxyNamespace' => null,
'entityNamespaces' => array() 'entityAliasMap' => array()
)); ));
} }
...@@ -121,24 +121,24 @@ class Configuration extends \Doctrine\DBAL\Configuration ...@@ -121,24 +121,24 @@ class Configuration extends \Doctrine\DBAL\Configuration
} }
/** /**
* Add a namespace alias for entities. * Add an alias for an entity.
* *
* @param string $className
* @param string $alias * @param string $alias
* @param string $namespace
*/ */
public function addEntityNamespace($alias, $namespace) public function addEntityAlias($className, $alias)
{ {
$this->_attributes['entityNamespaces'][$alias] = $namespace; $this->_attributes['entityAliasMap'][$alias] = $className;
} }
/** /**
* get the array of entity namespaces * get the array of entity aliases
* *
* @return array $entityNamespaces * @return array $aliasMap
*/ */
public function getEntityNamespaces() public function getEntityAliasMap()
{ {
return $this->_attributes['entityNamespaces']; return $this->_attributes['entityAliasMap'];
} }
/** /**
...@@ -147,9 +147,9 @@ class Configuration extends \Doctrine\DBAL\Configuration ...@@ -147,9 +147,9 @@ class Configuration extends \Doctrine\DBAL\Configuration
* @param array $entityAliasMap * @param array $entityAliasMap
* @return void * @return void
*/ */
public function setEntityNamespaces(array $entityNamespaces) public function setEntityAliasMap(array $entityAliasMap)
{ {
$this->_attributes['entityNamespaces'] = $entityNamespaces; $this->_attributes['entityAliasMap'] = $entityAliasMap;
} }
/** /**
......
...@@ -127,11 +127,12 @@ class ClassMetadataFactory ...@@ -127,11 +127,12 @@ class ClassMetadataFactory
*/ */
public function getMetadataFor($className) public function getMetadataFor($className)
{ {
$className = $this->_resolveClassName($className);
if ( ! isset($this->_loadedMetadata[$className])) { if ( ! isset($this->_loadedMetadata[$className])) {
$aliasMap = $this->_em->getConfiguration()->getEntityAliasMap();
if (isset($aliasMap[$className])) {
$className = $aliasMap[$className];
}
$cacheKey = "$className\$CLASSMETADATA"; $cacheKey = "$className\$CLASSMETADATA";
if ($this->_cacheDriver) { if ($this->_cacheDriver) {
if (($cached = $this->_cacheDriver->fetch($cacheKey)) !== false) { if (($cached = $this->_cacheDriver->fetch($cacheKey)) !== false) {
$this->_loadedMetadata[$className] = $cached; $this->_loadedMetadata[$className] = $cached;
...@@ -378,20 +379,4 @@ class ClassMetadataFactory ...@@ -378,20 +379,4 @@ class ClassMetadataFactory
throw new ORMException("Unknown generator type: " . $class->generatorType); throw new ORMException("Unknown generator type: " . $class->generatorType);
} }
} }
protected function _resolveClassName($className)
{
if (($pos = strrpos($className, ':')) !== false) {
$entityNamespaces = $this->_em->getConfiguration()->getEntityNamespaces();
$entityNamespace = substr($className, 0, $pos);
if ( ! isset($entityNamespaces[$entityNamespace])) {
throw MappingException::unknownEntityNamespace($entityNamespace, $className);
}
$className = trim($entityNamespaces[$entityNamespace], '\\') . '\\' . substr($className, $pos + 1);
}
return $className;
}
} }
...@@ -185,11 +185,4 @@ class MappingException extends \Doctrine\ORM\ORMException ...@@ -185,11 +185,4 @@ class MappingException extends \Doctrine\ORM\ORMException
"does not exist." "does not exist."
); );
} }
public static function unknownEntityNamespace($namespace, $entity)
{
return new self(
"Unknown Entity namespace '$namespace' when processing '$entity'."
);
}
} }
\ No newline at end of file
...@@ -51,44 +51,43 @@ class Lexer extends \Doctrine\Common\Lexer ...@@ -51,44 +51,43 @@ class Lexer extends \Doctrine\Common\Lexer
const T_BOTH = 108; const T_BOTH = 108;
const T_BY = 109; const T_BY = 109;
const T_CLOSE_PARENTHESIS = 110; const T_CLOSE_PARENTHESIS = 110;
const T_COLON = 111; const T_COMMA = 111;
const T_COMMA = 112; const T_COUNT = 112;
const T_COUNT = 113; const T_DELETE = 113;
const T_DELETE = 114; const T_DESC = 114;
const T_DESC = 115; const T_DISTINCT = 115;
const T_DISTINCT = 116; const T_DIVIDE = 116;
const T_DIVIDE = 117; const T_DOT = 117;
const T_DOT = 118; const T_EMPTY = 118;
const T_EMPTY = 119; const T_EQUALS = 119;
const T_EQUALS = 120; const T_ESCAPE = 120;
const T_ESCAPE = 121; const T_EXISTS = 121;
const T_EXISTS = 122; const T_FALSE = 122;
const T_FALSE = 123; const T_FROM = 123;
const T_FROM = 124; const T_GREATER_THAN = 124;
const T_GREATER_THAN = 125; const T_GROUP = 125;
const T_GROUP = 126; const T_HAVING = 126;
const T_HAVING = 127; const T_IN = 127;
const T_IN = 128; const T_INDEX = 128;
const T_INDEX = 129; const T_INNER = 129;
const T_INNER = 130; const T_IS = 130;
const T_IS = 131; const T_JOIN = 131;
const T_JOIN = 132; const T_LEADING = 132;
const T_LEADING = 133; const T_LEFT = 133;
const T_LEFT = 134; const T_LIKE = 134;
const T_LIKE = 135; const T_LIMIT = 135;
const T_LIMIT = 136; const T_LOWER_THAN = 136;
const T_LOWER_THAN = 137; const T_MAX = 137;
const T_MAX = 138; const T_MEMBER = 138;
const T_MEMBER = 139; const T_MIN = 139;
const T_MIN = 140; const T_MINUS = 140;
const T_MINUS = 141; const T_MOD = 141;
const T_MOD = 142; const T_MULTIPLY = 142;
const T_MULTIPLY = 143; const T_NEGATE = 143;
const T_NEGATE = 144; const T_NOT = 144;
const T_NOT = 145; const T_NULL = 145;
const T_NULL = 146; const T_OF = 146;
const T_OF = 147; const T_OFFSET = 147;
const T_OFFSET = 148;
const T_OPEN_PARENTHESIS = 149; const T_OPEN_PARENTHESIS = 149;
const T_OR = 150; const T_OR = 150;
const T_ORDER = 151; const T_ORDER = 151;
...@@ -124,7 +123,7 @@ class Lexer extends \Doctrine\Common\Lexer ...@@ -124,7 +123,7 @@ class Lexer extends \Doctrine\Common\Lexer
protected function getCatchablePatterns() protected function getCatchablePatterns()
{ {
return array( return array(
'[a-z_][a-z0-9_\:\\\]*[a-z0-9_]{1}', '[a-z_][a-z0-9_\\\]*',
'(?:[0-9]+(?:[,\.][0-9]+)*)(?:e[+-]?[0-9]+)?', '(?:[0-9]+(?:[,\.][0-9]+)*)(?:e[+-]?[0-9]+)?',
"'(?:[^']|'')*'", "'(?:[^']|'')*'",
'\?[1-9]+|:[a-z][a-z0-9_]+' '\?[1-9]+|:[a-z][a-z0-9_]+'
......
...@@ -867,22 +867,12 @@ class Parser ...@@ -867,22 +867,12 @@ class Parser
$this->match(Lexer::T_IDENTIFIER); $this->match(Lexer::T_IDENTIFIER);
$schemaName = $this->_lexer->token['value']; $schemaName = $this->_lexer->token['value'];
$aliasMap = $this->_em->getConfiguration()->getEntityAliasMap();
if (($pos = strrpos($schemaName, ':')) !== false) { if (isset($aliasMap[$schemaName])) {
$entityNamespaces = $this->_em->getConfiguration()->getEntityNamespaces(); $schemaName = $aliasMap[$schemaName];
$entityNamespace = substr($schemaName, 0, $pos);
if ( ! isset($entityNamespaces[$entityNamespace])) {
$this->semanticalError(
"Unknown Entity namespace '$entityNamespace' when processing '$schemaName'.", $this->_lexer->token
);
}
$schemaName = trim($entityNamespaces[$entityNamespace], '\\') . '\\' . substr($schemaName, $pos + 1);
} }
$exists = class_exists($schemaName, true); $exists = class_exists($schemaName, true);
if ( ! $exists) { if ( ! $exists) {
$this->semanticalError("Class '$schemaName' is not defined.", $this->_lexer->token); $this->semanticalError("Class '$schemaName' is not defined.", $this->_lexer->token);
} }
......
...@@ -297,27 +297,6 @@ class AnnotationExporter extends AbstractExporter ...@@ -297,27 +297,6 @@ class AnnotationExporter extends AbstractExporter
return '@Table(' . implode(', ', $table) . ')'; return '@Table(' . implode(', ', $table) . ')';
} }
private function _getInheritanceAnnotation($metadata)
{
if ($metadata->inheritanceType != ClassMetadataInfo::INHERITANCE_TYPE_NONE) {
switch ($metadata->inheritanceType) {
case ClassMetadataInfo::INHERITANCE_TYPE_JOINED:
$type = "JOINED";
break;
case ClassMetadataInfo::INHERITANCE_TYPE_SINGLE_TABLE:
$type = "SINGLE_TABLE";
break;
case ClassMetadataInfo::INHERITANCE_TYPE_TABLE_PER_CLASS:
$type = "TABLE_PER_CLASS";
break;
}
return '@InheritanceType("'.$type.'")';
}
return '';
}
private function _getJoinColumnAnnotation(array $joinColumn) private function _getJoinColumnAnnotation(array $joinColumn)
{ {
$joinColumnAnnot = array(); $joinColumnAnnot = array();
......
...@@ -16,7 +16,6 @@ use <?php echo $this->_getClassToExtendNamespace() ?>; ...@@ -16,7 +16,6 @@ use <?php echo $this->_getClassToExtendNamespace() ?>;
* @Entity * @Entity
<?php endif; ?> <?php endif; ?>
* <?php echo $this->_getTableAnnotation($metadata)."\n" ?> * <?php echo $this->_getTableAnnotation($metadata)."\n" ?>
* <?php echo $this->_getInheritanceAnnotation($metadata)."\n" ?>
*/ */
class <?Php echo $this->_getClassName($metadata) ?><?php if ($this->_extendsClass()): ?> extends <?php echo $this->_getClassToExtendName() ?><?php endif; ?> class <?Php echo $this->_getClassName($metadata) ?><?php if ($this->_extendsClass()): ?> extends <?php echo $this->_getClassToExtendName() ?><?php endif; ?>
......
...@@ -65,17 +65,6 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase ...@@ -65,17 +65,6 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase
$users = $repos->findAll(); $users = $repos->findAll();
$this->assertEquals(2, count($users)); $this->assertEquals(2, count($users));
$this->_em->clear();
$this->_em->getConfiguration()->addEntityNamespace('CMS', 'Doctrine\Tests\Models\CMS');
$repos = $this->_em->getRepository('CMS:CmsUser');
$users = $repos->findAll();
$this->assertEquals(2, count($users));
$this->_em->getConfiguration()->setEntityNamespaces(array());
} }
/** /**
......
...@@ -227,18 +227,18 @@ class QueryTest extends \Doctrine\Tests\OrmFunctionalTestCase ...@@ -227,18 +227,18 @@ class QueryTest extends \Doctrine\Tests\OrmFunctionalTestCase
->getSingleResult(); ->getSingleResult();
} }
public function testSupportsQueriesWithEntityNamespaces() public function testSupportsQueriesWithEntityAliases()
{ {
$this->_em->getConfiguration()->addEntityNamespace('CMS', 'Doctrine\Tests\Models\CMS'); $this->_em->getConfiguration()->addEntityAlias('Doctrine\Tests\Models\CMS\CmsUser', 'TestAlias');
try { try {
$query = $this->_em->createQuery('UPDATE CMS:CmsUser u SET u.name = ?1'); $query = $this->_em->createQuery('UPDATE TestAlias u SET u.name = ?1');
$this->assertEquals('UPDATE cms_users SET name = ?', $query->getSql()); $this->assertEquals('UPDATE cms_users SET name = ?', $query->getSql());
$query->free(); $query->free();
} catch (\Exception $e) { } catch (\Exception $e) {
$this->fail($e->getMessage()); $this->fail($e->getMessage());
} }
$this->_em->getConfiguration()->setEntityNamespaces(array()); $this->_em->getConfiguration()->setEntityAliasMap(array());
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment