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


PHP ClassMetadata::setCustomRepositoryClass方法代码示例

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


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

示例1: testLoadClassMetadataWithoutParent

 public function testLoadClassMetadataWithoutParent()
 {
     $this->loadClassMetadataEvent->getClassMetadata()->willReturn($this->classMetadata->reveal());
     $this->classMetadata->getName()->willReturn(get_class($this->object->reveal()));
     $this->classMetadata->setCustomRepositoryClass('Sulu\\Bundle\\ContactBundle\\Entity\\ContactRepository')->shouldNotBeCalled();
     $this->loadClassMetadataEvent->getEntityManager()->willReturn($this->entityManager->reveal());
     $this->entityManager->getConfiguration()->willReturn($this->configuration->reveal());
     $this->configuration->getNamingStrategy()->willReturn(null);
     /** @var \Doctrine\Common\Persistence\Mapping\Driver\MappingDriver $mappingDriver */
     $mappingDriver = $this->prophesize('Doctrine\\Common\\Persistence\\Mapping\\Driver\\MappingDriver');
     $this->configuration->getMetadataDriverImpl()->willReturn($mappingDriver->reveal());
     $mappingDriver->getAllClassNames()->willReturn([get_class($this->parentObject->reveal())]);
     $mappingDriver->loadMetadataForClass(get_class($this->parentObject->reveal()), Argument::type('Doctrine\\ORM\\Mapping\\ClassMetadata'))->shouldBeCalled();
     $this->subscriber->loadClassMetadata($this->loadClassMetadataEvent->reveal());
 }
开发者ID:ollietb,项目名称:sulu,代码行数:15,代码来源:MetadataSubscriberTest.php

示例2: testClassMetadataInstanceSerialization

 public function testClassMetadataInstanceSerialization()
 {
     $cm = new ClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsUser');
     // Test initial state
     $this->assertTrue(count($cm->getReflectionProperties()) == 0);
     $this->assertTrue($cm->reflClass instanceof \ReflectionClass);
     $this->assertEquals('Doctrine\\Tests\\Models\\CMS\\CmsUser', $cm->name);
     $this->assertEquals('Doctrine\\Tests\\Models\\CMS\\CmsUser', $cm->rootEntityName);
     $this->assertEquals(array(), $cm->subClasses);
     $this->assertEquals(array(), $cm->parentClasses);
     // Customize state
     $cm->setSubclasses(array("One", "Two", "Three"));
     $cm->setParentClasses(array("UserParent"));
     $cm->setCustomRepositoryClass("UserRepository");
     $cm->setDiscriminatorColumn(array('name' => 'disc', 'type' => 'integer'));
     $cm->mapOneToOne(array('fieldName' => 'phonenumbers', 'targetEntity' => 'Bar', 'mappedBy' => 'foo'));
     $this->assertTrue($cm->getAssociationMapping('phonenumbers') instanceof \Doctrine\ORM\Mapping\OneToOneMapping);
     $this->assertEquals(1, count($cm->associationMappings));
     $serialized = serialize($cm);
     $cm = unserialize($serialized);
     // Check state
     $this->assertTrue(count($cm->getReflectionProperties()) > 0);
     $this->assertTrue($cm->reflClass instanceof \ReflectionClass);
     $this->assertEquals('Doctrine\\Tests\\Models\\CMS\\CmsUser', $cm->name);
     $this->assertEquals('UserParent', $cm->rootEntityName);
     $this->assertEquals(array('One', 'Two', 'Three'), $cm->subClasses);
     $this->assertEquals(array('UserParent'), $cm->parentClasses);
     $this->assertEquals('UserRepository', $cm->getCustomRepositoryClass());
     $this->assertEquals(array('name' => 'disc', 'type' => 'integer'), $cm->discriminatorColumn);
     $this->assertTrue($cm->getAssociationMapping('phonenumbers') instanceof \Doctrine\ORM\Mapping\OneToOneMapping);
     $this->assertEquals(1, count($cm->associationMappings));
     $oneOneMapping = $cm->getAssociationMapping('phonenumbers');
     $this->assertEquals('phonenumbers', $oneOneMapping->getSourceFieldName());
     $this->assertEquals('Doctrine\\Tests\\Models\\CMS\\Bar', $oneOneMapping->getTargetEntityName());
 }
开发者ID:jackbravo,项目名称:doctrine,代码行数:35,代码来源:ClassMetadataTest.php

示例3: loadMetadataForClass

 public function loadMetadataForClass($className, ClassMetadata $metadata)
 {
     $entity = $this->_entities[$className];
     if (isset($entity['repositoryClass']) && $entity['repositoryClass']) {
         $metadata->setCustomRepositoryClass($entity['repositoryClass']);
     }
     if (isset($entity['table'])) {
         $metadata->setPrimaryTable($entity['table']);
     }
     if (isset($entity['inheritanceType']) && $entity['inheritanceType']) {
         $metadata->setInheritanceType($entity['inheritanceType']);
     }
     if (isset($entity['discriminatorColumn'])) {
         $metadata->setDiscriminatorColumn($entity['discriminatorColumn']);
     }
     if (isset($entity['discriminatorValue']) && $entity['discriminatorValue']) {
         $metadata->setDiscriminatorValue($entity['discriminatorValue']);
     }
     if (isset($entity['subClasses']) && $entity['subClasses']) {
         $metadata->setSubclasses((array) $entity['subClasses']);
     }
     $relationTypes = array('OneToOne', 'OneToMany', 'ManyToOne', 'ManyToMany');
     foreach ($entity['properties'] as $name => $property) {
         $mapping = array();
         $mapping['fieldName'] = $name;
         $joinColumns = array();
         if (isset($property['joinColumn']) && $property['joinColumn']) {
             $joinColumns[] = $property['joinColumn'];
         } else {
             if (isset($property['joinColumns']) && $property['joinColumns']) {
                 $joinColumns = $property['joinColumns'];
             }
         }
         $type = $property['type'];
         $mapping = array_merge($mapping, $property);
         if (in_array($type, $relationTypes)) {
             unset($property['type']);
             switch ($type) {
                 case 'ManyToOne':
                 case 'OneToOne':
                     $mapping['joinColumns'] = $joinColumns;
                     break;
                 case 'ManyToMany':
                     $joinTable = array();
                     if (isset($property['joinTable'])) {
                         $joinTable = $property['joinTable'];
                     }
                     $mapping['joinTable'] = $joinTable;
                     break;
                 case 'OneToMany':
                 default:
                     break;
             }
             $func = 'map' . $type;
             $metadata->{$func}($mapping);
         } else {
             $metadata->mapField($mapping);
         }
     }
 }
开发者ID:jackbravo,项目名称:doctrine,代码行数:60,代码来源:YamlDriver.php

示例4: setCustomRepositoryClass

 /**
  * @param ClassMetadata $metadata
  */
 private function setCustomRepositoryClass(ClassMetadata $metadata)
 {
     try {
         $resourceMetadata = $this->resourceRegistry->getByClass($metadata->getName());
     } catch (\InvalidArgumentException $exception) {
         return;
     }
     if ($resourceMetadata->hasClass('repository')) {
         $metadata->setCustomRepositoryClass($resourceMetadata->getClass('repository'));
     }
 }
开发者ID:ReissClothing,项目名称:Sylius,代码行数:14,代码来源:ORMRepositoryClassSubscriber.php

示例5: testClassMetadataInstanceSerialization

    public function testClassMetadataInstanceSerialization()
    {
        $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');

        // Test initial state
        $this->assertTrue(count($cm->getReflectionProperties()) == 0);
        $this->assertInstanceOf('ReflectionClass', $cm->reflClass);
        $this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $cm->name);
        $this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $cm->rootEntityName);
        $this->assertEquals(array(), $cm->subClasses);
        $this->assertEquals(array(), $cm->parentClasses);
        $this->assertEquals(ClassMetadata::INHERITANCE_TYPE_NONE, $cm->inheritanceType);

        // Customize state
        $cm->setInheritanceType(ClassMetadata::INHERITANCE_TYPE_SINGLE_TABLE);
        $cm->setSubclasses(array("One", "Two", "Three"));
        $cm->setParentClasses(array("UserParent"));
        $cm->setCustomRepositoryClass("UserRepository");
        $cm->setDiscriminatorColumn(array('name' => 'disc', 'type' => 'integer'));
        $cm->mapOneToOne(array('fieldName' => 'phonenumbers', 'targetEntity' => 'Bar', 'mappedBy' => 'foo'));
        $cm->markReadOnly();
        $cm->addNamedQuery(array('name' => 'dql', 'query' => 'foo'));
        $this->assertEquals(1, count($cm->associationMappings));

        $serialized = serialize($cm);
        $cm = unserialize($serialized);

        // Check state
        $this->assertTrue(count($cm->getReflectionProperties()) > 0);
        $this->assertEquals('Doctrine\Tests\Models\CMS', $cm->namespace);
        $this->assertInstanceOf('ReflectionClass', $cm->reflClass);
        $this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $cm->name);
        $this->assertEquals('UserParent', $cm->rootEntityName);
        $this->assertEquals(array('Doctrine\Tests\Models\CMS\One', 'Doctrine\Tests\Models\CMS\Two', 'Doctrine\Tests\Models\CMS\Three'), $cm->subClasses);
        $this->assertEquals(array('UserParent'), $cm->parentClasses);
        $this->assertEquals('Doctrine\Tests\Models\CMS\UserRepository', $cm->customRepositoryClassName);
        $this->assertEquals(array('name' => 'disc', 'type' => 'integer', 'fieldName' => 'disc'), $cm->discriminatorColumn);
        $this->assertTrue($cm->associationMappings['phonenumbers']['type'] == ClassMetadata::ONE_TO_ONE);
        $this->assertEquals(1, count($cm->associationMappings));
        $oneOneMapping = $cm->getAssociationMapping('phonenumbers');
        $this->assertTrue($oneOneMapping['fetch'] == ClassMetadata::FETCH_LAZY);
        $this->assertEquals('phonenumbers', $oneOneMapping['fieldName']);
        $this->assertEquals('Doctrine\Tests\Models\CMS\Bar', $oneOneMapping['targetEntity']);
        $this->assertTrue($cm->isReadOnly);
        $this->assertEquals(array('dql' => 'foo'), $cm->namedQueries);
    }
开发者ID:naderman,项目名称:doctrine2,代码行数:46,代码来源:ClassMetadataTest.php

示例6:

 function it_does_not_set_custom_repository_class_if_registry_does_not_have_class(LoadClassMetadataEventArgs $event, RegistryInterface $registry, ClassMetadata $classMetadata)
 {
     $registry->getByClass('Foo')->willThrow(\InvalidArgumentException::class);
     $classMetadata->setCustomRepositoryClass(Argument::any())->shouldNotBeCalled();
     $this->loadClassMetadata($event);
 }
开发者ID:okwinza,项目名称:Sylius,代码行数:6,代码来源:ORMRepositoryClassSubscriberSpec.php

示例7: __construct

 /**
  * QuestionnaireRepository constructor.
  * @param EntityManager $em
  * @param ClassMetadata $class
  */
 public function __construct(EntityManager $em, ClassMetadata $class)
 {
     $class->setCustomRepositoryClass(__CLASS__);
     parent::__construct($em, $class);
 }
开发者ID:TransformCore,项目名称:HayPersistenceApi,代码行数:10,代码来源:QuestionnaireRepository.php

示例8: setCustomRepositoryClass

 /**
  * Set custom Repository class name
  *
  * @param string $repositoryClassName
  * @return ClassMetadataBuilder
  */
 public function setCustomRepositoryClass($repositoryClassName)
 {
     $this->cm->setCustomRepositoryClass($repositoryClassName);
     return $this;
 }
开发者ID:ramonornela,项目名称:doctrine2,代码行数:11,代码来源:ClassMetadataBuilder.php

示例9: loadMetadataForClass

 /**
  * Loads the metadata for the specified class into the provided container.
  */
 public function loadMetadataForClass($className, ClassMetadata $metadata)
 {
     $annotClass = new \Addendum\ReflectionAnnotatedClass($className);
     // Evaluate DoctrineEntity annotation
     if (($entityAnnot = $annotClass->getAnnotation('DoctrineEntity')) === false) {
         throw DoctrineException::updateMe("{$className} is no entity.");
     }
     $metadata->setCustomRepositoryClass($entityAnnot->repositoryClass);
     // Evaluate DoctrineTable annotation
     if ($tableAnnot = $annotClass->getAnnotation('DoctrineTable')) {
         $metadata->setPrimaryTable(array('name' => $tableAnnot->name, 'schema' => $tableAnnot->schema, 'catalog' => $tableAnnot->catalog));
     }
     // Evaluate DoctrineInheritanceType annotation
     if ($inheritanceTypeAnnot = $annotClass->getAnnotation('DoctrineInheritanceType')) {
         $metadata->setInheritanceType($inheritanceTypeAnnot->value);
     }
     // Evaluate DoctrineDiscriminatorColumn annotation
     if ($discrColumnAnnot = $annotClass->getAnnotation('DoctrineDiscriminatorColumn')) {
         $metadata->setDiscriminatorColumn(array('name' => $discrColumnAnnot->name, 'type' => $discrColumnAnnot->type, 'length' => $discrColumnAnnot->length));
     }
     // Evaluate DoctrineDiscriminatorMap annotation
     if ($discrValueAnnot = $annotClass->getAnnotation('DoctrineDiscriminatorValue')) {
         $metadata->setDiscriminatorValue($discrValueAnnot->value);
     }
     // Evaluate DoctrineSubClasses annotation
     if ($subClassesAnnot = $annotClass->getAnnotation('DoctrineSubClasses')) {
         $metadata->setSubclasses($subClassesAnnot->value);
     }
     // Evaluate DoctrineChangeTrackingPolicy annotation
     if ($changeTrackingAnnot = $annotClass->getAnnotation('DoctrineChangeTrackingPolicy')) {
         $metadata->setChangeTrackingPolicy($changeTrackingAnnot->value);
     }
     // Evaluate annotations on properties/fields
     foreach ($annotClass->getProperties() as $property) {
         if ($metadata->hasField($property->getName())) {
             continue;
         }
         $mapping = array();
         $mapping['fieldName'] = $property->getName();
         // Check for DoctrineJoinColummn/DoctrineJoinColumns annotations
         $joinColumns = array();
         if ($joinColumnAnnot = $property->getAnnotation('DoctrineJoinColumn')) {
             $joinColumns[] = array('name' => $joinColumnAnnot->name, 'referencedColumnName' => $joinColumnAnnot->referencedColumnName, 'unique' => $joinColumnAnnot->unique, 'nullable' => $joinColumnAnnot->nullable, 'onDelete' => $joinColumnAnnot->onDelete, 'onUpdate' => $joinColumnAnnot->onUpdate);
         } else {
             if ($joinColumnsAnnot = $property->getAnnotation('DoctrineJoinColumns')) {
                 $joinColumns = $joinColumnsAnnot->value;
             }
         }
         // Field can only be annotated with one of: DoctrineColumn,
         // DoctrineOneToOne, DoctrineOneToMany, DoctrineManyToOne, DoctrineManyToMany
         if ($columnAnnot = $property->getAnnotation('DoctrineColumn')) {
             if ($columnAnnot->type == null) {
                 throw DoctrineException::updateMe("Missing type on property " . $property->getName());
             }
             $mapping['type'] = $columnAnnot->type;
             $mapping['length'] = $columnAnnot->length;
             $mapping['nullable'] = $columnAnnot->nullable;
             if ($idAnnot = $property->getAnnotation('DoctrineId')) {
                 $mapping['id'] = true;
             }
             if ($generatedValueAnnot = $property->getAnnotation('DoctrineGeneratedValue')) {
                 $metadata->setIdGeneratorType($generatedValueAnnot->strategy);
             }
             $metadata->mapField($mapping);
             // Check for SequenceGenerator/TableGenerator definition
             if ($seqGeneratorAnnot = $property->getAnnotation('DoctrineSequenceGenerator')) {
                 $metadata->setSequenceGeneratorDefinition(array('sequenceName' => $seqGeneratorAnnot->sequenceName, 'allocationSize' => $seqGeneratorAnnot->allocationSize, 'initialValue' => $seqGeneratorAnnot->initialValue));
             } else {
                 if ($tblGeneratorAnnot = $property->getAnnotation('DoctrineTableGenerator')) {
                     throw new DoctrineException("DoctrineTableGenerator not yet implemented.");
                 }
             }
         } else {
             if ($oneToOneAnnot = $property->getAnnotation('DoctrineOneToOne')) {
                 $mapping['targetEntity'] = $oneToOneAnnot->targetEntity;
                 $mapping['joinColumns'] = $joinColumns;
                 $mapping['mappedBy'] = $oneToOneAnnot->mappedBy;
                 $mapping['cascade'] = $oneToOneAnnot->cascade;
                 $metadata->mapOneToOne($mapping);
             } else {
                 if ($oneToManyAnnot = $property->getAnnotation('DoctrineOneToMany')) {
                     $mapping['mappedBy'] = $oneToManyAnnot->mappedBy;
                     $mapping['targetEntity'] = $oneToManyAnnot->targetEntity;
                     $mapping['cascade'] = $oneToManyAnnot->cascade;
                     $metadata->mapOneToMany($mapping);
                 } else {
                     if ($manyToOneAnnot = $property->getAnnotation('DoctrineManyToOne')) {
                         $mapping['joinColumns'] = $joinColumns;
                         $mapping['cascade'] = $manyToOneAnnot->cascade;
                         $mapping['targetEntity'] = $manyToOneAnnot->targetEntity;
                         $metadata->mapManyToOne($mapping);
                     } else {
                         if ($manyToManyAnnot = $property->getAnnotation('DoctrineManyToMany')) {
                             $joinTable = array();
                             if ($joinTableAnnot = $property->getAnnotation('DoctrineJoinTable')) {
                                 $joinTable = array('name' => $joinTableAnnot->name, 'schema' => $joinTableAnnot->schema, 'catalog' => $joinTableAnnot->catalog, 'joinColumns' => $joinTableAnnot->joinColumns, 'inverseJoinColumns' => $joinTableAnnot->inverseJoinColumns);
                             }
//.........这里部分代码省略.........
开发者ID:jackbravo,项目名称:doctrine,代码行数:101,代码来源:AnnotationDriver.php


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