本文整理汇总了PHP中Doctrine\ORM\Mapping\MappingException::duplicateDiscriminatorEntry方法的典型用法代码示例。如果您正苦于以下问题:PHP MappingException::duplicateDiscriminatorEntry方法的具体用法?PHP MappingException::duplicateDiscriminatorEntry怎么用?PHP MappingException::duplicateDiscriminatorEntry使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Mapping\MappingException
的用法示例。
在下文中一共展示了MappingException::duplicateDiscriminatorEntry方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addDefaultDiscriminatorMap
/**
* Adds a default discriminator map if no one is given
*
* If an entity is of any inheritance type and does not contain a
* discriminator map, then the map is generated automatically. This process
* is expensive computation wise.
*
* The automatically generated discriminator map contains the lowercase short name of
* each class as key.
*
* @param \Doctrine\ORM\Mapping\ClassMetadata $class
*
* @throws MappingException
*/
private function addDefaultDiscriminatorMap(ClassMetadata $class)
{
$allClasses = $this->driver->getAllClassNames();
$fqcn = $class->getName();
$map = array($this->getShortName($class->name) => $fqcn);
$duplicates = array();
foreach ($allClasses as $subClassCandidate) {
if (is_subclass_of($subClassCandidate, $fqcn)) {
$shortName = $this->getShortName($subClassCandidate);
if (isset($map[$shortName])) {
$duplicates[] = $shortName;
}
$map[$shortName] = $subClassCandidate;
}
}
if ($duplicates) {
throw MappingException::duplicateDiscriminatorEntry($class->name, $duplicates, $map);
}
$class->setDiscriminatorMap($map);
}
示例2: processDiscriminatorValues
/**
* Collecting discriminator map entries from child classes for entities with inheritance not equals NONE
*
* @param ClassMetadata $class
* @param EntityManager $em
*
* @throws MappingException
*/
protected function processDiscriminatorValues(ClassMetadata $class, EntityManager $em)
{
if (!$class->isInheritanceTypeNone()) {
if ($class->isRootEntity()) {
$allClasses = $em->getConfiguration()->getMetadataDriverImpl()->getAllClassNames();
$FQCN = $class->getName();
$map = $class->discriminatorMap ?: [];
$duplicates = [];
foreach ($allClasses as $subClassCandidate) {
if (is_subclass_of($subClassCandidate, $FQCN) && !in_array($subClassCandidate, $map, true)) {
$value = $this->getDiscriminatorValue($em->getMetadataFactory(), $subClassCandidate);
if (null !== $value) {
if (isset($map[$value])) {
$duplicates[] = $value;
}
$map[$value] = $subClassCandidate;
}
}
}
if ($duplicates) {
throw MappingException::duplicateDiscriminatorEntry($class->getName(), $duplicates, $map);
}
$class->setDiscriminatorMap($map);
$this->collectedMaps = array_merge($this->collectedMaps, array_fill_keys(array_values($map), $map));
} elseif (isset($this->collectedMaps[$class->name]) && $class->discriminatorMap !== $this->collectedMaps[$class->name]) {
$class->setDiscriminatorMap($this->collectedMaps[$class->name]);
}
}
}