1
0
mirror of synced 2025-01-31 12:32:59 +03:00

#1130 DDC-3300 - refactoring auto-remapping of discriminator value into a private method

This commit is contained in:
Marco Pivetta 2015-01-15 03:04:56 +01:00
parent c589b5d013
commit 786c34faa5

View File

@ -79,18 +79,7 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory
/* @var $loaded string[] */
$loaded = parent::loadMetadata($name);
foreach ($loaded as $className) {
/* @var $metadata ClassMetadata */
$metadata = $this->getMetadataFor($className);
if (! $metadata->discriminatorValue) {
foreach ($metadata->discriminatorMap as $discriminatorValue => $discriminatorClass) {
if ($metadata->name === $this->getMetadataFor($discriminatorClass)->getName()) {
$metadata->discriminatorValue = $discriminatorValue;
}
}
}
}
array_map([$this, 'populateDiscriminatorValue'], array_map([$this, 'getMetadataFor'], $loaded));
return $loaded;
}
@ -313,6 +302,29 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory
return new ClassMetadata($className, $this->em->getConfiguration()->getNamingStrategy());
}
/**
* Populates the discriminator value of the given metadata (if not set) by iterating over discriminator
* map classes and looking for a fitting one.
*
* @param ClassMetadata $metadata
*
* @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);
}
}
/**
* Adds a default discriminator map if no one is given
*