Skip to content

Commit

Permalink
#1130 DDC-3300 - rewording and clarifying logic that re-maps discrim…
Browse files Browse the repository at this point in the history
…inator values when needed
  • Loading branch information
Ocramius committed Jan 16, 2015
1 parent 2ec6011 commit 550694a
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
use Doctrine\ORM\Id\BigIntegerIdentityGenerator;
use Doctrine\ORM\Id\IdentityGenerator;
use Doctrine\ORM\ORMException;
use Exception;
use ReflectionException;

/**
Expand Down Expand Up @@ -75,11 +74,10 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory
* {@inheritDoc}
*/
protected function loadMetadata($name)
{
/* @var $loaded string[] */
`` {
$loaded = parent::loadMetadata($name);

array_map([$this, 'populateDiscriminatorValue'], array_map([$this, 'getMetadataFor'], $loaded));
array_map([$this, 'resolveDiscriminatorValue'], array_map([$this, 'getMetadataFor'], $loaded));

return $loaded;
}
Expand Down Expand Up @@ -280,9 +278,6 @@ protected function validateRuntimeMetadata($class, $parent)
if ( ! $class->discriminatorColumn) {
throw MappingException::missingDiscriminatorColumn($class->name);
}
} else if (! $class->reflClass->isAbstract() && !in_array($class->name, array_values($class->discriminatorMap))) {
// enforce discriminator map for all entities of an inheritance hierarchy, otherwise problems will occur.
//throw MappingException::mappedClassNotPartOfDiscriminatorMap($class->name, $class->rootEntityName);
}
} else if ($class->isMappedSuperclass && $class->name == $class->rootEntityName && (count($class->discriminatorMap) || $class->discriminatorColumn)) {
// second condition is necessary for mapped superclasses in the middle of an inheritance hierarchy
Expand All @@ -308,7 +303,7 @@ protected function newClassMetadataInstance($className)
*
* @throws MappingException
*/
private function populateDiscriminatorValue(ClassMetadata $metadata)
private function resolveDiscriminatorValue(ClassMetadata $metadata)
{
if ($metadata->discriminatorValue
|| ! $metadata->discriminatorMap
Expand All @@ -318,6 +313,7 @@ private function populateDiscriminatorValue(ClassMetadata $metadata)
return;
}

// minor optimization: avoid loading related metadata when not needed
foreach ($metadata->discriminatorMap as $discriminatorValue => $discriminatorClass) {
if ($discriminatorClass === $metadata->name) {
$metadata->discriminatorValue = $discriminatorValue;
Expand All @@ -326,6 +322,7 @@ private function populateDiscriminatorValue(ClassMetadata $metadata)
}
}

// iterate over discriminator mappings and resolve actual referenced classes according to existing metadata
foreach ($metadata->discriminatorMap as $discriminatorValue => $discriminatorClass) {
if ($metadata->name === $this->getMetadataFor($discriminatorClass)->getName()) {
$metadata->discriminatorValue = $discriminatorValue;
Expand Down

0 comments on commit 550694a

Please sign in to comment.