#1130 DDC-3300 - refactoring auto-remapping of discriminator value into a private method
This commit is contained in:
parent
c589b5d013
commit
786c34faa5
@ -79,18 +79,7 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory
|
|||||||
/* @var $loaded string[] */
|
/* @var $loaded string[] */
|
||||||
$loaded = parent::loadMetadata($name);
|
$loaded = parent::loadMetadata($name);
|
||||||
|
|
||||||
foreach ($loaded as $className) {
|
array_map([$this, 'populateDiscriminatorValue'], array_map([$this, 'getMetadataFor'], $loaded));
|
||||||
/* @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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $loaded;
|
return $loaded;
|
||||||
}
|
}
|
||||||
@ -313,6 +302,29 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory
|
|||||||
return new ClassMetadata($className, $this->em->getConfiguration()->getNamingStrategy());
|
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
|
* Adds a default discriminator map if no one is given
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user