コード例 #1
0
 /**
  * @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;
 }
コード例 #2
0
 public function testSetFieldValue()
 {
     $value1 = $this->createFieldObject('field1', 'oldfieldvalue');
     $value2 = $this->createFieldObject('field2', true);
     $fields = array('field1' => $value1, 'field2' => $value2);
     $information = new MetaInformation();
     $information->setFields($fields);
     $expectedValue = 'newFieldValue';
     $information->setFieldValue('field2', $expectedValue);
     $this->assertEquals($expectedValue, $information->getField('field2')->value, 'field2 should have new value');
 }
コード例 #3
0
 /**
  * @return MetaInformation
  */
 public static function getMetaInformation()
 {
     $entity = new ValidTestEntity();
     $entity->setId(2);
     $metaInformation = new MetaInformation();
     $title = new Field(array('name' => 'title', 'type' => 'string', 'boost' => '1.8'));
     $text = new Field(array('name' => 'text', 'type' => 'text'));
     $createdAt = new Field(array('name' => 'created_at', 'type' => 'date', 'boost' => '1'));
     $metaInformation->setFields(array($title, $text, $createdAt));
     $fieldMapping = array('id' => 'id', 'title_s' => 'title', 'text_t' => 'text', 'created_at_dt' => 'created_at');
     $metaInformation->setBoost(1);
     $metaInformation->setFieldMapping($fieldMapping);
     $metaInformation->setEntity($entity);
     $metaInformation->setDocumentName('validtestentity');
     $metaInformation->setClassName(get_class($entity));
     return $metaInformation;
 }
コード例 #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;
 }