/** * @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; }
/** * @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; }
/** * @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; }