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


PHP ClassMetadata::setCustomRepositoryClass方法代码示例

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


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

示例1: loadMetadataForClass

 /**
  * {@inheritDoc}
  */
 public function loadMetadataForClass($className, ClassMetadata $class)
 {
     $element = $this->getElement($className);
     if (!$element) {
         return;
     }
     if (isset($element['repositoryClass'])) {
         $class->setCustomRepositoryClass((string) $element['repositoryClass']);
     }
     foreach ($element['models'] as $managerName => $model) {
         $this->addModel($class, $managerName, $model);
     }
     // mandatory, after register models
     $this->setModelReference($class, $element['modelReference']);
 }
开发者ID:pokap,项目名称:pool-dbm,代码行数:18,代码来源:YmlDriver.php

示例2: loadMetadataForClass

 /**
  * Loads the metadata for the specified class into the provided container.
  *
  * ToDo: Caching
  *
  * ToDo: Embedded document
  *
  * ToDo: Inheritance type
  * ToDo: Change tracking policy
  * ToDo: Discriminator field
  * ToDo: Discriminator map
  * ToDo: Not saved
  * ToDo: Also load
  *
  * @param string $className
  * @param \Doctrine\Common\Persistence\Mapping\ClassMetadata|\Doctrine\ODM\MongoDB\Mapping\ClassMetadataInfo $metadata
  *
  * @return void
  */
 public function loadMetadataForClass($className, ClassMetadata $metadata)
 {
     if (empty($this->config[$className])) {
         return;
     }
     /** @var array $config */
     $config = $this->config[$className];
     // If this entity is supposed to go to a different db.
     if (!empty($config['db'])) {
         $metadata->setDatabase($config['db']);
     }
     // If this entity's collection is specified.
     if (!empty($config['collection'])) {
         $metadata->setCollection($config['collection']);
     }
     // If we're configuring a repository class.
     if (!empty($config['repository_class'])) {
         $metadata->setCustomRepositoryClass($config['repository_class']);
     }
     // If we're requiring indexes.
     if (!empty($config['require-indexes'])) {
         $metadata->setRequireIndexes(true);
     }
     // If slave is okay.
     if (!empty($config['slave-okay'])) {
         $metadata->setSlaveOkay(true);
     }
     // If any indexes need to be set up.
     if (!empty($config['indexes'])) {
         foreach ($config['indexes'] as $name => $index) {
             $this->addIndex($metadata, $name, $index);
         }
     }
     // Map any fields.
     if (!empty($config['fields'])) {
         foreach ($config['fields'] as $name => $config) {
             $this->mapField($metadata, $name, $config);
         }
     }
     // If this is an abstract superclass.
     if (!empty($config['abstract'])) {
         $metadata->isMappedSuperclass = true;
         $metadata->setCustomRepositoryClass(null);
         $metadata->setCollection(null);
     }
 }
开发者ID:atrauzzi,项目名称:laravel-mongodb,代码行数:65,代码来源:ConfigMapping.php

示例3: loadMetadataForClass

 /**
  * {@inheritDoc}
  */
 public function loadMetadataForClass($className, ClassMetadata $metadata)
 {
     // this happens when running annotation driver in combination with
     // static reflection services. This is not the nicest fix
     $class = new \ReflectionClass($metadata->name);
     $classAnnotations = $this->reader->getClassAnnotations($class);
     if ($classAnnotations && is_numeric(key($classAnnotations))) {
         foreach ($classAnnotations as $annot) {
             $classAnnotations[get_class($annot)] = $annot;
         }
     }
     if (isset($classAnnotations['Core\\Model\\OWM\\Mapping\\Endpoint'])) {
         $entityAnnot = $classAnnotations['Core\\Model\\OWM\\Mapping\\Endpoint'];
         if ($entityAnnot->repositoryClass !== NULL) {
             $metadata->setCustomRepositoryClass($entityAnnot->repositoryClass);
         }
         if ($entityAnnot->configKey !== NULL) {
             $metadata->configKey = $entityAnnot->configKey;
         }
     }
 }
开发者ID:sgdoc,项目名称:sgdoce-codigo,代码行数:24,代码来源:AnnotationDriver.php

示例4: loadMetadataForClass

 /**
  * {@inheritDoc}
  */
 public function loadMetadataForClass($className, ClassMetadata $class)
 {
     /* @var \Pok\PoolDBM\Mapping\ClassMetadata $class */
     /* @var \SimpleXMLElement $xmlRoot */
     $xmlRoot = $this->getElement($className);
     if (!$xmlRoot) {
         return;
     }
     if (isset($xmlRoot['repository-class'])) {
         $class->setCustomRepositoryClass((string) $xmlRoot['repository-class']);
     }
     foreach ($xmlRoot->model as $model) {
         $this->addModel($class, $model);
     }
     // mandatory, after register models
     $this->setModelReference($class, $xmlRoot->{'model-reference'});
     // associations
     foreach ($xmlRoot->{'relation-one'} as $reference) {
         $this->addAssociation($class, $reference, false);
     }
     foreach ($xmlRoot->{'relation-many'} as $reference) {
         $this->addAssociation($class, $reference, true);
     }
 }
开发者ID:pokap,项目名称:pool-dbm,代码行数:27,代码来源:XmlDriver.php

示例5: loadMetadataForClass

 /**
  * {@inheritDoc}
  */
 public function loadMetadataForClass($className, ClassMetadata $metadata)
 {
     /* @var $metadata \Doctrine\ORM\Mapping\ClassMetadataInfo */
     $class = $metadata->getReflectionClass();
     if (!$class) {
         // this happens when running annotation driver in combination with
         // static reflection services. This is not the nicest fix
         $class = new \ReflectionClass($metadata->name);
     }
     $classAnnotations = $this->reader->getClassAnnotations($class);
     if ($classAnnotations) {
         foreach ($classAnnotations as $key => $annot) {
             if (!is_numeric($key)) {
                 continue;
             }
             $classAnnotations[get_class($annot)] = $annot;
         }
     }
     // Evaluate Entity annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\Entity'])) {
         $entityAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\Entity'];
         if ($entityAnnot->repositoryClass !== null) {
             $metadata->setCustomRepositoryClass($entityAnnot->repositoryClass);
         }
         if ($entityAnnot->readOnly) {
             $metadata->markReadOnly();
         }
     } else {
         if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\MappedSuperclass'])) {
             $mappedSuperclassAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\MappedSuperclass'];
             $metadata->setCustomRepositoryClass($mappedSuperclassAnnot->repositoryClass);
             $metadata->isMappedSuperclass = true;
         } else {
             if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\Embeddable'])) {
                 $metadata->isEmbeddedClass = true;
             } else {
                 throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className);
             }
         }
     }
     // Evaluate Table annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\Table'])) {
         $tableAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\Table'];
         $primaryTable = array('name' => $tableAnnot->name, 'schema' => $tableAnnot->schema);
         if ($tableAnnot->indexes !== null) {
             foreach ($tableAnnot->indexes as $indexAnnot) {
                 $index = array('columns' => $indexAnnot->columns);
                 if (!empty($indexAnnot->flags)) {
                     $index['flags'] = $indexAnnot->flags;
                 }
                 if (!empty($indexAnnot->options)) {
                     $index['options'] = $indexAnnot->options;
                 }
                 if (!empty($indexAnnot->name)) {
                     $primaryTable['indexes'][$indexAnnot->name] = $index;
                 } else {
                     $primaryTable['indexes'][] = $index;
                 }
             }
         }
         if ($tableAnnot->uniqueConstraints !== null) {
             foreach ($tableAnnot->uniqueConstraints as $uniqueConstraintAnnot) {
                 $uniqueConstraint = array('columns' => $uniqueConstraintAnnot->columns);
                 if (!empty($uniqueConstraintAnnot->options)) {
                     $uniqueConstraint['options'] = $uniqueConstraintAnnot->options;
                 }
                 if (!empty($uniqueConstraintAnnot->name)) {
                     $primaryTable['uniqueConstraints'][$uniqueConstraintAnnot->name] = $uniqueConstraint;
                 } else {
                     $primaryTable['uniqueConstraints'][] = $uniqueConstraint;
                 }
             }
         }
         if ($tableAnnot->options) {
             $primaryTable['options'] = $tableAnnot->options;
         }
         $metadata->setPrimaryTable($primaryTable);
     }
     // Evaluate @Cache annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\Cache'])) {
         $cacheAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\Cache'];
         $cacheMap = array('region' => $cacheAnnot->region, 'usage' => constant('Doctrine\\ORM\\Mapping\\ClassMetadata::CACHE_USAGE_' . $cacheAnnot->usage));
         $metadata->enableCache($cacheMap);
     }
     // Evaluate NamedNativeQueries annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\NamedNativeQueries'])) {
         $namedNativeQueriesAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\NamedNativeQueries'];
         foreach ($namedNativeQueriesAnnot->value as $namedNativeQuery) {
             $metadata->addNamedNativeQuery(array('name' => $namedNativeQuery->name, 'query' => $namedNativeQuery->query, 'resultClass' => $namedNativeQuery->resultClass, 'resultSetMapping' => $namedNativeQuery->resultSetMapping));
         }
     }
     // Evaluate SqlResultSetMappings annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\SqlResultSetMappings'])) {
         $sqlResultSetMappingsAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\SqlResultSetMappings'];
         foreach ($sqlResultSetMappingsAnnot->value as $resultSetMapping) {
             $entities = array();
             $columns = array();
//.........这里部分代码省略.........
开发者ID:aschempp,项目名称:doctrine2,代码行数:101,代码来源:AnnotationDriver.php

示例6: loadMetadataForClass

 /**
  * {@inheritDoc}
  */
 public function loadMetadataForClass($className, ClassMetadata $metadata)
 {
     /* @var $metadata \Doctrine\ORM\Mapping\ClassMetadataInfo */
     $element = $this->getElement($className);
     if ($element['type'] == 'entity') {
         if (isset($element['repositoryClass'])) {
             $metadata->setCustomRepositoryClass($element['repositoryClass']);
         }
         if (isset($element['readOnly']) && $element['readOnly'] == true) {
             $metadata->markReadOnly();
         }
     } else {
         if ($element['type'] == 'mappedSuperclass') {
             $metadata->setCustomRepositoryClass(isset($element['repositoryClass']) ? $element['repositoryClass'] : null);
             $metadata->isMappedSuperclass = true;
         } else {
             if ($element['type'] == 'embeddable') {
                 $metadata->isEmbeddedClass = true;
             } else {
                 throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className);
             }
         }
     }
     // Evaluate root level properties
     $table = array();
     if (isset($element['table'])) {
         $table['name'] = $element['table'];
     }
     // Evaluate second level cache
     if (isset($element['cache'])) {
         $metadata->enableCache($this->cacheToArray($element['cache']));
     }
     $metadata->setPrimaryTable($table);
     // Evaluate named queries
     if (isset($element['namedQueries'])) {
         foreach ($element['namedQueries'] as $name => $queryMapping) {
             if (is_string($queryMapping)) {
                 $queryMapping = array('query' => $queryMapping);
             }
             if (!isset($queryMapping['name'])) {
                 $queryMapping['name'] = $name;
             }
             $metadata->addNamedQuery($queryMapping);
         }
     }
     // Evaluate named native queries
     if (isset($element['namedNativeQueries'])) {
         foreach ($element['namedNativeQueries'] as $name => $mappingElement) {
             if (!isset($mappingElement['name'])) {
                 $mappingElement['name'] = $name;
             }
             $metadata->addNamedNativeQuery(array('name' => $mappingElement['name'], 'query' => isset($mappingElement['query']) ? $mappingElement['query'] : null, 'resultClass' => isset($mappingElement['resultClass']) ? $mappingElement['resultClass'] : null, 'resultSetMapping' => isset($mappingElement['resultSetMapping']) ? $mappingElement['resultSetMapping'] : null));
         }
     }
     // Evaluate sql result set mappings
     if (isset($element['sqlResultSetMappings'])) {
         foreach ($element['sqlResultSetMappings'] as $name => $resultSetMapping) {
             if (!isset($resultSetMapping['name'])) {
                 $resultSetMapping['name'] = $name;
             }
             $entities = array();
             $columns = array();
             if (isset($resultSetMapping['entityResult'])) {
                 foreach ($resultSetMapping['entityResult'] as $entityResultElement) {
                     $entityResult = array('fields' => array(), 'entityClass' => isset($entityResultElement['entityClass']) ? $entityResultElement['entityClass'] : null, 'discriminatorColumn' => isset($entityResultElement['discriminatorColumn']) ? $entityResultElement['discriminatorColumn'] : null);
                     if (isset($entityResultElement['fieldResult'])) {
                         foreach ($entityResultElement['fieldResult'] as $fieldResultElement) {
                             $entityResult['fields'][] = array('name' => isset($fieldResultElement['name']) ? $fieldResultElement['name'] : null, 'column' => isset($fieldResultElement['column']) ? $fieldResultElement['column'] : null);
                         }
                     }
                     $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'])) {
//.........这里部分代码省略.........
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:101,代码来源:YamlDriver.php

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

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

示例9: loadMetadataForClass

 /**
  * Loads the metadata for the specified class into the provided container.
  *
  * @param string                       $className
  * @param EntityMetadata|ClassMetadata $metadata
  *
  * @return void
  * @throws MappingException
  */
 public function loadMetadataForClass($className, ClassMetadata $metadata)
 {
     $element = $this->getElement($className);
     switch ($element['type']) {
         case 'entity':
             if (array_key_exists('repositoryClass', $element)) {
                 $metadata->setCustomRepositoryClass($element['repositoryClass']);
             }
             break;
         case 'mappedSuperclass':
             $metadata->isMappedSuperclass = true;
             $metadata->setCustomRepositoryClass(array_key_exists('repositoryClass', $element) ? $element['repositoryClass'] : null);
             break;
     }
     if (null === $metadata->searcher) {
         $metadata->searcher = DoctrineApi::class;
     }
     if (null === $metadata->finder) {
         $metadata->finder = DoctrineApi::class;
     }
     // Configure client
     if (array_key_exists('client', $element)) {
         if (array_key_exists('name', $element['client'])) {
             $metadata->clientName = $element['client']['name'];
         }
         if (array_key_exists('searcher', $element['client'])) {
             $metadata->searcher = $element['client']['searcher'];
         }
         if (array_key_exists('finder', $element['client'])) {
             $metadata->finder = $element['client']['finder'];
         }
         assert(in_array(Searcher::class, class_implements($metadata->searcher), true), 'Searcher ' . $metadata->searcher . ' should implement ' . Searcher::class);
         assert(in_array(Finder::class, class_implements($metadata->finder), true), 'Finder ' . $metadata->finder . ' should implement ' . Finder::class);
         $methodProvider = null;
         if (array_key_exists('methods', $element['client'])) {
             $methodProvider = new MethodProvider($element['client']['methods']);
         }
         if (array_key_exists('entityPath', $element['client'])) {
             $pathSeparator = array_key_exists('entityPathSeparator', $element['client']) ? $element['client']['entityPathSeparator'] : null;
             $methodProvider = new EntityMethodProvider($element['client']['entityPath'], $pathSeparator, $methodProvider);
         }
         if (null === $methodProvider) {
             throw MappingException::noMethods();
         }
         $metadata->methodProvider = $methodProvider;
     }
     // Configure fields
     if (array_key_exists('fields', $element)) {
         foreach ($element['fields'] as $field => $mapping) {
             $mapping = $this->fieldToArray($field, $mapping);
             $metadata->mapField($mapping);
         }
     }
     // Configure identifiers
     $associationIds = [];
     if (array_key_exists('id', $element)) {
         // Evaluate identifier settings
         foreach ($element['id'] as $name => $idElement) {
             if (isset($idElement['associationKey']) && (bool) $idElement['associationKey'] === true) {
                 $associationIds[$name] = true;
                 continue;
             }
             $mapping = $this->fieldToArray($name, $idElement);
             $mapping['id'] = true;
             $metadata->mapField($mapping);
         }
     }
     foreach (['oneToOne', 'manyToOne', 'oneToMany'] as $type) {
         if (array_key_exists($type, $element)) {
             $associations = $element[$type];
             foreach ($associations as $name => $association) {
                 $this->mapAssociation($metadata, $type, $name, $association, $associationIds);
             }
         }
     }
 }
开发者ID:bankiru,项目名称:doctrine-api-client,代码行数:85,代码来源:YmlMetadataDriver.php

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

示例11: loadMetadataForClass

 /**
  * Loads the metadata for the specified class into the provided container.
  *
  * @param string                              $className
  * @param \Doctrine\ORM\Mapping\ClassMetadata $metadata
  */
 public function loadMetadataForClass($className, ClassMetadata $metadata)
 {
     global $container;
     $builder = new ClassMetadataBuilder($metadata);
     $tableName = static::classToTableName($className);
     $this->loadDataContainer($tableName);
     try {
         /** @var ClassLoader $entitiesClassLoader */
         $entitiesClassLoader = $container['doctrine.orm.entitiesClassLoader'];
         if (!class_exists($className, false)) {
             $entitiesClassLoader->loadClass($className);
         }
         if (class_exists($className, false)) {
             $class = new \ReflectionClass($className);
         } else {
             $class = false;
         }
     } catch (\Exception $e) {
         $class = false;
     }
     if (!array_key_exists('TL_DCA', $GLOBALS)) {
         $GLOBALS['TL_DCA'] = array();
     }
     if (!array_key_exists($tableName, $GLOBALS['TL_DCA']) || !is_array($GLOBALS['TL_DCA'][$tableName])) {
         $GLOBALS['TL_DCA'][$tableName] = array('fields' => array());
     }
     $entityConfig = array();
     if (array_key_exists('entity', $GLOBALS['TL_DCA'][$tableName])) {
         $entityConfig = $GLOBALS['TL_DCA'][$tableName]['entity'];
     }
     if ($class && !$class->isInstantiable()) {
         $metadata->isMappedSuperclass = true;
     } elseif (array_key_exists('isMappedSuperclass', $entityConfig)) {
         $metadata->isMappedSuperclass = $entityConfig['isMappedSuperclass'];
     }
     // custom repository class
     if (array_key_exists('repositoryClass', $entityConfig)) {
         $metadata->setCustomRepositoryClass($entityConfig['repositoryClass']);
     } else {
         $metadata->setCustomRepositoryClass('Contao\\Doctrine\\ORM\\Repository');
     }
     // id generator
     if (array_key_exists('idGenerator', $entityConfig)) {
         $metadata->setIdGeneratorType($entityConfig['idGenerator']);
     } else {
         $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
     }
     // indexes
     if (isset($entityConfig['indexes'])) {
         if (is_array($entityConfig['indexes'])) {
             foreach ($entityConfig['indexes'] as $name => $columns) {
                 if (is_array($columns)) {
                     $builder->addIndex($columns, $name);
                 } else {
                     throw new \RuntimeException(sprintf('$GLOBALS[TL_DCA][%s][entity][indexes][%s] must be an array', $tableName, $name));
                 }
             }
         } else {
             throw new \RuntimeException(sprintf('$GLOBALS[TL_DCA][%s][entity][indexes] must be an array', $tableName));
         }
     }
     // uniques
     if (isset($entityConfig['uniques'])) {
         if (is_array($entityConfig['uniques'])) {
             foreach ($entityConfig['uniques'] as $name => $columns) {
                 if (is_array($columns)) {
                     $builder->addUniqueConstraint($columns, $name);
                 } else {
                     throw new \RuntimeException(sprintf('$GLOBALS[TL_DCA][%s][entity][uniques][%s] must be an array', $tableName, $name));
                 }
             }
         } else {
             throw new \RuntimeException(sprintf('$GLOBALS[TL_DCA][%s][entity][uniques] must be an array', $tableName));
         }
     }
     $metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_NONE);
     $metadata->setPrimaryTable(array('name' => $tableName));
     $fields = (array) $GLOBALS['TL_DCA'][$tableName]['fields'];
     foreach ($fields as $fieldName => $fieldConfig) {
         $configured = array_key_exists('field', $fieldConfig) || array_key_exists('oneToOne', $fieldConfig) || array_key_exists('oneToMany', $fieldConfig) || array_key_exists('manyToOne', $fieldConfig) || array_key_exists('manyToMany', $fieldConfig);
         if (!$configured && empty($fieldConfig['inputType']) || $configured && $fieldConfig['field'] === false) {
             continue;
         }
         if (isset($fieldConfig['oneToOne'])) {
             $fieldConfig['oneToOne']['fieldName'] = $fieldName;
             $metadata->mapOneToOne($fieldConfig['oneToOne']);
         } elseif (isset($fieldConfig['oneToMany'])) {
             $fieldConfig['oneToMany']['fieldName'] = $fieldName;
             $metadata->mapOneToMany($fieldConfig['oneToMany']);
         } elseif (isset($fieldConfig['manyToOne'])) {
             $fieldConfig['manyToOne']['fieldName'] = $fieldName;
             $metadata->mapManyToOne($fieldConfig['manyToOne']);
         } elseif (isset($fieldConfig['manyToMany'])) {
             $fieldConfig['manyToMany']['fieldName'] = $fieldName;
//.........这里部分代码省略.........
开发者ID:bit3,项目名称:contao-doctrine-orm,代码行数:101,代码来源:ContaoDcaDriver.php

示例12: loadMetadataForClass

 /**
  * {@inheritdoc}
  */
 public function loadMetadataForClass($className, ClassMetadata $class)
 {
     $reflClass = $class->getReflectionClass();
     $isValidDocument = false;
     $classAnnotations = $this->reader->getClassAnnotations($reflClass);
     foreach ($classAnnotations as $classAnnotation) {
         if ($classAnnotation instanceof ODM\Document) {
             if ($classAnnotation->indexed) {
                 $class->indexed = true;
             }
             $class->setCustomRepositoryClass($classAnnotation->repositoryClass);
             $isValidDocument = true;
         } elseif ($classAnnotation instanceof ODM\EmbeddedDocument) {
             $class->isEmbeddedDocument = true;
             $isValidDocument = true;
         } else {
             if ($classAnnotation instanceof ODM\MappedSuperclass) {
                 $class->isMappedSuperclass = true;
                 $isValidDocument = true;
             } else {
                 if ($classAnnotation instanceof ODM\Index) {
                     $class->indexed = true;
                 } else {
                     if ($classAnnotation instanceof ODM\InheritanceRoot) {
                         $class->markInheritanceRoot();
                     }
                 }
             }
         }
     }
     if (!$isValidDocument) {
         throw MappingException::classIsNotAValidDocument($className);
     }
     foreach ($reflClass->getProperties() as $property) {
         if ($class->isInheritedAssociation($property->name) || $class->isInheritedField($property->name)) {
             continue;
         }
         $mapping = array();
         $mapping['fieldName'] = $property->name;
         if ($this->reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\CouchDB\\Mapping\\Annotations\\Index')) {
             $mapping['indexed'] = true;
         }
         foreach ($this->reader->getPropertyAnnotations($property) as $fieldAnnot) {
             if ($fieldAnnot instanceof \Doctrine\ODM\CouchDB\Mapping\Annotations\Field) {
                 if ($fieldAnnot instanceof \Doctrine\ODM\CouchDB\Mapping\Annotations\Version) {
                     $mapping['isVersionField'] = true;
                 }
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 unset($mapping['value']);
                 $class->mapField($mapping);
             } else {
                 if ($fieldAnnot instanceof \Doctrine\ODM\CouchDB\Mapping\Annotations\ReferenceOne) {
                     $mapping = array_merge($mapping, (array) $fieldAnnot);
                     $mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade);
                     unset($mapping['value']);
                     $class->mapManyToOne($mapping);
                 } else {
                     if ($fieldAnnot instanceof \Doctrine\ODM\CouchDB\Mapping\Annotations\ReferenceMany) {
                         $mapping = array_merge($mapping, (array) $fieldAnnot);
                         $mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade);
                         unset($mapping['value']);
                         $class->mapManyToMany($mapping);
                     } else {
                         if ($fieldAnnot instanceof \Doctrine\ODM\CouchDB\Mapping\Annotations\Attachments) {
                             $class->mapAttachments($mapping['fieldName']);
                         } else {
                             if ($fieldAnnot instanceof \Doctrine\ODM\CouchDB\Mapping\Annotations\EmbedOne || $fieldAnnot instanceof \Doctrine\ODM\CouchDB\Mapping\Annotations\EmbedMany) {
                                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                                 unset($mapping['value']);
                                 $class->mapEmbedded($mapping);
                             }
                         }
                     }
                 }
             }
         }
     }
 }
开发者ID:doctrine,项目名称:couchdb-odm,代码行数:81,代码来源:AnnotationDriver.php

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

示例14: loadMetadataForClass

 /**
  * Loads the metadata for the specified class into the provided container.
  *
  * @param string $className
  * @param ClassMetadata $metadata
  * @return void
  * @throws MappingException
  * @throws \UnexpectedValueException
  * @todo adjust when Doctrine 2.5 is used, see http://www.doctrine-project.org/jira/browse/DDC-93
  */
 public function loadMetadataForClass($className, ClassMetadata $metadata)
 {
     /**
      * This is the actual type we have at this point, but we cannot change the
      * signature due to inheritance.
      *
      * @var OrmClassMetadata $metadata
      */
     $class = $metadata->getReflectionClass();
     $classSchema = $this->getClassSchema($class->getName());
     $classAnnotations = $this->reader->getClassAnnotations($class);
     // Evaluate Entity annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\MappedSuperclass'])) {
         $mappedSuperclassAnnotation = $classAnnotations['Doctrine\\ORM\\Mapping\\MappedSuperclass'];
         if ($mappedSuperclassAnnotation->repositoryClass !== null) {
             $metadata->setCustomRepositoryClass($mappedSuperclassAnnotation->repositoryClass);
         }
         $metadata->isMappedSuperclass = true;
     } elseif (isset($classAnnotations[\TYPO3\Flow\Annotations\Entity::class]) || isset($classAnnotations['Doctrine\\ORM\\Mapping\\Entity'])) {
         $entityAnnotation = isset($classAnnotations[\TYPO3\Flow\Annotations\Entity::class]) ? $classAnnotations[\TYPO3\Flow\Annotations\Entity::class] : $classAnnotations['Doctrine\\ORM\\Mapping\\Entity'];
         if ($entityAnnotation->repositoryClass !== null) {
             $metadata->setCustomRepositoryClass($entityAnnotation->repositoryClass);
         } elseif ($classSchema->getRepositoryClassName() !== null) {
             if ($this->reflectionService->isClassImplementationOf($classSchema->getRepositoryClassName(), 'Doctrine\\ORM\\EntityRepository')) {
                 $metadata->setCustomRepositoryClass($classSchema->getRepositoryClassName());
             }
         }
         if ($entityAnnotation->readOnly) {
             $metadata->markReadOnly();
         }
     } elseif ($classSchema->getModelType() === ClassSchema::MODELTYPE_VALUEOBJECT) {
         // also ok... but we make it read-only
         $metadata->markReadOnly();
     } else {
         throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className);
     }
     // Evaluate Table annotation
     $primaryTable = array();
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\Table'])) {
         $tableAnnotation = $classAnnotations['Doctrine\\ORM\\Mapping\\Table'];
         $primaryTable = array('name' => $tableAnnotation->name, 'schema' => $tableAnnotation->schema);
         if ($tableAnnotation->indexes !== null) {
             foreach ($tableAnnotation->indexes as $indexAnnotation) {
                 $index = array('columns' => $indexAnnotation->columns);
                 if (!empty($indexAnnotation->name)) {
                     $primaryTable['indexes'][$indexAnnotation->name] = $index;
                 } else {
                     $primaryTable['indexes'][] = $index;
                 }
             }
         }
         if ($tableAnnotation->uniqueConstraints !== null) {
             foreach ($tableAnnotation->uniqueConstraints as $uniqueConstraint) {
                 $uniqueConstraint = array('columns' => $uniqueConstraint->columns);
                 if (!empty($uniqueConstraint->name)) {
                     $primaryTable['uniqueConstraints'][$uniqueConstraint->name] = $uniqueConstraint;
                 } else {
                     $primaryTable['uniqueConstraints'][] = $uniqueConstraint;
                 }
             }
         }
         if ($tableAnnotation->options !== null) {
             $primaryTable['options'] = $tableAnnotation->options;
         }
     }
     if (!isset($primaryTable['name'])) {
         $className = $classSchema->getClassName();
         $primaryTable['name'] = $this->inferTableNameFromClassName($className);
     }
     // Evaluate NamedNativeQueries annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\NamedNativeQueries'])) {
         $namedNativeQueriesAnnotation = $classAnnotations['Doctrine\\ORM\\Mapping\\NamedNativeQueries'];
         foreach ($namedNativeQueriesAnnotation->value as $namedNativeQuery) {
             $metadata->addNamedNativeQuery(array('name' => $namedNativeQuery->name, 'query' => $namedNativeQuery->query, 'resultClass' => $namedNativeQuery->resultClass, 'resultSetMapping' => $namedNativeQuery->resultSetMapping));
         }
     }
     // 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) {
//.........这里部分代码省略.........
开发者ID:robertlemke,项目名称:flow-development-collection,代码行数:101,代码来源:FlowAnnotationDriver.php

示例15: loadMetadataForClass

 /**
  * {@inheritdoc}
  */
 public function loadMetadataForClass($className, ClassMetadata $class)
 {
     /** @var $class \Doctrine\ODM\CouchDB\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;
     }
     if ($element['type'] == 'document') {
         $class->setCustomRepositoryClass(isset($element['repositoryClass']) ? $element['repositoryClass'] : null);
         if (isset($element['indexed']) && $element['indexed'] == true) {
             $class->indexed = true;
         }
         if (isset($element['inheritanceRoot']) && $element['inheritanceRoot']) {
             $class->markInheritanceRoot();
         }
     } else {
         if ($element['type'] == 'embedded') {
             $class->isEmbeddedDocument = true;
             if (isset($element['inheritanceRoot']) && $element['inheritanceRoot']) {
                 $class->markInheritanceRoot();
             }
         } else {
             if (strtolower($element['type']) == "mappedsuperclass") {
                 $class->isMappedSuperclass = true;
             } else {
                 throw MappingException::classIsNotAValidDocument($className);
             }
         }
     }
     if (isset($element['id'])) {
         foreach ($element['id'] as $fieldName => $idElement) {
             $class->mapField(array('fieldName' => $fieldName, 'indexed' => isset($idElement['index']) ? (bool) $idElement['index'] : false, 'type' => isset($idElement['type']) ? $idElement['type'] : null, 'id' => true, 'strategy' => isset($idElement['strategy']) ? $idElement['strategy'] : null));
         }
     }
     if (isset($element['fields'])) {
         foreach ($element['fields'] as $fieldName => $fieldElement) {
             $class->mapField(array('fieldName' => $fieldName, 'jsonName' => isset($fieldElement['jsonName']) ? $fieldElement['jsonName'] : null, 'indexed' => isset($fieldElement['index']) ? (bool) $fieldElement['index'] : false, 'type' => isset($fieldElement['type']) ? $fieldElement['type'] : null, 'isVersionField' => isset($fieldElement['version']) ? true : null));
         }
     }
     if (isset($element['referenceOne'])) {
         foreach ($element['referenceOne'] as $field => $referenceOneElement) {
             $class->mapManyToOne(array('cascade' => isset($referenceOneElement['cascade']) ? $this->getCascadeMode($referenceOneElement['cascade']) : 0, 'targetDocument' => (string) $referenceOneElement['targetDocument'], 'fieldName' => $field, 'jsonName' => isset($referenceOneElement['jsonName']) ? (string) $referenceOneElement['jsonName'] : null, 'indexed' => isset($referenceOneElement['index']) ? (bool) $referenceOneElement['index'] : false));
         }
     }
     if (isset($element['referenceMany'])) {
         foreach ($element['referenceMany'] as $field => $referenceManyElement) {
             $class->mapManyToMany(array('cascade' => isset($referenceManyElement['cascade']) ? $this->getCascadeMode($referenceManyElement['cascade']) : 0, 'targetDocument' => (string) $referenceManyElement['targetDocument'], 'fieldName' => $field, 'jsonName' => isset($referenceManyElement['jsonName']) ? (string) $referenceManyElement['jsonName'] : null, 'mappedBy' => isset($referenceManyElement['mappedBy']) ? (string) $referenceManyElement['mappedBy'] : null));
         }
     }
     if (isset($element['attachments'])) {
         $class->mapAttachments($element['attachments']);
     }
     if (isset($element['embedOne'])) {
         foreach ($element['embedOne'] as $field => $embedOneElement) {
             $class->mapEmbedded(array('targetDocument' => (string) $embedOneElement['targetDocument'], 'fieldName' => $field, 'jsonName' => isset($embedOneElement['jsonName']) ? (string) $embedOneElement['jsonName'] : null, 'embedded' => 'one'));
         }
     }
     if (isset($element['embedMany'])) {
         foreach ($element['embedMany'] as $field => $embedManyElement) {
             $class->mapEmbedded(array('targetDocument' => (string) $embedManyElement['targetDocument'], 'fieldName' => $field, 'jsonName' => isset($embedManyElement['jsonName']) ? (string) $embedManyElement['jsonName'] : null, 'embedded' => 'many'));
         }
     }
 }
开发者ID:doctrine,项目名称:couchdb-odm,代码行数:71,代码来源:YamlDriver.php


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