1
0
mirror of synced 2024-12-14 07:06:04 +03:00

apply naming strategy on ClassMetadata

This commit is contained in:
Fabio B. Silva 2011-12-23 12:28:09 -02:00
parent 8b1f60c9f8
commit 83a9458653
2 changed files with 10 additions and 5 deletions

View File

@ -21,7 +21,8 @@ namespace Doctrine\ORM\Mapping;
use ReflectionClass, ReflectionProperty; use ReflectionClass, ReflectionProperty;
use Doctrine\Common\Persistence\Mapping\ClassMetadata AS IClassMetadata; use Doctrine\Common\Persistence\Mapping\ClassMetadata AS IClassMetadata;
use Doctrine\ORM\DefaultNamingStrategy;
use Doctrine\ORM\NamingStrategy;
/** /**
* A <tt>ClassMetadata</tt> instance holds all the object-relational mapping metadata * A <tt>ClassMetadata</tt> instance holds all the object-relational mapping metadata
* of an entity and it's associations. * of an entity and it's associations.
@ -61,13 +62,15 @@ class ClassMetadata extends ClassMetadataInfo implements IClassMetadata
* metadata of the class with the given name. * metadata of the class with the given name.
* *
* @param string $entityName The name of the entity class the new instance is used for. * @param string $entityName The name of the entity class the new instance is used for.
* @param NamingStrategy $namingStrategy
*/ */
public function __construct($entityName) public function __construct($entityName, NamingStrategy $namingStrategy = null)
{ {
$namingStrategy = $namingStrategy ?: new DefaultNamingStrategy();
$this->reflClass = new ReflectionClass($entityName); $this->reflClass = new ReflectionClass($entityName);
$this->namespace = $this->reflClass->getNamespaceName(); $this->namespace = $this->reflClass->getNamespaceName();
$this->table['name'] = $this->reflClass->getShortName(); $this->table['name'] = $namingStrategy->classToTableName($this->reflClass->getShortName());
parent::__construct($this->reflClass->getName()); // do not use $entityName, possible case-problems parent::__construct($this->reflClass->getName(),$namingStrategy); // do not use $entityName, possible case-problems
} }
/** /**

View File

@ -21,6 +21,8 @@ namespace Doctrine\ORM\Mapping;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use ReflectionClass; use ReflectionClass;
use Doctrine\ORM\DefaultNamingStrategy;
use Doctrine\ORM\NamingStrategy;
/** /**
* A <tt>ClassMetadata</tt> instance holds all the object-relational mapping metadata * A <tt>ClassMetadata</tt> instance holds all the object-relational mapping metadata
@ -512,7 +514,7 @@ class ClassMetadataInfo
{ {
$this->name = $entityName; $this->name = $entityName;
$this->rootEntityName = $entityName; $this->rootEntityName = $entityName;
$this->namingStrategy = $namingStrategy ?: new \Doctrine\ORM\DefaultNamingStrategy(); $this->namingStrategy = $namingStrategy ?: new DefaultNamingStrategy();
} }
/** /**