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


PHP ClassMetadata::mapField方法代码示例

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


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

示例1: loadMetadata

 /**
  * Metadata definition for static_php metadata driver.
  * @param  ClassMetadata $metadata
  * @return void
  */
 public static function loadMetadata(ClassMetadata $metadata)
 {
     $metadata->setPrimaryTable(['name' => 'password_resets']);
     $metadata->mapField(['id' => true, 'fieldName' => 'email', 'type' => 'string']);
     $metadata->mapField(['fieldName' => 'token', 'type' => 'string']);
     $metadata->mapField(['columnName' => 'created_at', 'fieldName' => 'createdAt', 'type' => 'datetime', 'nullable' => false]);
 }
开发者ID:spohess,项目名称:orm,代码行数:12,代码来源:PasswordReminder.php

示例2: testGetMetadataForSingleClass

 public function testGetMetadataForSingleClass()
 {
     $mockPlatform = new DatabasePlatformMock();
     $mockDriver = new MetadataDriverMock();
     $mockPlatform->setPrefersSequences(true);
     $mockPlatform->setPrefersIdentityColumns(false);
     // Self-made metadata
     $cm1 = new ClassMetadata('Doctrine\\Tests\\ORM\\Mapping\\TestEntity1');
     // Add a mapped field
     $cm1->mapField(array('fieldName' => 'name', 'type' => 'varchar'));
     // Add a mapped field
     $cm1->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true));
     // and a mapped association
     $cm1->mapOneToOne(array('fieldName' => 'other', 'targetEntity' => 'Other', 'mappedBy' => 'this'));
     // and an id generator type
     $cm1->setIdGeneratorType('auto');
     // SUT
     $cmf = new ClassMetadataFactoryTestSubject($mockDriver, $mockPlatform);
     $cmf->setMetadataForClass('Doctrine\\Tests\\ORM\\Mapping\\TestEntity1', $cm1);
     // Prechecks
     $this->assertEquals(array(), $cm1->parentClasses);
     $this->assertEquals('none', $cm1->inheritanceType);
     $this->assertTrue($cm1->hasField('name'));
     $this->assertEquals(1, count($cm1->associationMappings));
     $this->assertEquals('auto', $cm1->generatorType);
     // Go
     $cm1 = $cmf->getMetadataFor('Doctrine\\Tests\\ORM\\Mapping\\TestEntity1');
     $this->assertEquals(array(), $cm1->parentClasses);
     $this->assertTrue($cm1->hasField('name'));
     $this->assertEquals('sequence', $cm1->generatorType);
 }
开发者ID:jackbravo,项目名称:doctrine,代码行数:31,代码来源:ClassMetadataFactoryTest.php

示例3: prepare

 private function prepare()
 {
     $cmf = $this->em->getMetadataFactory();
     $metadata = new ClassMetadata('Mapping\\Fixture\\Unmapped\\Timestampable');
     $id = array();
     $id['fieldName'] = 'id';
     $id['type'] = 'integer';
     $id['nullable'] = false;
     $id['columnName'] = 'id';
     $id['id'] = true;
     $metadata->mapField($id);
     $created = array();
     $created['fieldName'] = 'created';
     $created['type'] = 'datetime';
     $created['nullable'] = false;
     $created['columnName'] = 'created';
     $metadata->mapField($created);
     $metadata->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_IDENTITY);
     $metadata->setIdGenerator(new \Doctrine\ORM\Id\IdentityGenerator(null));
     $metadata->setPrimaryTable(array('name' => 'temp_test'));
     $cmf->setMetadataFor('Mapping\\Fixture\\Unmapped\\Timestampable', $metadata);
     // trigger loadClassMetadata event
     $evm = $this->em->getEventManager();
     $eventArgs = new \Doctrine\ORM\Event\LoadClassMetadataEventArgs($metadata, $this->em);
     $evm->dispatchEvent(\Doctrine\ORM\Events::loadClassMetadata, $eventArgs);
     if (Version::compare('2.3.0-dev') <= 0) {
         $metadata->wakeupReflection($cmf->getReflectionService());
     }
     $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->em);
     $schemaTool->dropSchema(array());
     $schemaTool->createSchema(array($this->em->getClassMetadata('Mapping\\Fixture\\Unmapped\\Timestampable')));
 }
开发者ID:esserj,项目名称:DoctrineExtensions,代码行数:32,代码来源:ForcedMetadataTest.php

示例4: prepareMocks

 /**
  * @return array
  */
 protected function prepareMocks()
 {
     $configuration = new Configuration();
     $configuration->addEntityNamespace('Stub', 'Oro\\Bundle\\BatchBundle\\Tests\\Unit\\ORM\\Query\\Stub');
     $classMetadata = new ClassMetadata('Entity');
     $classMetadata->mapField(['fieldName' => 'a', 'columnName' => 'a']);
     $classMetadata->mapField(['fieldName' => 'b', 'columnName' => 'b']);
     $classMetadata->setIdentifier(['a']);
     $platform = $this->getMockBuilder('Doctrine\\DBAL\\Platforms\\AbstractPlatform')->setMethods([])->disableOriginalConstructor()->getMockForAbstractClass();
     $statement = $this->getMockBuilder('Doctrine\\DBAL\\Statement')->setMethods(['fetch', 'fetchColumn', 'closeCursor'])->disableOriginalConstructor()->getMock();
     $driverConnection = $this->getMockBuilder('Doctrine\\DBAL\\Driver\\Connection')->setMethods(['query'])->disableOriginalConstructor()->getMockForAbstractClass();
     $driverConnection->expects($this->any())->method('query')->will($this->returnValue($statement));
     $driver = $this->getMockBuilder('Doctrine\\DBAL\\Driver')->setMethods(['connect', 'getDatabasePlatform'])->disableOriginalConstructor()->getMockForAbstractClass();
     $driver->expects($this->any())->method('connect')->will($this->returnValue($driverConnection));
     $driver->expects($this->any())->method('getDatabasePlatform')->will($this->returnValue($platform));
     $connection = $this->getMockBuilder('Doctrine\\DBAL\\Connection')->setMethods(['getDatabasePlatform', 'executeQuery'])->setConstructorArgs([[], $driver])->getMock();
     $connection->expects($this->any())->method('getDatabasePlatform')->will($this->returnValue($platform));
     /** @var UnitOfWork $unitOfWork */
     $unitOfWork = $this->getMockBuilder('UnitOfWork')->setMethods(['getEntityPersister'])->disableOriginalConstructor()->getMock();
     $entityManager = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->setMethods(['getConfiguration', 'getClassMetadata', 'getConnection', 'getUnitOfWork'])->disableOriginalConstructor()->getMock();
     $entityManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($configuration));
     $entityManager->expects($this->any())->method('getClassMetadata')->will($this->returnValue($classMetadata));
     $entityManager->expects($this->any())->method('getConnection')->will($this->returnValue($connection));
     $entityManager->expects($this->any())->method('getUnitOfWork')->will($this->returnValue($unitOfWork));
     return [$entityManager, $connection, $statement];
 }
开发者ID:northdakota,项目名称:platform,代码行数:29,代码来源:QueryCountCalculatorTest.php

示例5: getMetadata

 /**
  * @return ClassMetadata
  */
 public static function getMetadata()
 {
     $metadata = new ClassMetadata(static::class);
     $metadata->mapField(['fieldName' => 'x']);
     $metadata->mapField(['fieldName' => 'y']);
     $metadata->mapField(['fieldName' => 'z']);
     $metadata->wakeupReflection(new RuntimeReflectionService());
     return $metadata;
 }
开发者ID:mihai-stancu,项目名称:serializer,代码行数:12,代码来源:DummyEmbeddable.php

示例6: getMetadata

 /**
  * @return ClassMetadata
  */
 public static function getMetadata()
 {
     $metadata = new ClassMetadata(static::class);
     $metadata->setIdentifier(['id']);
     $metadata->mapField(['fieldName' => 'id']);
     $metadata->mapField(['fieldName' => 'a']);
     $metadata->mapField(['fieldName' => 'b']);
     $metadata->mapField(['fieldName' => 'c']);
     $metadata->mapEmbedded(['fieldName' => 'd', 'class' => DummyEmbeddable::class, 'columnPrefix' => 'd']);
     $metadata->mapManyToOne(['fieldName' => 'parent', 'targetEntity' => self::class, 'inversedBy' => 'children']);
     $metadata->mapOneToMany(['fieldName' => 'children', 'targetEntity' => self::class, 'mappedBy' => 'parent']);
     $metadata->wakeupReflection(new RuntimeReflectionService());
     return $metadata;
 }
开发者ID:mihai-stancu,项目名称:serializer,代码行数:17,代码来源:DummyEntity.php

示例7: let

 function let(EntityManager $em, Connection $connection)
 {
     $classMetadata = new ClassMetadata('Acme\\Bundle\\AppBundle\\Entity\\Color');
     $classMetadata->mapField(['fieldName' => 'sortOrder', 'type' => 'integer']);
     $em->getConnection()->willReturn($connection);
     $this->beConstructedWith($em, $classMetadata);
 }
开发者ID:alexisfroger,项目名称:pim-community-dev,代码行数:7,代码来源:ReferenceDataRepositorySpec.php

示例8: generate

 public function generate($jsonSchema)
 {
     $schema = json_decode($jsonSchema, true);
     if (!isset($schema['type']) && $schema['type'] !== 'object') {
         throw new \RuntimeException("Unable to process the schema");
     }
     if (!isset($schema['title'])) {
         throw new \RuntimeException("title property must be defined");
     }
     // TODO investigate implementation via ClassMetadataBuilder
     $className = $schema['title'];
     $medatadata = new ClassMetadata($this->getNamespace() . '\\' . $className);
     if (isset($schema['properties'])) {
         foreach ($schema['properties'] as $name => $definition) {
             $type = $definition['type'];
             $nullable = isset($schema['required']) ? !in_array($name, $schema['required']) : true;
             $medatadata->mapField(['fieldName' => $name, 'type' => $type, 'nullable' => $nullable, 'options' => []]);
         }
     }
     $filename = sprintf("%s/%s/%s.php", $this->getPath(), join('/', explode('\\', $this->getNamespace())), $className);
     mkdir(dirname($filename), 0777, true);
     $generator = new EntityGenerator();
     $generator->setGenerateAnnotations(true);
     file_put_contents($filename, $generator->generateEntityClass($medatadata));
 }
开发者ID:jeremygiberson,项目名称:js2doctrine,代码行数:25,代码来源:ModelGenerator.php

示例9: addField

 /**
  * Add Field
  *
  * @param string $name
  * @param string $type
  * @param array $mapping
  */
 public function addField($name, $type, array $mapping = array())
 {
     $mapping['fieldName'] = $name;
     $mapping['type'] = $type;
     $this->cm->mapField($mapping);
     return $this;
 }
开发者ID:ramonornela,项目名称:doctrine2,代码行数:14,代码来源:ClassMetadataBuilder.php

示例10: __invoke

 public function __invoke($fieldName, Field $field, ClassMetadata $metadata, $extraOptions = [])
 {
     $type = $field->getStorageType();
     $options = $field->getStorageOptions();
     $extraOptions = array_merge(['serialize_scalar' => false], $extraOptions);
     if (true === $extraOptions['serialize_scalar']) {
         $metadata->mapField(['fieldName' => $fieldName, 'type' => 'array']);
         return;
     }
     if ($type === Type\ObjectType::class) {
         $metadata->mapField(['fieldName' => $fieldName, 'type' => 'object']);
         return;
     }
     if ($type === Type\BooleanType::class) {
         $metadata->mapField(['fieldName' => $fieldName, 'type' => 'boolean', 'nullable' => true]);
         return;
     }
     if ($type === Type\DoubleType::class) {
         $metadata->mapField(['fieldName' => $fieldName, 'type' => 'float', 'nullable' => true]);
         return;
     }
     if ($type === Type\CollectionType::class) {
         $this->mapCollectionType($fieldName, $field, $metadata);
         return;
     }
     if ($type === Type\StringType::class) {
         $metadata->mapField(['fieldName' => $fieldName, 'type' => 'string', 'nullable' => true]);
         return;
     }
     if ($type === Type\IntegerType::class) {
         $metadata->mapField(['fieldName' => $fieldName, 'type' => 'integer', 'nullable' => true]);
         return;
     }
     if ($type === Type\DateTimeType::class) {
         $metadata->mapField(['fieldName' => $fieldName, 'type' => 'date', 'nullable' => true]);
         return;
     }
     if ($type === Type\ReferenceType::class) {
         if (false === isset($options['class'])) {
             throw new \InvalidArgumentException(sprintf('Doctrine ORM storage requires that you provide the "class" option for reference mapping for "%s::$%s"', $metadata->getName(), $fieldName));
         }
         $metadata->mapManyToOne(['fieldName' => $fieldName, 'targetEntity' => $options['class'], 'cascade' => ['all']]);
         return;
     }
     throw new \RuntimeException(sprintf('Do not know how to map field of type "%s"', $type));
 }
开发者ID:symfony-cmf,项目名称:content-type,代码行数:46,代码来源:FieldMapper.php

示例11: addValueObjectFields

 /**
  * @param LoadClassMetadataEventArgs $event
  * @param $valueObjectPropertyMetadata
  */
 private function addValueObjectFields(DoctrineOrmClassMetadata $classMetadata, PropertyMetadata $valueObjectPropertyMetadata)
 {
     $valueObjectClass = $valueObjectPropertyMetadata->getValueObjectClass();
     $fieldPrefix = $valueObjectPropertyMetadata->getFieldPrefix();
     $extraFields = $this->getValueObjectFieldMappings($valueObjectClass, $fieldPrefix);
     foreach ($extraFields as $fieldMapping) {
         $classMetadata->mapField($fieldMapping);
     }
 }
开发者ID:kawanamiyuu,项目名称:doctrine-orm-value-object,代码行数:13,代码来源:AddValueObjectMappingEventSubscriber.php

示例12: testGetMetadataForSingleClass

 public function testGetMetadataForSingleClass()
 {
     $mockDriver = new MetadataDriverMock();
     $entityManager = $this->_createEntityManager($mockDriver);
     $conn = $entityManager->getConnection();
     $mockPlatform = $conn->getDatabasePlatform();
     $mockPlatform->setPrefersSequences(true);
     $mockPlatform->setPrefersIdentityColumns(false);
     // Self-made metadata
     $cm1 = new ClassMetadata('Doctrine\\Tests\\ORM\\Mapping\\TestEntity1');
     $cm1->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
     $cm1->setPrimaryTable(array('name' => '`group`'));
     // Add a mapped field
     $cm1->mapField(array('fieldName' => 'name', 'type' => 'varchar'));
     // Add a mapped field
     $cm1->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true));
     // and a mapped association
     $cm1->mapOneToOne(array('fieldName' => 'other', 'targetEntity' => 'TestEntity1', 'mappedBy' => 'this'));
     // and an association on the owning side
     $joinColumns = array(array('name' => 'other_id', 'referencedColumnName' => 'id'));
     $cm1->mapOneToOne(array('fieldName' => 'association', 'targetEntity' => 'TestEntity1', 'joinColumns' => $joinColumns));
     // and an id generator type
     $cm1->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_AUTO);
     // SUT
     $cmf = new \Doctrine\ORM\Mapping\ClassMetadataFactory();
     $cmf->setEntityManager($entityManager);
     $cmf->setMetadataFor('Doctrine\\Tests\\ORM\\Mapping\\TestEntity1', $cm1);
     // Prechecks
     $this->assertEquals(array(), $cm1->parentClasses);
     $this->assertEquals(ClassMetadata::INHERITANCE_TYPE_NONE, $cm1->inheritanceType);
     $this->assertTrue($cm1->hasField('name'));
     $this->assertEquals(2, count($cm1->associationMappings));
     $this->assertEquals(ClassMetadata::GENERATOR_TYPE_AUTO, $cm1->generatorType);
     $this->assertEquals('group', $cm1->table['name']);
     // Go
     $cmMap1 = $cmf->getMetadataFor('Doctrine\\Tests\\ORM\\Mapping\\TestEntity1');
     $this->assertSame($cm1, $cmMap1);
     $this->assertEquals('group', $cmMap1->table['name']);
     $this->assertTrue($cmMap1->table['quoted']);
     $this->assertEquals(array(), $cmMap1->parentClasses);
     $this->assertTrue($cmMap1->hasField('name'));
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:42,代码来源:ClassMetadataFactoryTest.php

示例13: addCompositePropertiesClassMetadata

 /**
  * Adds the mapped properties of the composite property
  *
  * @param \ReflectionClass $reflectionClass
  * @param \Doctrine\ORM\Mapping\ClassMetadata $classMetadata
  * @return null
  */
 public function addCompositePropertiesClassMetadata(ReflectionClass $reflectionClass, ClassMetadata &$classMetadata)
 {
     if (!$this->classContainsMappedProperties($reflectionClass)) {
         return;
     }
     $this->walkCompositePropertiesAnnotations($reflectionClass, function ($reflectionProperty, $annotation) use($reflectionClass, $classMetadata) {
         /**
          * @var $annotation \Matmar10\Bundle\MoneyBundle\Annotation\CompositeProperty
          * @var $reflectionClass \ReflectionClass
          * @var $classMetadata \Doctrine\ORM\Mapping\ClassMetadata
          */
         $mappings = $annotation->getMap($reflectionProperty);
         foreach ($mappings as $map) {
             $classMetadata->mapField($map);
         }
     });
 }
开发者ID:matmar10,项目名称:money-bundle,代码行数:24,代码来源:CompositePropertyService.php

示例14: mapTranslation

 /**
  * Add mapping data to a translation entity.
  *
  * @param ClassMetadata $metadata
  */
 private function mapTranslation(ClassMetadata $metadata)
 {
     // In the case A -> B -> TranslationInterface, B might not have mapping defined as it
     // is probably defined in A, so in that case, we just return.
     if (!isset($this->configs[$metadata->name])) {
         return;
     }
     $metadata->mapManyToOne(array('fieldName' => 'translatable', 'targetEntity' => $this->configs[$metadata->name]['model'], 'inversedBy' => 'translations', 'joinColumns' => array(array('name' => 'translatable_id', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE', 'nullable' => false))));
     if (!$metadata->hasField('locale')) {
         $metadata->mapField(array('fieldName' => 'locale', 'type' => 'string', 'nullable' => false));
     }
     // Map unique index.
     $columns = array($metadata->getSingleAssociationJoinColumnName('translatable'), 'locale');
     if (!$this->hasUniqueConstraint($metadata, $columns)) {
         $constraints = isset($metadata->table['uniqueConstraints']) ? $metadata->table['uniqueConstraints'] : array();
         $constraints[$metadata->getTableName() . '_uniq_trans'] = array('columns' => $columns);
         $metadata->setPrimaryTable(array('uniqueConstraints' => $constraints));
     }
 }
开发者ID:aleherse,项目名称:Sylius,代码行数:24,代码来源:ORMTranslatableListener.php

示例15: testFieldOptionsExport

    /**
     * @group 1214
     * @group 1216
     * @group DDC-3439
     */
    public function testFieldOptionsExport()
    {
        $exporter = new XmlExporter();
        $metadata = new ClassMetadata('entityTest');
        $metadata->mapField(array("fieldName" => 'myField', "type" => 'string', "columnName" => 'my_field', "options" => array("default" => "default_string", "comment" => "The comment for the field")));
        $expectedFileContent = <<<'XML'
<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
  <entity name="entityTest">
    <field name="myField" type="string" column="my_field">
      <options>
        <option name="default">default_string</option>
        <option name="comment">The comment for the field</option>
      </options>
    </field>
  </entity>
</doctrine-mapping>
XML;
        $this->assertXmlStringEqualsXmlString($expectedFileContent, $exporter->exportClassMetadata($metadata));
    }
开发者ID:selimcr,项目名称:servigases,代码行数:25,代码来源:XmlClassMetadataExporterTest.php


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