當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ClassMetadata::setDiscriminatorMap方法代碼示例

本文整理匯總了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));
    	}
	}
開發者ID:norbe,項目名稱:framework,代碼行數:13,代碼來源:Listener.php

示例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']);
 }
開發者ID:andreia,項目名稱:doctrine,代碼行數:11,代碼來源:ClassMetadataTest.php

示例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]);
 }
開發者ID:symedit,項目名稱:symedit,代碼行數:11,代碼來源:MetadataSubscriber.php

示例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);
 }
開發者ID:dracony,項目名稱:forked-php-orm-benchmark,代碼行數:34,代碼來源:ClassMetadataFactory.php

示例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']);
 }
開發者ID:dracony,項目名稱:forked-php-orm-benchmark,代碼行數:12,代碼來源:ClassMetadataTest.php

示例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;
     }
 }
開發者ID:bryanbanda,項目名稱:roadiz,代碼行數:27,代碼來源:DataInheritanceEvent.php

示例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]);
         }
     }
 }
開發者ID:Maksold,項目名稱:platform,代碼行數:37,代碼來源:DoctrineListener.php


注:本文中的Doctrine\ORM\Mapping\ClassMetadata::setDiscriminatorMap方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。