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


PHP ClassMetadata::setDatabase方法代码示例

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


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

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

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

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

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


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