本文整理汇总了PHP中Doctrine\ORM\Mapping\ClassMetadata::setDiscriminatorMap方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadata::setDiscriminatorMap方法的具体用法?PHP ClassMetadata::setDiscriminatorMap怎么用?PHP ClassMetadata::setDiscriminatorMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Mapping\ClassMetadata
的用法示例。
在下文中一共展示了ClassMetadata::setDiscriminatorMap方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: updateDiscriminator
/**
* Update the discriminator map
* @param \Doctrine\ORM\Mapping\ClassMetadata $metadata
* @param \Doctrine\ORM\EntityManager $em
*/
private function updateDiscriminator(\Doctrine\ORM\Mapping\ClassMetadata $metadata, \Doctrine\ORM\EntityManager $em)
{
if ($metadata->name == 'Nella\Media\FileEntity' || in_array('Nella\Media\FileEntity', $metadata->parentClasses)) {
$metadata->setDiscriminatorMap(array_merge($metadata->discriminatorMap, $this->fileMap));
} elseif ($metadata->name == 'Nella\Media\ImageEntity' || in_array('Nella\Media\ImageEntity', $metadata->parentClasses)) {
$metadata->setDiscriminatorMap(array_merge($metadata->discriminatorMap, $this->imageMap));
}
}
示例2: testSetDiscriminatorMapInGlobalNamespace
/**
* @group DDC-115
*/
public function testSetDiscriminatorMapInGlobalNamespace()
{
require_once __DIR__ . "/../../Models/Global/GlobalNamespaceModel.php";
$cm = new ClassMetadata('DoctrineGlobal_User');
$cm->setDiscriminatorMap(array('descr' => 'DoctrineGlobal_Article', 'foo' => 'DoctrineGlobal_User'));
$this->assertEquals("DoctrineGlobal_Article", $cm->discriminatorMap['descr']);
$this->assertEquals("DoctrineGlobal_User", $cm->discriminatorMap['foo']);
}
示例3: setupProfileDiscriminator
protected function setupProfileDiscriminator(ClassMetadata $metadata)
{
// Set inheritence type
$metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_JOINED);
// Set not mapped superclass
$metadata->isMappedSuperclass = false;
// Set discriminator column
$metadata->setDiscriminatorColumn(['name' => 'discr', 'type' => 'string', 'length' => 20]);
// Set map
$metadata->setDiscriminatorMap(['user' => $this->profile, 'admin' => $this->adminProfile]);
}
示例4: 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);
}
示例5: testSetDiscriminatorMapInGlobalNamespace
/**
* @group DDC-115
*/
public function testSetDiscriminatorMapInGlobalNamespace()
{
require_once __DIR__ . "/../../Models/Global/GlobalNamespaceModel.php";
$cm = new ClassMetadata('DoctrineGlobal_User');
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
$cm->setDiscriminatorMap(array('descr' => 'DoctrineGlobal_Article', 'foo' => 'DoctrineGlobal_User'));
$this->assertEquals("DoctrineGlobal_Article", $cm->discriminatorMap['descr']);
$this->assertEquals("DoctrineGlobal_User", $cm->discriminatorMap['foo']);
}
示例6: getNodesSourcesMetadata
/**
* Get NodesSources class metadata.
*
* @return Doctrine\ORM\Mapping\ClassMetadata
*/
public static function getNodesSourcesMetadata()
{
$metadata = new ClassMetadata('RZ\\Roadiz\\Core\\Entities\\NodesSources');
try {
/**
* List node types
*/
$nodeTypes = Kernel::getService('em')->getRepository('RZ\\Roadiz\\Core\\Entities\\NodeType')->findAll();
$map = [];
foreach ($nodeTypes as $type) {
$map[strtolower($type->getName())] = NodeType::getGeneratedEntitiesNamespace() . '\\' . $type->getSourceEntityClassName();
}
$metadata->setDiscriminatorMap($map);
return $metadata;
} catch (\PDOException $e) {
/*
* Database tables don't exist yet
* Need Install
*/
return null;
}
}
示例7: 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]);
}
}
}