当前位置: 首页>>代码示例>>PHP>>正文


PHP ClassMetadata::setInheritMixins方法代码示例

本文整理汇总了PHP中Doctrine\Common\Persistence\Mapping\ClassMetadata::setInheritMixins方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadata::setInheritMixins方法的具体用法?PHP ClassMetadata::setInheritMixins怎么用?PHP ClassMetadata::setInheritMixins使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Doctrine\Common\Persistence\Mapping\ClassMetadata的用法示例。


在下文中一共展示了ClassMetadata::setInheritMixins方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: loadMetadataForClass

 /**
  * {@inheritdoc}
  */
 public function loadMetadataForClass($className, ClassMetadata $class)
 {
     /** @var $class \Doctrine\ODM\PHPCR\Mapping\ClassMetadata */
     try {
         $element = $this->getElement($className);
     } catch (DoctrineMappingException $e) {
         // Convert Exception type for consistency with other drivers
         throw new MappingException($e->getMessage(), $e->getCode(), $e);
     }
     if (!$element) {
         return;
     }
     $element['type'] = isset($element['type']) ? $element['type'] : 'document';
     if (isset($element['repositoryClass'])) {
         $class->setCustomRepositoryClassName($element['repositoryClass']);
     }
     if (isset($element['translator'])) {
         $class->setTranslator($element['translator']);
     }
     if (isset($element['versionable']) && $element['versionable']) {
         $class->setVersioned($element['versionable']);
     }
     if (isset($element['referenceable']) && $element['referenceable']) {
         $class->setReferenceable($element['referenceable']);
     }
     if (isset($element['uniqueNodeType']) && $element['uniqueNodeType']) {
         $class->setUniqueNodeType($element['uniqueNodeType']);
     }
     if (isset($element['mixins'])) {
         $mixins = array();
         foreach ($element['mixins'] as $mixin) {
             $mixins[] = $mixin;
         }
         $class->setMixins($mixins);
     }
     if (isset($element['inheritMixins'])) {
         $class->setInheritMixins($element['inheritMixins']);
     }
     if (isset($element['nodeType'])) {
         $class->setNodeType($element['nodeType']);
     }
     if ($element['type'] === 'mappedSuperclass') {
         $class->isMappedSuperclass = true;
     }
     if (isset($element['fields'])) {
         foreach ($element['fields'] as $fieldName => $mapping) {
             if (is_string($mapping)) {
                 $type = $mapping;
                 $mapping = array();
                 $mapping['type'] = $type;
             }
             if (!isset($mapping['fieldName'])) {
                 $mapping['fieldName'] = $fieldName;
             }
             $class->mapField($mapping);
         }
     }
     if (isset($element['uuid'])) {
         $mapping = array('fieldName' => $element['uuid'], 'uuid' => true);
         $class->mapField($mapping);
     }
     if (isset($element['id'])) {
         if (is_array($element['id'])) {
             if (!isset($element['id']['fieldName'])) {
                 throw new MappingException("Missing fieldName property for id field");
             }
             $fieldName = $element['id']['fieldName'];
         } else {
             $fieldName = $element['id'];
         }
         $mapping = array('fieldName' => $fieldName, 'id' => true);
         if (isset($element['id']['generator']['strategy'])) {
             $mapping['strategy'] = $element['id']['generator']['strategy'];
         }
         $class->mapId($mapping);
     }
     if (isset($element['node'])) {
         $class->mapNode(array('fieldName' => $element['node']));
     }
     if (isset($element['nodename'])) {
         $class->mapNodename(array('fieldName' => $element['nodename']));
     }
     if (isset($element['parentdocument'])) {
         $mapping = array('fieldName' => $element['parentdocument'], 'cascade' => isset($element['cascade']) ? $this->getCascadeMode($element['cascade']) : 0);
         $class->mapParentDocument($mapping);
     }
     if (isset($element['child'])) {
         foreach ($element['child'] as $fieldName => $mapping) {
             if (is_string($mapping)) {
                 $name = $mapping;
                 $mapping = array();
                 $mapping['nodeName'] = $name;
             }
             if (!isset($mapping['fieldName'])) {
                 $mapping['fieldName'] = $fieldName;
             }
             $mapping['cascade'] = isset($mapping['cascade']) ? $this->getCascadeMode($mapping['cascade']) : 0;
//.........这里部分代码省略.........
开发者ID:steffenbrem,项目名称:phpcr-odm,代码行数:101,代码来源:YamlDriver.php

示例2: loadMetadataForClass

 /**
  * {@inheritdoc}
  */
 public function loadMetadataForClass($className, ClassMetadata $metadata)
 {
     /** @var $metadata \Doctrine\ODM\PHPCR\Mapping\ClassMetadata */
     $reflClass = $metadata->getReflectionClass();
     $documentAnnots = array();
     foreach ($this->reader->getClassAnnotations($reflClass) as $annot) {
         foreach ($this->entityAnnotationClasses as $annotClass => $i) {
             if ($annot instanceof $annotClass) {
                 $documentAnnots[$i] = $annot;
             }
         }
     }
     if (!$documentAnnots) {
         throw MappingException::classIsNotAValidDocument($className);
     }
     // find the winning document annotation
     ksort($documentAnnots);
     $documentAnnot = reset($documentAnnots);
     if ($documentAnnot instanceof ODM\MappedSuperclass) {
         $metadata->isMappedSuperclass = true;
     }
     if (null !== $documentAnnot->referenceable) {
         $metadata->setReferenceable($documentAnnot->referenceable);
     }
     if (null !== $documentAnnot->versionable) {
         $metadata->setVersioned($documentAnnot->versionable);
     }
     if (null !== $documentAnnot->mixins) {
         $metadata->setMixins($documentAnnot->mixins);
     }
     if (null !== $documentAnnot->inheritMixins) {
         $metadata->setInheritMixins($documentAnnot->inheritMixins);
     }
     if (null !== $documentAnnot->nodeType) {
         $metadata->setNodeType($documentAnnot->nodeType);
     }
     if (null !== $documentAnnot->repositoryClass) {
         $metadata->setCustomRepositoryClassName($documentAnnot->repositoryClass);
     }
     if (null !== $documentAnnot->translator) {
         $metadata->setTranslator($documentAnnot->translator);
     }
     foreach ($reflClass->getProperties() as $property) {
         if ($metadata->isInheritedField($property->name) && $metadata->name !== $property->getDeclaringClass()->getName()) {
             continue;
         }
         $mapping = array();
         $mapping['fieldName'] = $property->getName();
         foreach ($this->reader->getPropertyAnnotations($property) as $fieldAnnot) {
             if ($fieldAnnot instanceof ODM\Property) {
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 $metadata->mapField($mapping);
             } elseif ($fieldAnnot instanceof ODM\Id) {
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 $metadata->mapId($mapping);
             } elseif ($fieldAnnot instanceof ODM\Node) {
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 $metadata->mapNode($mapping);
             } elseif ($fieldAnnot instanceof ODM\Nodename) {
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 $metadata->mapNodename($mapping);
             } elseif ($fieldAnnot instanceof ODM\ParentDocument) {
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 $mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade);
                 $metadata->mapParentDocument($mapping);
             } elseif ($fieldAnnot instanceof ODM\Child) {
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 $mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade);
                 $metadata->mapChild($mapping);
             } elseif ($fieldAnnot instanceof ODM\Children) {
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 $mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade);
                 $metadata->mapChildren($mapping);
             } elseif ($fieldAnnot instanceof ODM\ReferenceOne) {
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 $mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade);
                 $metadata->mapManyToOne($mapping);
             } elseif ($fieldAnnot instanceof ODM\ReferenceMany) {
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 $mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade);
                 $metadata->mapManyToMany($mapping);
             } elseif ($fieldAnnot instanceof ODM\Referrers) {
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 $mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade);
                 $metadata->mapReferrers($mapping);
             } elseif ($fieldAnnot instanceof ODM\MixedReferrers) {
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 $metadata->mapMixedReferrers($mapping);
             } elseif ($fieldAnnot instanceof ODM\Locale) {
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 $metadata->mapLocale($mapping);
             } elseif ($fieldAnnot instanceof ODM\Depth) {
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 $metadata->mapDepth($mapping);
             } elseif ($fieldAnnot instanceof ODM\VersionName) {
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 $metadata->mapVersionName($mapping);
//.........这里部分代码省略.........
开发者ID:pkdevbox,项目名称:phpcr-odm,代码行数:101,代码来源:AnnotationDriver.php

示例3: loadMetadataForClass

 /**
  * {@inheritdoc}
  */
 public function loadMetadataForClass($className, ClassMetadata $class)
 {
     /** @var $class \Doctrine\ODM\PHPCR\Mapping\ClassMetadata */
     try {
         $xmlRoot = $this->getElement($className);
     } catch (DoctrineMappingException $e) {
         // Convert Exception type for consistency with other drivers
         throw new MappingException($e->getMessage(), $e->getCode(), $e);
     }
     if (!$xmlRoot) {
         return;
     }
     if (isset($xmlRoot['repository-class'])) {
         $class->setCustomRepositoryClassName((string) $xmlRoot['repository-class']);
     }
     if (isset($xmlRoot['translator'])) {
         $class->setTranslator((string) $xmlRoot['translator']);
     }
     if (isset($xmlRoot['versionable']) && $xmlRoot['versionable'] !== 'false') {
         $class->setVersioned(strtolower($xmlRoot['versionable']));
     }
     if (isset($xmlRoot['referenceable']) && $xmlRoot['referenceable'] !== 'false') {
         $class->setReferenceable((bool) $xmlRoot['referenceable']);
     }
     if (isset($xmlRoot['uniqueNodeType']) && $xmlRoot['uniqueNodeType'] !== 'false') {
         $class->setUniqueNodeType((bool) $xmlRoot['uniqueNodeType']);
     }
     if (isset($xmlRoot['is-leaf'])) {
         if (!in_array($value = $xmlRoot['is-leaf'], array('true', 'false'))) {
             throw new MappingException(sprintf('Value of is-leaf must be "true" or "false", got "%s" for class "%s"', $value, $className));
         }
         $class->setIsLeaf($value == 'true' ? true : false);
     }
     if (isset($xmlRoot->mixins)) {
         $mixins = array();
         foreach ($xmlRoot->mixins->mixin as $mixin) {
             $attributes = $mixin->attributes();
             if (!isset($attributes['type'])) {
                 throw new MappingException('<mixin> missing mandatory type attribute');
             }
             $mixins[] = (string) $attributes['type'];
         }
         $class->setMixins($mixins);
         $attributes = $xmlRoot->mixins->attributes();
         if (isset($attributes['inherit'])) {
             $class->setInheritMixins($attributes['inherit']);
         }
     }
     if (isset($xmlRoot['node-type'])) {
         $class->setNodeType((string) $xmlRoot['node-type']);
     }
     if ($xmlRoot->getName() === 'mapped-superclass') {
         $class->isMappedSuperclass = true;
     }
     if (isset($xmlRoot->field)) {
         foreach ($xmlRoot->field as $field) {
             $mapping = array();
             $attributes = $field->attributes();
             foreach ($attributes as $key => $value) {
                 $mapping[$key] = (string) $value;
                 // convert bool fields
                 if (in_array($key, array('id', 'multivalue', 'assoc', 'translated', 'nullable'))) {
                     $mapping[$key] = 'true' === $mapping[$key] ? true : false;
                 }
             }
             if (!isset($mapping['name'])) {
                 throw new MappingException(sprintf('Missing name attribute for field of %s', $className));
             }
             $mapping['fieldName'] = $mapping['name'];
             unset($mapping['name']);
             $class->mapField($mapping);
         }
     }
     if (isset($xmlRoot->id)) {
         $mapping = array('fieldName' => (string) $xmlRoot->id->attributes()->name, 'id' => true);
         if (isset($xmlRoot->id->generator) && isset($xmlRoot->id->generator->attributes()->strategy)) {
             $mapping['strategy'] = (string) $xmlRoot->id->generator->attributes()->strategy;
         }
         $class->mapId($mapping);
     }
     if (isset($xmlRoot->node)) {
         $class->mapNode(array('fieldName' => (string) $xmlRoot->node->attributes()->name));
     }
     if (isset($xmlRoot->nodename)) {
         $class->mapNodename(array('fieldName' => (string) $xmlRoot->nodename->attributes()->name));
     }
     if (isset($xmlRoot->{'parent-document'})) {
         $mapping = array('fieldName' => (string) $xmlRoot->{'parent-document'}->attributes()->name, 'cascade' => isset($xmlRoot->{'parent-document'}->cascade) ? $this->getCascadeMode($xmlRoot->{'parent-document'}->cascade) : 0);
         $class->mapParentDocument($mapping);
     }
     if (isset($xmlRoot->child)) {
         foreach ($xmlRoot->child as $child) {
             $attributes = $child->attributes();
             $mapping = array('fieldName' => (string) $attributes->name, 'cascade' => isset($child->cascade) ? $this->getCascadeMode($child->cascade) : 0);
             if (isset($attributes['node-name'])) {
                 $mapping['nodeName'] = (string) $attributes->{'node-name'};
             }
//.........这里部分代码省略.........
开发者ID:doctrine,项目名称:phpcr-odm,代码行数:101,代码来源:XmlDriver.php


注:本文中的Doctrine\Common\Persistence\Mapping\ClassMetadata::setInheritMixins方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。