From a36bea29510347469e9454612009d3963ed200ff Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 15 Jan 2015 03:37:50 +0100 Subject: [PATCH] #1130 DDC-3300 - optimizing performance (looping over existing classes first): throwing exceptions if the class is not found in the discriminator map --- .../ORM/Mapping/ClassMetadataFactory.php | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index a6ad18832..e44ed2ff4 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -308,21 +308,37 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory * * @param ClassMetadata $metadata * + * @return void + * * @throws MappingException */ private function populateDiscriminatorValue(ClassMetadata $metadata) { - if (! $metadata->discriminatorValue && $metadata->discriminatorMap) { - foreach ($metadata->discriminatorMap as $discriminatorValue => $discriminatorClass) { - if ($metadata->name === $this->getMetadataFor($discriminatorClass)->getName()) { - $metadata->discriminatorValue = $discriminatorValue; - - break; - } - } - - //throw MappingException::mappedClassNotPartOfDiscriminatorMap($metadata->name, $metadata->rootEntityName); + if ($metadata->discriminatorValue + || ! $metadata->discriminatorMap + || $metadata->isMappedSuperclass + || $metadata->reflClass->isAbstract() + ) { + return; } + + foreach ($metadata->discriminatorMap as $discriminatorValue => $discriminatorClass) { + if ($discriminatorClass === $metadata->name) { + $metadata->discriminatorValue = $discriminatorValue; + + return; + } + } + + foreach ($metadata->discriminatorMap as $discriminatorValue => $discriminatorClass) { + if ($metadata->name === $this->getMetadataFor($discriminatorClass)->getName()) { + $metadata->discriminatorValue = $discriminatorValue; + + return; + } + } + + throw MappingException::mappedClassNotPartOfDiscriminatorMap($metadata->name, $metadata->rootEntityName); } /**