/**
  * @param object $entity
  *
  * @return MetaInformation
  *
  * @throws \RuntimeException if no declaration for document found in $entity
  */
 public function loadInformation($entity)
 {
     $className = $this->getClass($entity);
     if (!is_object($entity)) {
         $reflectionClass = new \ReflectionClass($className);
         if (!$reflectionClass->isInstantiable()) {
             throw new \RuntimeException(sprintf('cannot instantiate entity %s', $className));
         }
         $entity = $reflectionClass->newInstanceWithoutConstructor();
     }
     if (!$this->annotationReader->hasDocumentDeclaration($entity)) {
         throw new \RuntimeException(sprintf('no declaration for document found in entity %s', $className));
     }
     $metaInformation = new MetaInformation();
     $metaInformation->setEntity($entity);
     $metaInformation->setClassName($className);
     $metaInformation->setDocumentName($this->getDocumentName($className));
     $metaInformation->setFieldMapping($this->annotationReader->getFieldMapping($entity));
     $metaInformation->setFields($this->annotationReader->getFields($entity));
     $metaInformation->setRepository($this->annotationReader->getRepository($entity));
     $metaInformation->setIdentifier($this->annotationReader->getIdentifier($entity));
     $metaInformation->setBoost($this->annotationReader->getEntityBoost($entity));
     $metaInformation->setSynchronizationCallback($this->annotationReader->getSynchronizationCallback($entity));
     $metaInformation->setIndex($this->annotationReader->getDocumentIndex($entity));
     $metaInformation->setIsDoctrineEntity($this->annotationReader->isDoctrineEntity($entity));
     return $metaInformation;
 }
Ejemplo n.º 2
0
 public function testGetFieldMapping_ThreeMappingsAndId()
 {
     $fields = $this->reader->getFieldMapping(new ValidTestEntity());
     $this->assertEquals(5, count($fields), 'five fields are mapped');
     $this->assertTrue(array_key_exists('title', $fields));
     $this->assertTrue(array_key_exists('id', $fields));
 }
Ejemplo n.º 3
0
 public function testGetFieldMapping_ThreeMappingsAndId()
 {
     $reader = new AnnotationReader();
     $fields = $reader->getFieldMapping(new ValidTestEntity());
     $this->assertEquals(4, count($fields), 'four fields are mapped');
     $this->assertTrue(array_key_exists('title_s', $fields));
     $this->assertTrue(array_key_exists('id', $fields));
 }
Ejemplo n.º 4
0
 /**
  * @param string|object entityAlias
  * @return MetaInformation
  */
 public function loadInformation($entity)
 {
     $className = $this->getClass($entity);
     if (!is_object($entity)) {
         $entity = new $className();
     }
     if (!$this->annotationReader->hasDocumentDeclaration($entity)) {
         throw new \RuntimeException(sprintf('no declaration for document found in entity %s', $className));
     }
     $metaInformation = new MetaInformation();
     $metaInformation->setEntity($entity);
     $metaInformation->setClassName($className);
     $metaInformation->setDocumentName($this->getDocumentName($className));
     $metaInformation->setFieldMapping($this->annotationReader->getFieldMapping($entity));
     $metaInformation->setFields($this->annotationReader->getFields($entity));
     $metaInformation->setRepository($this->annotationReader->getRepository($entity));
     $metaInformation->setIdentifier($this->annotationReader->getIdentifier($entity));
     $metaInformation->setBoost($this->annotationReader->getEntityBoost($entity));
     $metaInformation->setSynchronizationCallback($this->annotationReader->getSynchronizationCallback($entity));
     return $metaInformation;
 }