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


PHP ClassMetadataInfo::getReflectionClass方法代碼示例

本文整理匯總了PHP中Doctrine\ODM\MongoDB\Mapping\ClassMetadataInfo::getReflectionClass方法的典型用法代碼示例。如果您正苦於以下問題:PHP ClassMetadataInfo::getReflectionClass方法的具體用法?PHP ClassMetadataInfo::getReflectionClass怎麽用?PHP ClassMetadataInfo::getReflectionClass使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Doctrine\ODM\MongoDB\Mapping\ClassMetadataInfo的用法示例。


在下文中一共展示了ClassMetadataInfo::getReflectionClass方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: loadMetadataForClass

 /**
  * {@inheritdoc}
  */
 public function loadMetadataForClass($className, ClassMetadataInfo $class)
 {
     $reflClass = $class->getReflectionClass();
     $classAnnotations = $this->reader->getClassAnnotations($reflClass);
     if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\Document'])) {
         $documentAnnot = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\Document'];
     } elseif (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\MappedSuperclass'])) {
         $documentAnnot = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\MappedSuperclass'];
         $class->isMappedSuperclass = true;
     } elseif (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\EmbeddedDocument'])) {
         $documentAnnot = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\EmbeddedDocument'];
         $class->isEmbeddedDocument = true;
     } else {
         throw MongoDBException::classIsNotAValidDocument($className);
     }
     if (isset($documentAnnot->db)) {
         $class->setDatabase($documentAnnot->db);
     }
     if (isset($documentAnnot->collection)) {
         $class->setCollection($documentAnnot->collection);
     }
     if (isset($documentAnnot->repositoryClass)) {
         $class->setCustomRepositoryClass($documentAnnot->repositoryClass);
     }
     if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\Indexes'])) {
         $indexes = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\Indexes']->value;
         $indexes = is_array($indexes) ? $indexes : array($indexes);
         foreach ($indexes as $index) {
             $this->addIndex($class, $index);
         }
     }
     if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\Index'])) {
         $index = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\Index'];
         $this->addIndex($class, $index);
     }
     if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\UniqueIndex'])) {
         $index = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\UniqueIndex'];
         $this->addIndex($class, $index);
     }
     if (isset($documentAnnot->indexes)) {
         foreach ($documentAnnot->indexes as $index) {
             $this->addIndex($class, $index);
         }
     }
     if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\InheritanceType'])) {
         $inheritanceTypeAnnot = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\InheritanceType'];
         $class->setInheritanceType(constant('Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadata::INHERITANCE_TYPE_' . $inheritanceTypeAnnot->value));
     }
     if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\DiscriminatorField'])) {
         $discrFieldAnnot = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\DiscriminatorField'];
         $class->setDiscriminatorField(array('fieldName' => $discrFieldAnnot->fieldName));
     }
     if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\DiscriminatorMap'])) {
         $discrMapAnnot = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\DiscriminatorMap'];
         $class->setDiscriminatorMap($discrMapAnnot->value);
     }
     if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\DiscriminatorValue'])) {
         $discrValueAnnot = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\DiscriminatorValue'];
         $class->setDiscriminatorValue($discrValueAnnot->value);
     }
     if (isset($classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\ChangeTrackingPolicy'])) {
         $changeTrackingAnnot = $classAnnotations['Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\ChangeTrackingPolicy'];
         $class->setChangeTrackingPolicy(constant('Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadata::CHANGETRACKING_' . $changeTrackingAnnot->value));
     }
     $methods = $reflClass->getMethods();
     foreach ($reflClass->getProperties() as $property) {
         if ($class->isMappedSuperclass && !$property->isPrivate() || $class->isInheritedField($property->name)) {
             continue;
         }
         $mapping = array();
         $mapping['fieldName'] = $property->getName();
         if ($alsoLoad = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\AlsoLoad')) {
             $mapping['alsoLoadFields'] = (array) $alsoLoad->value;
         }
         if ($notSaved = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\NotSaved')) {
             $mapping['notSaved'] = true;
         }
         if ($versionAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\Version')) {
             $mapping['version'] = true;
         }
         if ($versionAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\Lock')) {
             $mapping['lock'] = true;
         }
         $indexes = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\Indexes');
         $indexes = $indexes ? $indexes : array();
         if ($index = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\Index')) {
             $indexes[] = $index;
         }
         if ($index = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\UniqueIndex')) {
             $indexes[] = $index;
         }
         foreach ($this->reader->getPropertyAnnotations($property) as $fieldAnnot) {
             if ($fieldAnnot instanceof \Doctrine\ODM\MongoDB\Mapping\Annotations\AbstractField) {
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 $class->mapField($mapping);
             }
         }
//.........這裏部分代碼省略.........
開發者ID:JasonOcean,項目名稱:iOS_Interest_Group,代碼行數:101,代碼來源:AnnotationDriver.php

示例2: loadMetadataForClass

    /**
     * {@inheritdoc}
     */
    public function loadMetadataForClass($className, ClassMetadataInfo $class)
    {
        $reflClass = $class->getReflectionClass();

        $documentAnnots = array();
        foreach ($this->reader->getClassAnnotations($reflClass) as $annot) {
            foreach (self::$documentAnnotationClasses as $i => $annotClass) {
                if ($annot instanceof $annotClass) {
                    $documentAnnots[$i] = $annot;
                    continue 2;
                }
            }

            // non-document class annotations
            if ($annot instanceof ODM\AbstractIndex) {
                $this->addIndex($class, $annot);
            }
            if ($annot instanceof ODM\Indexes) {
                foreach (is_array($annot->value) ? $annot->value : array($annot->value) as $index) {
                    $this->addIndex($class, $index);
                }
            } elseif ($annot instanceof ODM\InheritanceType) {
                $class->setInheritanceType(constant('Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadata::INHERITANCE_TYPE_'.$annot->value));
            } elseif ($annot instanceof ODM\DiscriminatorField) {
                $class->setDiscriminatorField(array('fieldName' => $annot->fieldName));
            } elseif ($annot instanceof ODM\DiscriminatorMap) {
                $class->setDiscriminatorMap($annot->value);
            } elseif ($annot instanceof ODM\DiscriminatorValue) {
                $class->setDiscriminatorValue($annot->value);
            } elseif ($annot instanceof ODM\ChangeTrackingPolicy) {
                $class->setChangeTrackingPolicy(constant('Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadata::CHANGETRACKING_'.$annot->value));
            }

        }

        if (!$documentAnnots) {
            throw MongoDBException::classIsNotAValidDocument($className);
        }

        // find the winning document annotation
        ksort($documentAnnots);
        $documentAnnot = reset($documentAnnots);

        if ($documentAnnot instanceof ODM\MappedSuperclass) {
            $class->isMappedSuperclass = true;
        } elseif ($documentAnnot instanceof ODM\EmbeddedDocument) {
            $class->isEmbeddedDocument = true;
        }
        if (isset($documentAnnot->db)) {
            $class->setDatabase($documentAnnot->db);
        }
        if (isset($documentAnnot->collection)) {
            $class->setCollection($documentAnnot->collection);
        }
        if (isset($documentAnnot->repositoryClass)) {
            $class->setCustomRepositoryClass($documentAnnot->repositoryClass);
        }
        if (isset($documentAnnot->indexes)) {
            foreach ($documentAnnot->indexes as $index) {
                $this->addIndex($class, $index);
            }
        }

        foreach ($reflClass->getProperties() as $property) {
            if ($class->isMappedSuperclass && !$property->isPrivate() || $class->isInheritedField($property->name)) {
                continue;
            }

            $indexes = array();
            $mapping = array('fieldName' => $property->getName());
            $fieldAnnot = null;

            foreach ($this->reader->getPropertyAnnotations($property) as $annot) {
                if ($annot instanceof ODM\AbstractField) {
                    $fieldAnnot = $annot;
                }
                if ($annot instanceof ODM\AbstractIndex) {
                    $indexes[] = $annot;
                }
                if ($annot instanceof ODM\Indexes) {
                    foreach (is_array($annot->value) ? $annot->value : array($annot->value) as $index) {
                        $indexes[] = $index;
                    }
                } elseif ($annot instanceof ODM\AlsoLoad) {
                    $mapping['alsoLoadFields'] = (array) $annot->value;
                } elseif ($annot instanceof ODM\Version) {
                    $mapping['version'] = true;
                } elseif ($annot instanceof ODM\Lock) {
                    $mapping['lock'] = true;
                }
            }

            if ($fieldAnnot) {
                $mapping = array_replace($mapping, (array) $fieldAnnot);
                $class->mapField($mapping);
            }

//.........這裏部分代碼省略.........
開發者ID:royra,項目名稱:mongodb-odm,代碼行數:101,代碼來源:AnnotationDriver.php


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