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


PHP ClassMetadata::setChangeTrackingPolicy方法代码示例

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


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

示例1: loadMetadataForClass


//.........这里部分代码省略.........
     // Evaluate SqlResultSetMappings annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\SqlResultSetMappings'])) {
         $sqlResultSetMappingsAnnotation = $classAnnotations['Doctrine\\ORM\\Mapping\\SqlResultSetMappings'];
         foreach ($sqlResultSetMappingsAnnotation->value as $resultSetMapping) {
             $entities = array();
             $columns = array();
             foreach ($resultSetMapping->entities as $entityResultAnnotation) {
                 $entityResult = array('fields' => array(), 'entityClass' => $entityResultAnnotation->entityClass, 'discriminatorColumn' => $entityResultAnnotation->discriminatorColumn);
                 foreach ($entityResultAnnotation->fields as $fieldResultAnnotation) {
                     $entityResult['fields'][] = array('name' => $fieldResultAnnotation->name, 'column' => $fieldResultAnnotation->column);
                 }
                 $entities[] = $entityResult;
             }
             foreach ($resultSetMapping->columns as $columnResultAnnotation) {
                 $columns[] = array('name' => $columnResultAnnotation->name);
             }
             $metadata->addSqlResultSetMapping(array('name' => $resultSetMapping->name, 'entities' => $entities, 'columns' => $columns));
         }
     }
     // Evaluate NamedQueries annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\NamedQueries'])) {
         $namedQueriesAnnotation = $classAnnotations['Doctrine\\ORM\\Mapping\\NamedQueries'];
         if (!is_array($namedQueriesAnnotation->value)) {
             throw new \UnexpectedValueException('@NamedQueries should contain an array of @NamedQuery annotations.');
         }
         foreach ($namedQueriesAnnotation->value as $namedQuery) {
             if (!$namedQuery instanceof NamedQuery) {
                 throw new \UnexpectedValueException('@NamedQueries should contain an array of @NamedQuery annotations.');
             }
             $metadata->addNamedQuery(array('name' => $namedQuery->name, 'query' => $namedQuery->query));
         }
     }
     // Evaluate InheritanceType annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\InheritanceType'])) {
         $inheritanceTypeAnnotation = $classAnnotations['Doctrine\\ORM\\Mapping\\InheritanceType'];
         $inheritanceType = constant('Doctrine\\ORM\\Mapping\\ClassMetadata::INHERITANCE_TYPE_' . strtoupper($inheritanceTypeAnnotation->value));
         if ($inheritanceType !== OrmClassMetadata::INHERITANCE_TYPE_NONE) {
             // Evaluate DiscriminatorColumn annotation
             if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorColumn'])) {
                 $discriminatorColumnAnnotation = $classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorColumn'];
                 $discriminatorColumn = array('name' => $discriminatorColumnAnnotation->name, 'type' => $discriminatorColumnAnnotation->type, 'length' => $discriminatorColumnAnnotation->length, 'columnDefinition' => $discriminatorColumnAnnotation->columnDefinition);
             } else {
                 $discriminatorColumn = array('name' => 'dtype', 'type' => 'string', 'length' => 255);
             }
             // Evaluate DiscriminatorMap annotation
             if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorMap'])) {
                 $discriminatorMapAnnotation = $classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorMap'];
                 $discriminatorMap = $discriminatorMapAnnotation->value;
             } else {
                 $discriminatorMap = array();
                 $subclassNames = $this->reflectionService->getAllSubClassNamesForClass($className);
                 if (!$this->reflectionService->isClassAbstract($className)) {
                     $mappedClassName = strtolower(str_replace('Domain_Model_', '', str_replace('\\', '_', $className)));
                     $discriminatorMap[$mappedClassName] = $className;
                 }
                 foreach ($subclassNames as $subclassName) {
                     $mappedSubclassName = strtolower(str_replace('Domain_Model_', '', str_replace('\\', '_', $subclassName)));
                     $discriminatorMap[$mappedSubclassName] = $subclassName;
                 }
             }
             if ($discriminatorMap !== array()) {
                 $metadata->setDiscriminatorColumn($discriminatorColumn);
                 $metadata->setDiscriminatorMap($discriminatorMap);
             } else {
                 $inheritanceType = OrmClassMetadata::INHERITANCE_TYPE_NONE;
             }
         }
         $metadata->setInheritanceType($inheritanceType);
     }
     // Evaluate DoctrineChangeTrackingPolicy annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\ChangeTrackingPolicy'])) {
         $changeTrackingAnnotation = $classAnnotations['Doctrine\\ORM\\Mapping\\ChangeTrackingPolicy'];
         $metadata->setChangeTrackingPolicy(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::CHANGETRACKING_' . strtoupper($changeTrackingAnnotation->value)));
     } else {
         $metadata->setChangeTrackingPolicy(OrmClassMetadata::CHANGETRACKING_DEFERRED_EXPLICIT);
     }
     // Evaluate annotations on properties/fields
     try {
         $this->evaluatePropertyAnnotations($metadata);
     } catch (MappingException $exception) {
         throw new MappingException(sprintf('Failure while evaluating property annotations for class "%s": %s', $metadata->getName(), $exception->getMessage()), 1382003497, $exception);
     }
     // build unique index for table
     if (!isset($primaryTable['uniqueConstraints'])) {
         $idProperties = array_keys($classSchema->getIdentityProperties());
         if (array_diff($idProperties, $metadata->getIdentifierFieldNames()) !== array()) {
             $uniqueIndexName = $this->truncateIdentifier('flow_identity_' . $primaryTable['name']);
             foreach ($idProperties as $idProperty) {
                 $primaryTable['uniqueConstraints'][$uniqueIndexName]['columns'][] = isset($metadata->columnNames[$idProperty]) ? $metadata->columnNames[$idProperty] : strtolower($idProperty);
             }
         }
     }
     $metadata->setPrimaryTable($primaryTable);
     // Evaluate AssociationOverrides annotation
     $this->evaluateOverridesAnnotations($classAnnotations, $metadata);
     // Evaluate EntityListeners annotation
     $this->evaluateEntityListenersAnnotation($class, $metadata, $classAnnotations);
     // Evaluate @HasLifecycleCallbacks annotation
     $this->evaluateLifeCycleAnnotations($class, $metadata);
 }
开发者ID:robertlemke,项目名称:flow-development-collection,代码行数:101,代码来源:FlowAnnotationDriver.php

示例2: loadMetadataForClass

 /**
  * {@inheritDoc}
  */
 public function loadMetadataForClass($className, ClassMetadata $metadata)
 {
     /* @var $metadata \Doctrine\ORM\Mapping\ClassMetadataInfo */
     /* @var $xmlRoot SimpleXMLElement */
     $xmlRoot = $this->getElement($className);
     if ($xmlRoot->getName() == 'entity') {
         if (isset($xmlRoot['repository-class'])) {
             $metadata->setCustomRepositoryClass((string) $xmlRoot['repository-class']);
         }
         if (isset($xmlRoot['read-only']) && $this->evaluateBoolean($xmlRoot['read-only'])) {
             $metadata->markReadOnly();
         }
     } else {
         if ($xmlRoot->getName() == 'mapped-superclass') {
             $metadata->setCustomRepositoryClass(isset($xmlRoot['repository-class']) ? (string) $xmlRoot['repository-class'] : null);
             $metadata->isMappedSuperclass = true;
         } else {
             throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className);
         }
     }
     // Evaluate <entity...> attributes
     $table = array();
     if (isset($xmlRoot['table'])) {
         $table['name'] = (string) $xmlRoot['table'];
     }
     $metadata->setPrimaryTable($table);
     // Evaluate named queries
     if (isset($xmlRoot->{'named-queries'})) {
         foreach ($xmlRoot->{'named-queries'}->{'named-query'} as $namedQueryElement) {
             $metadata->addNamedQuery(array('name' => (string) $namedQueryElement['name'], 'query' => (string) $namedQueryElement['query']));
         }
     }
     // Evaluate native named queries
     if (isset($xmlRoot->{'named-native-queries'})) {
         foreach ($xmlRoot->{'named-native-queries'}->{'named-native-query'} as $nativeQueryElement) {
             $metadata->addNamedNativeQuery(array('name' => isset($nativeQueryElement['name']) ? (string) $nativeQueryElement['name'] : null, 'query' => isset($nativeQueryElement->query) ? (string) $nativeQueryElement->query : null, 'resultClass' => isset($nativeQueryElement['result-class']) ? (string) $nativeQueryElement['result-class'] : null, 'resultSetMapping' => isset($nativeQueryElement['result-set-mapping']) ? (string) $nativeQueryElement['result-set-mapping'] : null));
         }
     }
     // Evaluate sql result set mapping
     if (isset($xmlRoot->{'sql-result-set-mappings'})) {
         foreach ($xmlRoot->{'sql-result-set-mappings'}->{'sql-result-set-mapping'} as $rsmElement) {
             $entities = array();
             $columns = array();
             foreach ($rsmElement as $entityElement) {
                 //<entity-result/>
                 if (isset($entityElement['entity-class'])) {
                     $entityResult = array('fields' => array(), 'entityClass' => (string) $entityElement['entity-class'], 'discriminatorColumn' => isset($entityElement['discriminator-column']) ? (string) $entityElement['discriminator-column'] : null);
                     foreach ($entityElement as $fieldElement) {
                         $entityResult['fields'][] = array('name' => isset($fieldElement['name']) ? (string) $fieldElement['name'] : null, 'column' => isset($fieldElement['column']) ? (string) $fieldElement['column'] : null);
                     }
                     $entities[] = $entityResult;
                 }
                 //<column-result/>
                 if (isset($entityElement['name'])) {
                     $columns[] = array('name' => (string) $entityElement['name']);
                 }
             }
             $metadata->addSqlResultSetMapping(array('name' => (string) $rsmElement['name'], 'entities' => $entities, 'columns' => $columns));
         }
     }
     /* not implemented specially anyway. use table = schema.table
        if (isset($xmlRoot['schema'])) {
            $metadata->table['schema'] = (string)$xmlRoot['schema'];
        }*/
     if (isset($xmlRoot['inheritance-type'])) {
         $inheritanceType = (string) $xmlRoot['inheritance-type'];
         $metadata->setInheritanceType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::INHERITANCE_TYPE_' . $inheritanceType));
         if ($metadata->inheritanceType != \Doctrine\ORM\Mapping\ClassMetadata::INHERITANCE_TYPE_NONE) {
             // Evaluate <discriminator-column...>
             if (isset($xmlRoot->{'discriminator-column'})) {
                 $discrColumn = $xmlRoot->{'discriminator-column'};
                 $metadata->setDiscriminatorColumn(array('name' => isset($discrColumn['name']) ? (string) $discrColumn['name'] : null, 'type' => isset($discrColumn['type']) ? (string) $discrColumn['type'] : null, 'length' => isset($discrColumn['length']) ? (string) $discrColumn['length'] : null, 'columnDefinition' => isset($discrColumn['column-definition']) ? (string) $discrColumn['column-definition'] : null));
             } else {
                 $metadata->setDiscriminatorColumn(array('name' => 'dtype', 'type' => 'string', 'length' => 255));
             }
             // Evaluate <discriminator-map...>
             if (isset($xmlRoot->{'discriminator-map'})) {
                 $map = array();
                 foreach ($xmlRoot->{'discriminator-map'}->{'discriminator-mapping'} as $discrMapElement) {
                     $map[(string) $discrMapElement['value']] = (string) $discrMapElement['class'];
                 }
                 $metadata->setDiscriminatorMap($map);
             }
         }
     }
     // Evaluate <change-tracking-policy...>
     if (isset($xmlRoot['change-tracking-policy'])) {
         $metadata->setChangeTrackingPolicy(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::CHANGETRACKING_' . strtoupper((string) $xmlRoot['change-tracking-policy'])));
     }
     // Evaluate <indexes...>
     if (isset($xmlRoot->indexes)) {
         $metadata->table['indexes'] = array();
         foreach ($xmlRoot->indexes->index as $index) {
             $columns = explode(',', (string) $index['columns']);
             if (isset($index['name'])) {
                 $metadata->table['indexes'][(string) $index['name']] = array('columns' => $columns);
             } else {
//.........这里部分代码省略.........
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:101,代码来源:XmlDriver.php

示例3: loadMetadataForClass


//.........这里部分代码省略.........
                     $entities[] = $entityResult;
                 }
             }
             if (isset($resultSetMapping['columnResult'])) {
                 foreach ($resultSetMapping['columnResult'] as $columnResultAnnot) {
                     $columns[] = array('name' => isset($columnResultAnnot['name']) ? $columnResultAnnot['name'] : null);
                 }
             }
             $metadata->addSqlResultSetMapping(array('name' => $resultSetMapping['name'], 'entities' => $entities, 'columns' => $columns));
         }
     }
     /* not implemented specially anyway. use table = schema.table
        if (isset($element['schema'])) {
            $metadata->table['schema'] = $element['schema'];
        }*/
     if (isset($element['inheritanceType'])) {
         $metadata->setInheritanceType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::INHERITANCE_TYPE_' . strtoupper($element['inheritanceType'])));
         if ($metadata->inheritanceType != \Doctrine\ORM\Mapping\ClassMetadata::INHERITANCE_TYPE_NONE) {
             // Evaluate discriminatorColumn
             if (isset($element['discriminatorColumn'])) {
                 $discrColumn = $element['discriminatorColumn'];
                 $metadata->setDiscriminatorColumn(array('name' => isset($discrColumn['name']) ? (string) $discrColumn['name'] : null, 'type' => isset($discrColumn['type']) ? (string) $discrColumn['type'] : null, 'length' => isset($discrColumn['length']) ? (string) $discrColumn['length'] : null, 'columnDefinition' => isset($discrColumn['columnDefinition']) ? (string) $discrColumn['columnDefinition'] : null));
             } else {
                 $metadata->setDiscriminatorColumn(array('name' => 'dtype', 'type' => 'string', 'length' => 255));
             }
             // Evaluate discriminatorMap
             if (isset($element['discriminatorMap'])) {
                 $metadata->setDiscriminatorMap($element['discriminatorMap']);
             }
         }
     }
     // Evaluate changeTrackingPolicy
     if (isset($element['changeTrackingPolicy'])) {
         $metadata->setChangeTrackingPolicy(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::CHANGETRACKING_' . strtoupper($element['changeTrackingPolicy'])));
     }
     // Evaluate indexes
     if (isset($element['indexes'])) {
         foreach ($element['indexes'] as $name => $indexYml) {
             if (!isset($indexYml['name'])) {
                 $indexYml['name'] = $name;
             }
             if (is_string($indexYml['columns'])) {
                 $index = array('columns' => array_map('trim', explode(',', $indexYml['columns'])));
             } else {
                 $index = array('columns' => $indexYml['columns']);
             }
             if (isset($indexYml['flags'])) {
                 if (is_string($indexYml['flags'])) {
                     $index['flags'] = array_map('trim', explode(',', $indexYml['flags']));
                 } else {
                     $index['flags'] = $indexYml['flags'];
                 }
             }
             if (isset($indexYml['options'])) {
                 $index['options'] = $indexYml['options'];
             }
             $metadata->table['indexes'][$indexYml['name']] = $index;
         }
     }
     // Evaluate uniqueConstraints
     if (isset($element['uniqueConstraints'])) {
         foreach ($element['uniqueConstraints'] as $name => $uniqueYml) {
             if (!isset($uniqueYml['name'])) {
                 $uniqueYml['name'] = $name;
             }
             if (is_string($uniqueYml['columns'])) {
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:67,代码来源:YamlDriver.php

示例4: loadMetadataForClass


//.........这里部分代码省略.........
         $namedQueriesAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\NamedQueries'];
         if (!is_array($namedQueriesAnnot->value)) {
             throw new \UnexpectedValueException("@NamedQueries should contain an array of @NamedQuery annotations.");
         }
         foreach ($namedQueriesAnnot->value as $namedQuery) {
             if (!$namedQuery instanceof \Doctrine\ORM\Mapping\NamedQuery) {
                 throw new \UnexpectedValueException("@NamedQueries should contain an array of @NamedQuery annotations.");
             }
             $metadata->addNamedQuery(array('name' => $namedQuery->name, 'query' => $namedQuery->query));
         }
     }
     // Evaluate InheritanceType annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\InheritanceType'])) {
         $inheritanceTypeAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\InheritanceType'];
         $metadata->setInheritanceType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::INHERITANCE_TYPE_' . $inheritanceTypeAnnot->value));
         if ($metadata->inheritanceType != \Doctrine\ORM\Mapping\ClassMetadata::INHERITANCE_TYPE_NONE) {
             // Evaluate DiscriminatorColumn annotation
             if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorColumn'])) {
                 $discrColumnAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorColumn'];
                 $metadata->setDiscriminatorColumn(array('name' => $discrColumnAnnot->name, 'type' => $discrColumnAnnot->type ?: 'string', 'length' => $discrColumnAnnot->length ?: 255, 'columnDefinition' => $discrColumnAnnot->columnDefinition));
             } else {
                 $metadata->setDiscriminatorColumn(array('name' => 'dtype', 'type' => 'string', 'length' => 255));
             }
             // Evaluate DiscriminatorMap annotation
             if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorMap'])) {
                 $discrMapAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorMap'];
                 $metadata->setDiscriminatorMap($discrMapAnnot->value);
             }
         }
     }
     // Evaluate DoctrineChangeTrackingPolicy annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\ChangeTrackingPolicy'])) {
         $changeTrackingAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\ChangeTrackingPolicy'];
         $metadata->setChangeTrackingPolicy(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::CHANGETRACKING_' . $changeTrackingAnnot->value));
     }
     // Evaluate annotations on properties/fields
     /* @var $property \ReflectionProperty */
     foreach ($class->getProperties() as $property) {
         if ($metadata->isMappedSuperclass && !$property->isPrivate() || $metadata->isInheritedField($property->name) || $metadata->isInheritedAssociation($property->name) || $metadata->isInheritedEmbeddedClass($property->name)) {
             continue;
         }
         $mapping = array();
         $mapping['fieldName'] = $property->getName();
         // Evaluate @Cache annotation
         if (($cacheAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Cache')) !== null) {
             $mapping['cache'] = $metadata->getAssociationCacheDefaults($mapping['fieldName'], array('usage' => constant('Doctrine\\ORM\\Mapping\\ClassMetadata::CACHE_USAGE_' . $cacheAnnot->usage), 'region' => $cacheAnnot->region));
         }
         // Check for JoinColumn/JoinColumns annotations
         $joinColumns = array();
         if ($joinColumnAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\JoinColumn')) {
             $joinColumns[] = $this->joinColumnToArray($joinColumnAnnot);
         } else {
             if ($joinColumnsAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\JoinColumns')) {
                 foreach ($joinColumnsAnnot->value as $joinColumn) {
                     $joinColumns[] = $this->joinColumnToArray($joinColumn);
                 }
             }
         }
         // Field can only be annotated with one of:
         // @Column, @OneToOne, @OneToMany, @ManyToOne, @ManyToMany
         if ($columnAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Column')) {
             if ($columnAnnot->type == null) {
                 throw MappingException::propertyTypeIsRequired($className, $property->getName());
             }
             $mapping = $this->columnToArray($property->getName(), $columnAnnot);
             if ($idAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Id')) {
开发者ID:aschempp,项目名称:doctrine2,代码行数:67,代码来源:AnnotationDriver.php

示例5: loadMetadataForClass

 /**
  * {@inheritDoc}
  */
 public function loadMetadataForClass($className, ClassMetadata $class)
 {
     /* @var $class ClassMetadataInfo */
     $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->setCustomRepositoryClass(isset($element['repositoryClass']) ? $element['repositoryClass'] : null);
         $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'])) {
         $class->setDiscriminatorField($this->parseDiscriminatorField($element['discriminatorField']));
     }
     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['requireIndexes'])) {
         $class->setRequireIndexes($element['requireIndexes']);
     }
     if (isset($element['slaveOkay'])) {
         $class->setSlaveOkay($element['slaveOkay']);
     }
     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') {
                 // Note: this strategy is not actually used
                 $mapping['strategy'] = isset($mapping['strategy']) ? $mapping['strategy'] : 'pushAll';
             }
             if (isset($mapping['type']) && !empty($mapping['embedded'])) {
                 $this->addMappingFromEmbed($class, $fieldName, $mapping, $mapping['type']);
             } elseif (isset($mapping['type']) && !empty($mapping['reference'])) {
                 $this->addMappingFromReference($class, $fieldName, $mapping, $mapping['type']);
             } else {
                 $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:backplane,项目名称:mongodb-odm,代码行数:101,代码来源:YamlDriver.php

示例6: loadMetadataForClass

 /**
  * {@inheritDoc}
  */
 public function loadMetadataForClass($className, ClassMetadata $class)
 {
     /* @var $class ClassMetadataInfo */
     /* @var $xmlRoot \SimpleXMLElement */
     $xmlRoot = $this->getElement($className);
     if (!$xmlRoot) {
         return;
     }
     if ($xmlRoot->getName() == 'document') {
         if (isset($xmlRoot['repository-class'])) {
             $class->setCustomRepositoryClass((string) $xmlRoot['repository-class']);
         }
     } elseif ($xmlRoot->getName() == 'mapped-superclass') {
         $class->setCustomRepositoryClass(isset($xmlRoot['repository-class']) ? (string) $xmlRoot['repository-class'] : null);
         $class->isMappedSuperclass = true;
     } elseif ($xmlRoot->getName() == 'embedded-document') {
         $class->isEmbeddedDocument = true;
     }
     if (isset($xmlRoot['db'])) {
         $class->setDatabase((string) $xmlRoot['db']);
     }
     if (isset($xmlRoot['collection'])) {
         $class->setCollection((string) $xmlRoot['collection']);
     }
     if (isset($xmlRoot['inheritance-type'])) {
         $inheritanceType = (string) $xmlRoot['inheritance-type'];
         $class->setInheritanceType(constant('Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadata::INHERITANCE_TYPE_' . $inheritanceType));
     }
     if (isset($xmlRoot['change-tracking-policy'])) {
         $class->setChangeTrackingPolicy(constant('Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadata::CHANGETRACKING_' . strtoupper((string) $xmlRoot['change-tracking-policy'])));
     }
     if (isset($xmlRoot->{'discriminator-field'})) {
         $discrField = $xmlRoot->{'discriminator-field'};
         /* XSD only allows for "name", which is consistent with association
          * configurations, but fall back to "fieldName" for BC.
          */
         $class->setDiscriminatorField(isset($discrField['name']) ? (string) $discrField['name'] : (string) $discrField['fieldName']);
     }
     if (isset($xmlRoot->{'discriminator-map'})) {
         $map = array();
         foreach ($xmlRoot->{'discriminator-map'}->{'discriminator-mapping'} as $discrMapElement) {
             $map[(string) $discrMapElement['value']] = (string) $discrMapElement['class'];
         }
         $class->setDiscriminatorMap($map);
     }
     if (isset($xmlRoot->{'indexes'})) {
         foreach ($xmlRoot->{'indexes'}->{'index'} as $index) {
             $this->addIndex($class, $index);
         }
     }
     if (isset($xmlRoot->{'shard-key'})) {
         $this->setShardKey($class, $xmlRoot->{'shard-key'}[0]);
     }
     if (isset($xmlRoot['require-indexes'])) {
         $class->setRequireIndexes('true' === (string) $xmlRoot['require-indexes']);
     }
     if (isset($xmlRoot['slave-okay'])) {
         $class->setSlaveOkay('true' === (string) $xmlRoot['slave-okay']);
     }
     if (isset($xmlRoot->field)) {
         foreach ($xmlRoot->field as $field) {
             $mapping = array();
             $attributes = $field->attributes();
             foreach ($attributes as $key => $value) {
                 $mapping[$key] = (string) $value;
                 $booleanAttributes = array('id', 'reference', 'embed', 'unique', 'sparse', 'file', 'distance');
                 if (in_array($key, $booleanAttributes)) {
                     $mapping[$key] = 'true' === $mapping[$key];
                 }
             }
             if (isset($mapping['id']) && $mapping['id'] === true && isset($mapping['strategy'])) {
                 $mapping['options'] = array();
                 if (isset($field->{'id-generator-option'})) {
                     foreach ($field->{'id-generator-option'} as $generatorOptions) {
                         $attributesGenerator = iterator_to_array($generatorOptions->attributes());
                         if (isset($attributesGenerator['name']) && isset($attributesGenerator['value'])) {
                             $mapping['options'][(string) $attributesGenerator['name']] = (string) $attributesGenerator['value'];
                         }
                     }
                 }
             }
             if (isset($attributes['not-saved'])) {
                 $mapping['notSaved'] = 'true' === (string) $attributes['not-saved'];
             }
             if (isset($attributes['also-load'])) {
                 $mapping['alsoLoadFields'] = explode(',', $attributes['also-load']);
             } elseif (isset($attributes['version'])) {
                 $mapping['version'] = 'true' === (string) $attributes['version'];
             } elseif (isset($attributes['lock'])) {
                 $mapping['lock'] = 'true' === (string) $attributes['lock'];
             }
             $this->addFieldMapping($class, $mapping);
         }
     }
     if (isset($xmlRoot->{'embed-one'})) {
         foreach ($xmlRoot->{'embed-one'} as $embed) {
             $this->addEmbedMapping($class, $embed, 'one');
//.........这里部分代码省略.........
开发者ID:briareos,项目名称:mongodb-odm,代码行数:101,代码来源:XmlDriver.php

示例7: loadMetadataForClass

 /**
  * Loads the metadata for the specified class into the provided container.
  *
  * @param string            $className
  * @param BaseClassMetadata $metadata
  *
  * @throws MappingException
  */
 public function loadMetadataForClass($className, BaseClassMetadata $metadata)
 {
     /** @var ClassMetadata $metadata */
     $classAnnotations = $this->reader->getClassAnnotations($metadata->getReflectionClass());
     if (count($classAnnotations) === 0) {
         throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className);
     }
     $documentAnnot = null;
     foreach ($classAnnotations as $annot) {
         if ($annot instanceof AbstractDocument) {
             if ($documentAnnot !== null) {
                 throw MappingException::duplicateDocumentAnnotation($className);
             }
             $documentAnnot = $annot;
             continue;
         }
         switch (true) {
             case $annot instanceof ChangeTrackingPolicy:
                 $metadata->setChangeTrackingPolicy(constant('Doctrine\\ODM\\OrientDB\\Mapping\\ClassMetadata::CHANGETRACKING_' . $annot->value));
                 continue;
             case $annot instanceof DocumentListeners:
                 // handle listeners
                 $this->mapDocumentListeners($className, $metadata, $annot);
                 continue;
         }
     }
     $isDocument = false;
     switch (true) {
         case $documentAnnot instanceof Document:
             $isDocument = true;
             $metadata->setIsDocument();
             break;
         case $documentAnnot instanceof Vertex:
             $isDocument = true;
             $metadata->setIsDocument();
             $metadata->setIsVertex();
             break;
         case $documentAnnot instanceof Relationship:
             $isDocument = true;
             $metadata->setIsDocument();
             $metadata->setIsEdge();
             break;
         case $documentAnnot instanceof EmbeddedDocument:
             $isDocument = true;
             $metadata->setIsEmbeddedDocument();
             break;
         case $documentAnnot instanceof MappedSuperclass:
             $metadata->setIsMappedSuperclass();
             break;
     }
     if ($documentAnnot instanceof Annotations\AbstractPersistentDocument) {
         $metadata->setCustomRepositoryClass($documentAnnot->repositoryClass);
     }
     if ($isDocument) {
         if ($documentAnnot->abstract === true) {
             $metadata->setIsAbstract();
         }
         $metadata->setOrientClass($documentAnnot->oclass);
     }
     foreach ($metadata->reflClass->getProperties() as $property) {
         if ($metadata->isMappedSuperclass() && !$property->isPrivate() || $metadata->isInheritedField($property->name)) {
             continue;
         }
         $pas = $this->reader->getPropertyAnnotations($property);
         foreach ($pas as $ann) {
             $mapping = ['fieldName' => $property->getName(), 'nullable' => true];
             if ($ann instanceof PropertyBase) {
                 if (!$ann->name) {
                     $ann->name = $property->getName();
                 }
                 $mapping['name'] = $ann->name;
             }
             switch (true) {
                 case $ann instanceof Property:
                     $mapping = $this->propertyToArray($property->getName(), $ann);
                     $metadata->mapField($mapping);
                     continue;
                 case $ann instanceof RID:
                     $metadata->mapRid($property->getName());
                     continue;
                 case $ann instanceof Version:
                     $metadata->mapVersion($property->getName());
                     continue;
                 case $ann instanceof Link:
                     $this->mergeLink($ann, $mapping);
                     $mapping['nullable'] = $ann->nullable;
                     $metadata->mapLink($mapping);
                     continue;
                 case $ann instanceof LinkList:
                     $this->mergeLink($ann, $mapping);
                     $metadata->mapLinkList($mapping);
                     continue;
//.........这里部分代码省略.........
开发者ID:Edencia,项目名称:orientdb-php-odm,代码行数:101,代码来源:AnnotationDriver.php

示例8: loadMetadataForClass

 /**
  * {@inheritDoc}
  */
 public function loadMetadataForClass($className, ClassMetadata $class)
 {
     /* @var $class ClassMetadataInfo */
     /* @var $xmlRoot SimpleXMLElement */
     $xmlRoot = $this->getElement($className);
     if (!$xmlRoot) {
         return;
     }
     if ($xmlRoot->getName() == 'document') {
         if (isset($xmlRoot['repository-class'])) {
             $class->setCustomRepositoryClass((string) $xmlRoot['repository-class']);
         }
     } elseif ($xmlRoot->getName() == 'mapped-superclass') {
         $class->isMappedSuperclass = true;
     } elseif ($xmlRoot->getName() == 'embedded-document') {
         $class->isEmbeddedDocument = true;
     }
     if (isset($xmlRoot['db'])) {
         $class->setDatabase((string) $xmlRoot['db']);
     }
     if (isset($xmlRoot['collection'])) {
         $class->setCollection((string) $xmlRoot['collection']);
     }
     if (isset($xmlRoot['inheritance-type'])) {
         $inheritanceType = (string) $xmlRoot['inheritance-type'];
         $class->setInheritanceType(constant('Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadata::INHERITANCE_TYPE_' . $inheritanceType));
     }
     if (isset($xmlRoot['change-tracking-policy'])) {
         $class->setChangeTrackingPolicy(constant('Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadata::CHANGETRACKING_' . strtoupper((string) $xmlRoot['change-tracking-policy'])));
     }
     if (isset($xmlRoot->{'discriminator-field'})) {
         $discrField = $xmlRoot->{'discriminator-field'};
         $class->setDiscriminatorField(array('name' => isset($discrField['name']) ? (string) $discrField['name'] : null, 'fieldName' => (string) $discrField['fieldName']));
     }
     if (isset($xmlRoot->{'discriminator-map'})) {
         $map = array();
         foreach ($xmlRoot->{'discriminator-map'}->{'discriminator-mapping'} as $discrMapElement) {
             $map[(string) $discrMapElement['value']] = (string) $discrMapElement['class'];
         }
         $class->setDiscriminatorMap($map);
     }
     if (isset($xmlRoot->{'indexes'})) {
         foreach ($xmlRoot->{'indexes'}->{'index'} as $index) {
             $this->addIndex($class, $index);
         }
     }
     if (isset($xmlRoot->{'require-indexes'})) {
         $class->setRequireIndexes((bool) $xmlRoot->{'require-indexes'});
     }
     if (isset($xmlRoot->{'slave-okay'})) {
         $class->setSlaveOkay((bool) $xmlRoot->{'slave-okay'});
     }
     if (isset($xmlRoot->field)) {
         foreach ($xmlRoot->field as $field) {
             $mapping = array();
             $attributes = $field->attributes();
             foreach ($attributes as $key => $value) {
                 $mapping[$key] = (string) $value;
                 $booleanAttributes = array('id', 'reference', 'embed', 'unique', 'sparse', 'file', 'distance');
                 if (in_array($key, $booleanAttributes)) {
                     $mapping[$key] = 'true' === $mapping[$key] ? true : false;
                 }
             }
             $this->addFieldMapping($class, $mapping);
         }
     }
     if (isset($xmlRoot->{'embed-one'})) {
         foreach ($xmlRoot->{'embed-one'} as $embed) {
             $this->addEmbedMapping($class, $embed, 'one');
         }
     }
     if (isset($xmlRoot->{'embed-many'})) {
         foreach ($xmlRoot->{'embed-many'} as $embed) {
             $this->addEmbedMapping($class, $embed, 'many');
         }
     }
     if (isset($xmlRoot->{'reference-many'})) {
         foreach ($xmlRoot->{'reference-many'} as $reference) {
             $this->addReferenceMapping($class, $reference, 'many');
         }
     }
     if (isset($xmlRoot->{'reference-one'})) {
         foreach ($xmlRoot->{'reference-one'} as $reference) {
             $this->addReferenceMapping($class, $reference, 'one');
         }
     }
     if (isset($xmlRoot->{'lifecycle-callbacks'})) {
         foreach ($xmlRoot->{'lifecycle-callbacks'}->{'lifecycle-callback'} as $lifecycleCallback) {
             $class->addLifecycleCallback((string) $lifecycleCallback['method'], constant('Doctrine\\ODM\\MongoDB\\Events::' . (string) $lifecycleCallback['type']));
         }
     }
 }
开发者ID:3116246,项目名称:haolinju,代码行数:95,代码来源:XmlDriver.php

示例9: loadMetadataForClass

 /**
  * @inheritdoc
  */
 public function loadMetadataForClass($className, \Doctrine\Common\Persistence\Mapping\ClassMetadata $metadata)
 {
     /* @var $metadata ClassMetadata */
     /* @var $xmlRoot SimpleXMLElement */
     $xmlRoot = $this->getElement($className);
     switch ($xmlRoot->getName()) {
         case 'document':
             $metadata->setIsDocument();
             break;
         case 'vertex':
             $metadata->setIsDocument();
             $metadata->setIsVertex();
             break;
         case 'relationship':
             $metadata->setIsDocument();
             $metadata->setIsEdge();
             break;
         case 'embedded-document':
             $metadata->setIsEmbeddedDocument();
             break;
         case 'mapped-superclass':
             $metadata->setIsMappedSuperclass();
             break;
         default:
             throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className);
     }
     if (isset($xmlRoot['repository-class'])) {
         $metadata->setCustomRepositoryClass((string) $xmlRoot['repository-class']);
     }
     if (isset($xmlRoot['oclass'])) {
         $metadata->setOrientClass((string) $xmlRoot['oclass']);
     }
     if (isset($xmlRoot['abstract']) && (string) $xmlRoot['abstract'] === 'true') {
         $metadata->setIsAbstract();
     }
     if (isset($xmlRoot->{'rid'})) {
         $field = $xmlRoot->{'rid'};
         $metadata->mapRid((string) $field['fieldName']);
     }
     if (isset($xmlRoot->{'version'})) {
         $field = $xmlRoot->{'version'};
         $metadata->mapVersion((string) $field['fieldName']);
     }
     if ($metadata->isEdge()) {
         if (isset($xmlRoot->{'in'})) {
             $mapping = [];
             $this->_copyCommonPropertyAttributesToMapping($xmlRoot->{'in'}->attributes(), $mapping);
             $metadata->mapVertexLink($mapping, 'in');
         }
         if (isset($xmlRoot->{'out'})) {
             $mapping = [];
             $this->_copyCommonPropertyAttributesToMapping($xmlRoot->{'out'}->attributes(), $mapping);
             $metadata->mapVertexLink($mapping, 'out');
         }
     }
     // Evaluate <change-tracking-policy...>
     if (isset($xmlRoot['change-tracking-policy'])) {
         $metadata->setChangeTrackingPolicy(constant(sprintf('%s::CHANGETRACKING_%s', ClassMetadata::class, strtoupper((string) $xmlRoot['change-tracking-policy']))));
     }
     if (isset($xmlRoot->field)) {
         $this->readFields($metadata, $xmlRoot);
     }
     if (isset($xmlRoot->{'embed-one'})) {
         foreach ($xmlRoot->{'embed-one'} as $node) {
             $this->addEmbedMapping($metadata, $node, 'one');
         }
     }
     if (isset($xmlRoot->{'embed-many'})) {
         foreach ($xmlRoot->{'embed-many'} as $node) {
             $type = isset($node['collection']) ? (string) $node['collection'] : 'list';
             $this->addEmbedMapping($metadata, $node, $type);
         }
     }
     if (isset($xmlRoot->{'link-one'})) {
         foreach ($xmlRoot->{'link-one'} as $node) {
             $this->addLinkMapping($metadata, $node, 'one');
         }
     }
     if (isset($xmlRoot->{'link-many'})) {
         foreach ($xmlRoot->{'link-many'} as $node) {
             $type = isset($node['collection']) ? (string) $node['collection'] : 'list';
             $this->addLinkMapping($metadata, $node, $type);
         }
     }
     if (isset($xmlRoot->{'related-to'})) {
         foreach ($xmlRoot->{'related-to'} as $node) {
             $this->addRelatedToMapping($metadata, $node);
         }
     }
     if (isset($xmlRoot->{'related-to-via'})) {
         foreach ($xmlRoot->{'related-to-via'} as $node) {
             $this->addRelatedToMapping($metadata, $node, false);
         }
     }
     // Evaluate entity listener
     if (isset($xmlRoot->{'document-listeners'})) {
         /** @var SimpleXMLElement $listenerElement */
//.........这里部分代码省略.........
开发者ID:Edencia,项目名称:orientdb-php-odm,代码行数:101,代码来源:XmlDriver.php


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