• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Mapping\ClassMetadataInfo类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中Doctrine\ODM\MongoDB\Mapping\ClassMetadataInfo的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadataInfo类的具体用法?PHP ClassMetadataInfo怎么用?PHP ClassMetadataInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: read

 /**
  * Convert thrift class spec to doctrine ClassMetadataInfo
  *
  * @param $className
  * @return ClassMetadataInfo
  * @throws \Doctrine\ODM\MongoDB\Mapping\MappingException
  * @throws \Exception
  */
 public function read($className)
 {
     $cmi = new ClassMetadataInfo($className);
     $types = array(TType::BOOL => 'bool', TType::I32 => 'integer', TType::I64 => 'integer', TType::DOUBLE => 'float', TType::UTF7 => 'string', TType::UTF8 => 'string', TType::LST => 'many', TType::STRUCT => 'one', TType::MAP => 'hash');
     $spec = $this->loadSpec($className);
     foreach ($spec as $id => $fieldSpec) {
         if (!isset($types[$fieldSpec['type']])) {
             throw new \Exception('Unknown thrift -> doctrine type conversion');
         }
         $type = $types[$fieldSpec['type']];
         if ($fieldSpec['type'] == TType::LST) {
             // list
             if ($fieldSpec['etype'] == TType::STRUCT) {
                 // list of structs
                 $mapping = array('fieldName' => $fieldSpec['var'], 'name' => $id . '_' . $fieldSpec['var'], 'embedded' => true, 'type' => $type, 'targetDocument' => substr($fieldSpec['elem']['class'], 1));
             } else {
                 // list of simple types
                 $mapping = array('fieldName' => $fieldSpec['var'], 'name' => $id . '_' . $fieldSpec['var'], 'type' => 'hash');
             }
         } elseif ($fieldSpec['type'] == TType::STRUCT) {
             // single struct
             $mapping = array('fieldName' => $fieldSpec['var'], 'name' => $id . '_' . $fieldSpec['var'], 'embedded' => true, 'type' => $type, 'targetDocument' => substr($fieldSpec['class'], 1));
         } else {
             // simple field
             $mapping = array('fieldName' => $fieldSpec['var'], 'name' => $id . '_' . $fieldSpec['var'], 'type' => $type);
         }
         $cmi->mapField($mapping);
     }
     return $cmi;
 }
开发者ID:AlexeyKupershtokh,项目名称:ThriftDoctrineBundle,代码行数:38,代码来源:Reader.php


示例2: getODMTransformerInfo

 /**
  * @param ColumnInfoInterface         $columnInfo
  * @param ODMMongoDBClassMetadataInfo $metadata
  *
  * @return array
  */
 private function getODMTransformerInfo(ColumnInfoInterface $columnInfo, ODMMongoDBClassMetadataInfo $metadata)
 {
     $fieldName = $columnInfo->getPropertyPath();
     if (in_array($metadata->getTypeOfField($fieldName), ['entity', 'entities'])) {
         $mapping = $metadata->getFieldMapping($fieldName);
         $target = $mapping['targetEntity'];
         if (!$this->doctrine->getRepository($target) instanceof ReferableEntityRepositoryInterface) {
             return;
         }
         return array($this->transformer, array('class' => $target, 'multiple' => 'entities' === $metadata->getTypeOfField($fieldName)));
     }
     if (in_array($metadata->getTypeOfField($fieldName), ['one', 'many'])) {
         $mapping = $metadata->getFieldMapping($fieldName);
         $target = $mapping['targetDocument'];
         // TODO Remove this hack
         switch ($target) {
             case 'Pim\\Bundle\\CatalogBundle\\Model\\ProductPrice':
             case 'Pim\\Bundle\\CatalogBundle\\Model\\Metric':
                 return;
         }
         if (!$this->doctrine->getRepository($target) instanceof ReferableEntityRepositoryInterface) {
             return;
         }
         return array($this->transformer, array('class' => $mapping['targetDocument'], 'multiple' => 'many' === $metadata->getTypeOfField($fieldName)));
     }
 }
开发者ID:javiersantos,项目名称:pim-community-dev,代码行数:32,代码来源:RelationGuesser.php


示例3: getFieldsFromMetadata

 /**
  * Returns an array of fields. Fields can be both column fields and
  * association fields.
  *
  * @param \Doctrine\ODM\MongoDB\Mapping\ClassMetadataInfo $metadata
  *
  * @return array
  */
 private function getFieldsFromMetadata(ClassMetadataInfo $metadata)
 {
     $fields = (array) $metadata->getFieldNames();
     // Remove the primary key field if it's not managed manually
     if ($metadata->isIdGeneratorAuto()) {
         $fields = array_diff($fields, array($metadata->identifier));
     }
     return $fields;
 }
开发者ID:ReservedDeveloper,项目名称:IsmaAmbrosiGeneratorBundle,代码行数:17,代码来源:DoctrineFormGenerator.php


示例4: testOwningSideAndInverseSide

 public function testOwningSideAndInverseSide()
 {
     $cm = new ClassMetadataInfo('Documents\\User');
     $cm->mapManyReference(array('fieldName' => 'articles', 'inversedBy' => 'user'));
     $this->assertTrue($cm->fieldMappings['articles']['isOwningSide']);
     $cm = new ClassMetadataInfo('Documents\\Article');
     $cm->mapOneReference(array('fieldName' => 'user', 'mappedBy' => 'articles'));
     $this->assertTrue($cm->fieldMappings['user']['isInverseSide']);
 }
开发者ID:roed,项目名称:mongodb-odm,代码行数:9,代码来源:ClassMetadataTest.php


示例5: setUp

 protected function setUp()
 {
     parent::setUp();
     $this->filesystem = new Filesystem();
     $this->documentName = ucfirst($this->getName());
     $this->tmpDir = sys_get_temp_dir() . '/ismaambrosi';
     $this->metadata = new ClassMetadataInfo($this->documentName);
     $this->metadata->mapField(array('name' => 'id', 'id' => true, 'strategy' => 'auto'));
     $this->metadata->mapField(array('fieldName' => 'name', 'type' => 'string'));
     $this->metadata->mapField(array('fieldName' => 'description', 'type' => 'string'));
 }
开发者ID:anhpha,项目名称:reports,代码行数:11,代码来源:GeneratorTestCase.php


示例6:

 function it_configures_the_mappings_of_a_model_that_overrides_an_original_model($configuration, ClassMetadataInfo $metadataInfo, MappingDriver $mappingDriver)
 {
     $originalQux1 = __NAMESPACE__ . '\\OriginalQux1';
     $originalQux2 = __NAMESPACE__ . '\\OriginalQux2';
     $overrideQux1 = __NAMESPACE__ . '\\OverrideQux1';
     $overrideQux2 = __NAMESPACE__ . '\\OverrideQux2';
     $mappingDriver->getAllClassNames()->willReturn([$originalQux1]);
     $configuration->getMetadataDriverImpl()->willReturn($mappingDriver);
     $metadataInfo->getName()->willReturn($overrideQux1);
     $mappingDriver->loadMetadataForClass($originalQux1, Argument::any())->shouldBeCalled();
     $overrides = [['original' => $originalQux1, 'override' => $overrideQux1], ['original' => $originalQux2, 'override' => $overrideQux2]];
     $this->configure($metadataInfo, $overrides, $configuration);
 }
开发者ID:abdeldayem,项目名称:pim-community-dev,代码行数:13,代码来源:MappingsOverrideConfiguratorSpec.php


示例7: setAssociationMappings

 /**
  * Set the association mappings of a metadata.
  *
  * @param ClassMetadataInfo $metadata
  * @param Configuration     $configuration
  */
 protected function setAssociationMappings(ClassMetadataInfo $metadata, Configuration $configuration)
 {
     $supportedClasses = $configuration->getMetadataDriverImpl()->getAllClassNames();
     foreach (class_parents($metadata->getName()) as $parent) {
         if (in_array($parent, $supportedClasses)) {
             $parentMetadata = new MongoClassMetadata($parent);
             $configuration->getMetadataDriverImpl()->loadMetadataForClass($parent, $parentMetadata);
             foreach ($parentMetadata->associationMappings as $key => $value) {
                 if ($this->hasRelation($value['association'])) {
                     $metadata->associationMappings[$key] = $value;
                 }
             }
         }
     }
 }
开发者ID:abdeldayem,项目名称:pim-community-dev,代码行数:21,代码来源:MappingsOverrideConfigurator.php


示例8: setAssociationMappings

 /**
  * @param ClassMetadataInfo $metadata
  * @param $configuration
  */
 private function setAssociationMappings(ClassMetadataInfo $metadata, $configuration)
 {
     foreach (class_parents($metadata->getName()) as $parent) {
         $parentMetadata = new ClassMetadata($parent);
         if (in_array($parent, $configuration->getMetadataDriverImpl()->getAllClassNames())) {
             $configuration->getMetadataDriverImpl()->loadMetadataForClass($parent, $parentMetadata);
             if ($parentMetadata->isMappedSuperclass) {
                 foreach ($parentMetadata->associationMappings as $key => $value) {
                     if ($this->hasRelation($value['association'])) {
                         $metadata->associationMappings[$key] = $value;
                     }
                 }
             }
         }
     }
 }
开发者ID:bendavies,项目名称:Sylius,代码行数:20,代码来源:LoadODMMetadataSubscriber.php


示例9: generateBookDocumentFixture

 public function generateBookDocumentFixture()
 {
     $metadata = new ClassMetadataInfo($this->namespace . '\\DocumentGeneratorBook');
     $metadata->namespace = $this->namespace;
     $metadata->customRepositoryClassName = $this->namespace . '\\DocumentGeneratorBookRepository';
     $metadata->collection = 'book';
     $metadata->mapField(array('fieldName' => 'name', 'type' => 'string'));
     $metadata->mapField(array('fieldName' => 'status', 'type' => 'string'));
     $metadata->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true));
     $metadata->mapOneReference(array('fieldName' => 'author', 'targetDocument' => 'Doctrine\\ODM\\MongoDB\\Tests\\Tools\\DocumentGeneratorAuthor'));
     $metadata->mapManyReference(array('fieldName' => 'comments', 'targetDocument' => 'Doctrine\\ODM\\MongoDB\\Tests\\Tools\\DocumentGeneratorComment'));
     $metadata->addLifecycleCallback('loading', 'postLoad');
     $metadata->addLifecycleCallback('willBeRemoved', 'preRemove');
     $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
     $this->generator->writeDocumentClass($metadata, $this->tmpDir);
     return $metadata;
 }
开发者ID:roed,项目名称:mongodb-odm,代码行数:17,代码来源:DocumentGeneratorTest.php


示例10: generate

 /**
  * @param  \Symfony\Component\HttpKernel\Bundle\BundleInterface $bundle
  * @param  string                                               $document
  * @param  array                                                $fields
  * @param  Boolean                                              $withRepository
  * @throws \RuntimeException
  */
 public function generate(BundleInterface $bundle, $document, array $fields, $withRepository)
 {
     $config = $this->documentManager->getConfiguration();
     $config->addDocumentNamespace($bundle->getName(), $bundle->getNamespace() . '\\Document');
     $documentClass = $config->getDocumentNamespace($bundle->getName()) . '\\' . $document;
     $documentPath = $bundle->getPath() . '/Document/' . str_replace('\\', '/', $document) . '.php';
     if (file_exists($documentPath)) {
         throw new \RuntimeException(sprintf('Document "%s" already exists.', $documentClass));
     }
     $class = new ClassMetadataInfo($documentClass);
     if ($withRepository) {
         $class->setCustomRepositoryClass($documentClass . 'Repository');
     }
     $class->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true));
     $class->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
     foreach ($fields as $field) {
         $class->mapField($field);
     }
     $documentGenerator = $this->getDocumentGenerator();
     $documentCode = $documentGenerator->generateDocumentClass($class);
     $this->filesystem->mkdir(dirname($documentPath));
     file_put_contents($documentPath, rtrim($documentCode) . PHP_EOL, LOCK_EX);
     if ($withRepository) {
         $path = $bundle->getPath() . str_repeat('/..', substr_count(get_class($bundle), '\\'));
         $this->getRepositoryGenerator()->writeDocumentRepositoryClass($class->customRepositoryClassName, $path);
     }
 }
开发者ID:anhpha,项目名称:reports,代码行数:34,代码来源:DoctrineDocumentGenerator.php


示例11: setAssociationMappings

 /**
  * @param ClassMetadataInfo $metadata
  * @param $configuration
  */
 private function setAssociationMappings(ClassMetadataInfo $metadata, $configuration)
 {
     foreach (class_parents($metadata->getName()) as $parent) {
         if (false === in_array($parent, $configuration->getMetadataDriverImpl()->getAllClassNames())) {
             continue;
         }
         $parentMetadata = new ClassMetadata($parent, $configuration->getNamingStrategy());
         // Wakeup Reflection
         $parentMetadata->wakeupReflection($this->getReflectionService());
         // Load Metadata
         $configuration->getMetadataDriverImpl()->loadMetadataForClass($parent, $parentMetadata);
         if (false === $this->isResource($parentMetadata)) {
             continue;
         }
         if ($parentMetadata->isMappedSuperclass) {
             foreach ($parentMetadata->associationMappings as $key => $value) {
                 if ($this->hasRelation($value['association'])) {
                     $metadata->associationMappings[$key] = $value;
                 }
             }
         }
     }
 }
开发者ID:loic425,项目名称:Sylius,代码行数:27,代码来源:ODMMappedSuperClassSubscriber.php


示例12: setShardKey

 /**
  * @param ClassMetadataInfo $class
  * @param ODM\ShardKey      $shardKey
  *
  * @throws MappingException
  */
 private function setShardKey(ClassMetadataInfo $class, ODM\ShardKey $shardKey)
 {
     $options = array();
     $allowed = array('unique', 'numInitialChunks');
     foreach ($allowed as $name) {
         if (isset($shardKey->{$name})) {
             $options[$name] = $shardKey->{$name};
         }
     }
     $class->setShardKey($shardKey->keys, $options);
 }
开发者ID:doctrine,项目名称:mongodb-odm,代码行数:17,代码来源:AnnotationDriver.php


示例13: loadMetadataForClass

    /**
     * {@inheritdoc}
     */
    public function loadMetadataForClass($className, ClassMetadataInfo $class)
    {
        $element = $this->getElement($className);
        if ( ! $element) {
            return;
        }
        $element['type'] = isset($element['type']) ? $element['type'] : 'document';

        if (isset($element['db'])) {
            $class->setDatabase($element['db']);
        }
        if (isset($element['collection'])) {
            $class->setCollection($element['collection']);
        }
        if ($element['type'] == 'document') {
            if (isset($element['repositoryClass'])) {
                $class->setCustomRepositoryClass($element['repositoryClass']);
            }
        } elseif ($element['type'] === 'mappedSuperclass') {
            $class->isMappedSuperclass = true;
        } elseif ($element['type'] === 'embeddedDocument') {
            $class->isEmbeddedDocument = true;
        }
        if (isset($element['indexes'])) {
            foreach($element['indexes'] as $index) {
                $class->addIndex($index['keys'], isset($index['options']) ? $index['options'] : array());
            }
        }
        if (isset($element['inheritanceType'])) {
            $class->setInheritanceType(constant('Doctrine\ODM\MongoDB\Mapping\ClassMetadata::INHERITANCE_TYPE_' . strtoupper($element['inheritanceType'])));
        }
        if (isset($element['discriminatorField'])) {
            $discrField = $element['discriminatorField'];
            $class->setDiscriminatorField(array(
                'name' => $discrField['name'],
                'fieldName' => $discrField['fieldName']
            ));
        }
        if (isset($element['discriminatorMap'])) {
            $class->setDiscriminatorMap($element['discriminatorMap']);
        }
        if (isset($element['changeTrackingPolicy'])) {
            $class->setChangeTrackingPolicy(constant('Doctrine\ODM\MongoDB\Mapping\ClassMetadata::CHANGETRACKING_'
                    . strtoupper($element['changeTrackingPolicy'])));
        }
        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;
                }
                if (isset($mapping['type']) && $mapping['type'] === 'collection') {
                    $mapping['strategy'] = isset($mapping['strategy']) ? $mapping['strategy'] : 'pushAll';
                }
                $this->addFieldMapping($class, $mapping);
            }
        }
        if (isset($element['embedOne'])) {
            foreach ($element['embedOne'] as $fieldName => $embed) {
                $this->addMappingFromEmbed($class, $fieldName, $embed, 'one');
            }
        }
        if (isset($element['embedMany'])) {
            foreach ($element['embedMany'] as $fieldName => $embed) {
                $this->addMappingFromEmbed($class, $fieldName, $embed, 'many');
            }
        }
        if (isset($element['referenceOne'])) {
            foreach ($element['referenceOne'] as $fieldName => $reference) {
                $this->addMappingFromReference($class, $fieldName, $reference, 'one');
            }
        }
        if (isset($element['referenceMany'])) {
            foreach ($element['referenceMany'] as $fieldName => $reference) {
                $this->addMappingFromReference($class, $fieldName, $reference, 'many');
            }
        }
        if (isset($element['lifecycleCallbacks'])) {
            foreach ($element['lifecycleCallbacks'] as $type => $methods) {
                foreach ($methods as $method) {
                    $class->addLifecycleCallback($method, constant('Doctrine\ODM\MongoDB\Events::' . $type));
                }
            }
        }
    }
开发者ID:royra,项目名称:mongodb-odm,代码行数:92,代码来源:YamlDriver.php


示例14: addFieldMapping

 private function addFieldMapping(ClassMetadataInfo $class, $mapping)
 {
     if (isset($mapping['name'])) {
         $name = $mapping['name'];
     } elseif (isset($mapping['fieldName'])) {
         $name = $mapping['fieldName'];
     } else {
         throw new \InvalidArgumentException('Cannot infer a MongoDB name from the mapping');
     }
     $class->mapField($mapping);
     if (!(isset($mapping['index']) || isset($mapping['unique']) || isset($mapping['sparse']))) {
         return;
     }
     // Multiple index specifications in one field mapping is ambiguous
     if ((isset($mapping['index']) && is_array($mapping['index'])) + (isset($mapping['unique']) && is_array($mapping['unique'])) + (isset($mapping['sparse']) && is_array($mapping['sparse'])) > 1) {
         throw new \InvalidArgumentException('Multiple index specifications found among index, unique, and/or sparse fields');
     }
     // Index this field if either "index", "unique", or "sparse" are set
     $keys = array($name => 'asc');
     /* The "order" option is only used in the index specification and should
      * not be passed along as an index option.
      */
     if (isset($mapping['index']['order'])) {
         $keys[$name] = $mapping['index']['order'];
         unset($mapping['index']['order']);
     } elseif (isset($mapping['unique']['order'])) {
         $keys[$name] = $mapping['unique']['order'];
         unset($mapping['unique']['order']);
     } elseif (isset($mapping['sparse']['order'])) {
         $keys[$name] = $mapping['sparse']['order'];
         unset($mapping['sparse']['order']);
     }
     /* Initialize $options from any array value among index, unique, and
      * sparse. Any boolean values for unique or sparse should be merged into
      * the options afterwards to ensure consistent parsing.
      */
     $options = array();
     $unique = null;
     $sparse = null;
     if (isset($mapping['index']) && is_array($mapping['index'])) {
         $options = $mapping['index'];
     }
     if (isset($mapping['unique'])) {
         if (is_array($mapping['unique'])) {
             $options = $mapping['unique'] + array('unique' => true);
         } else {
             $unique = (bool) $mapping['unique'];
         }
     }
     if (isset($mapping['sparse'])) {
         if (is_array($mapping['sparse'])) {
             $options = $mapping['sparse'] + array('sparse' => true);
         } else {
             $sparse = (bool) $mapping['sparse'];
         }
     }
     if (isset($unique)) {
         $options['unique'] = $unique;
     }
     if (isset($sparse)) {
         $options['sparse'] = $sparse;
     }
     $class->addIndex($keys, $options);
 }
开发者ID:backplane,项目名称:mongodb-odm,代码行数:64,代码来源:YamlDriver.php


示例15: addIndex

 private function addIndex(ClassMetadataInfo $class, \SimpleXmlElement $xmlIndex)
 {
     $attributes = $xmlIndex->attributes();
     $keys = array();
     foreach ($xmlIndex->{'key'} as $key) {
         $keys[(string) $key['name']] = isset($key['order']) ? (string) $key['order'] : 'asc';
     }
     $options = array();
     if (isset($attributes['background'])) {
         $options['background'] = 'true' === (string) $attributes['background'];
     }
     if (isset($attributes['drop-dups'])) {
         $options['dropDups'] = 'true' === (string) $attributes['drop-dups'];
     }
     if (isset($attributes['name'])) {
         $options['name'] = (string) $attributes['name'];
     }
     if (isset($attributes['safe'])) {
         $options['safe'] = 'true' === (string) $attributes['safe'];
     }
     if (isset($attributes['sparse'])) {
         $options['sparse'] = 'true' === (string) $attributes['sparse'];
     }
     if (isset($attributes['unique'])) {
         $options['unique'] = 'true' === (string) $attributes['unique'];
     }
     if (isset($xmlIndex->{'option'})) {
         foreach ($xmlIndex->{'option'} as $option) {
             $value = (string) $option['value'];
             if ($value === 'true') {
                 $value = true;
             } elseif ($value === 'false') {
                 $value = false;
             } elseif (is_numeric($value)) {
                 $value = preg_match('/^[-]?\\d+$/', $value) ? (int) $value : (double) $value;
             }
             $options[(string) $option['name']] = $value;
         }
     }
     $class->addIndex($keys, $options);
 }
开发者ID:Wizkunde,项目名称:mongodb-odm,代码行数:41,代码来源:XmlDriver.php


示例16: 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


示例17: setShardKey

 private function setShardKey(ClassMetadataInfo $class, \SimpleXmlElement $xmlShardkey)
 {
     $attributes = $xmlShardkey->attributes();
     $keys = array();
     $options = array();
     foreach ($xmlShardkey->{'key'} as $key) {
         $keys[(string) $key['name']] = isset($key['order']) ? (string) $key['order'] : 'asc';
     }
     if (isset($attributes['unique'])) {
         $options['unique'] = 'true' === (string) $attributes['unique'];
     }
     if (isset($attributes['numInitialChunks'])) {
         $options['numInitialChunks'] = (int) $attributes['numInitialChunks'];
     }
     if (isset($xmlShardkey->{'option'})) {
         foreach ($xmlShardkey->{'option'} as $option) {
             $value = (string) $option['value'];
             if ($value === 'true') {
                 $value = true;
             } elseif ($value === 'false') {
                 $value = false;
             } elseif (is_numeric($value)) {
                 $value = preg_match('/^[-]?\\d+$/', $value) ? (int) $value : (double) $value;
             }
             $options[(string) $option['name']] = $value;
         }
     }
     $class->setShardKey($keys, $options);
 }
开发者ID:briareos,项目名称:mongodb-odm,代码行数:29,代码来源:XmlDriver.php


示例18: testEmbedWithCascadeThrowsMappingException

 /**
  * @expectedException \Doctrine\ODM\MongoDB\Mapping\MappingException
  * @expectedExceptionMessage Cascade on Doctrine\ODM\MongoDB\Tests\Mapping\EmbedWithCascadeTest::address is not allowed.
  */
 public function testEmbedWithCascadeThrowsMappingException()
 {
     $class = new ClassMetadataInfo(__NAMESPACE__ . '\\EmbedWithCascadeTest');
     $class->mapOneEmbedded(array('fieldName' => 'address', 'targetDocument' => 'Documents\\Address', 'cascade' => 'all'));
 }
开发者ID:im286er,项目名称:ent,代码行数:9,代码来源:ClassMetadataInfoTest.php


示例19: addFieldMapping

 private function addFieldMapping(ClassMetadataInfo $class, $mapping)
 {
     $keys = null;
     $name = isset($mapping['name']) ? $mapping['name'] : $mapping['fieldName'];
     if (isset($mapping['index'])) {
         $keys = array($name => isset($mapping['index']['order']) ? $mapping['index']['order'] : 'asc');
     }
     if (isset($mapping['unique'])) {
         $keys = array($name => isset($mapping['unique']['order']) ? $mapping['unique']['order'] : 'asc');
     }
     if ($keys !== null) {
         $options = array();
         if (isset($mapping['index'])) {
             $options = $mapping['index'];
         } elseif (isset($mapping['unique'])) {
             $options = $mapping['unique'];
             $options['unique'] = true;
         }
         $class->addIndex($keys, $options);
     }
     $class->mapField($mapping);
 }
开发者ID:nextmotion,项目名称:mongodb-odm,代码行数:22,代码来源:YamlDriver.php


示例20: addIndex

 private function addIndex(ClassMetadataInfo $class, SimpleXmlElement $xmlIndex)
 {
     $attributes = $xmlIndex->attributes();
     $options = array();
     if (isset($attributes['name'])) {
         $options['name'] = (string) $attributes['name'];
     }
     if (isset($attributes['drop-dups'])) {
         $options['dropDups'] = ((string) $attributes['dropDups'] == 'false') ? false : true;
     }
     if (isset($attributes['background'])) {
         $options['background'] = ((string) $attributes['background'] == 'false') ? false : true;
     }
     if (isset($attributes['safe'])) {
         $options['safe'] = ((string) $attributes['safe'] == 'false') ? false : true;
     }
     if (isset($attributes['unique'])) {
         $options['unique'] = ((string) $attributes['unique'] == 'false') ? false : true;
     }
     $index = array(
         'keys' => array(),
         'options' => $options
     );
     foreach ($xmlIndex->{'key'} as $key) {
         $index['keys'][(string) $key['name']] = isset($key['order']) ? (string) $key['order'] : 'asc';
     }
     if (isset($xmlIndex->{'option'})) {
         foreach ($xmlIndex->{'option'} as $option) {
             $value = (string) $option['value'];
             $value = $value === 'true' ? true : $value;
             $value = $value === 'false' ? false : $value;
             $index['options'][(string) $option['name']] = $value;
         }
     }
     $class->addIndex($index['keys'], $index['options']);
 }
开发者ID:royra,项目名称:mongodb-odm,代码行数:36,代码来源:XmlDriver.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Types\Type类代码示例发布时间:2022-05-23
下一篇:
PHP Mapping\ClassMetadata类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap