/**
  * @param MetaInformationInterface $meta
  *
  * @return Document
  */
 public function createDocument(MetaInformationInterface $meta)
 {
     $document = new Document();
     $document->setKey(MetaInformationInterface::DOCUMENT_KEY_FIELD_NAME, $meta->getDocumentKey());
     $document->setBoost($meta->getBoost());
     return $document;
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 public function hydrate($document, MetaInformationInterface $metaInformation)
 {
     $sourceTargetEntity = $metaInformation->getEntity();
     $targetEntity = clone $sourceTargetEntity;
     $metaInformation->setEntity($targetEntity);
     return $this->valueHydrator->hydrate($document, $metaInformation);
 }
Beispiel #3
0
 /**
  * {@inheritdoc}
  */
 public function hydrate($document, MetaInformationInterface $metaInformation)
 {
     $targetEntity = $metaInformation->getEntity();
     $reflectionClass = new \ReflectionClass($targetEntity);
     foreach ($document as $property => $value) {
         if ($property === MetaInformationInterface::DOCUMENT_KEY_FIELD_NAME) {
             $value = $this->removePrefixedKeyFieldName($value);
         }
         // skip field if value is array or "flat" object
         // hydrated object should contain a list of real entities / entity
         if ($this->mapValue($property, $value, $metaInformation) == false) {
             continue;
         }
         try {
             $classProperty = $reflectionClass->getProperty($this->removeFieldSuffix($property));
         } catch (\ReflectionException $e) {
             try {
                 $classProperty = $reflectionClass->getProperty($this->toCamelCase($this->removeFieldSuffix($property)));
             } catch (\ReflectionException $e) {
                 continue;
             }
         }
         $classProperty->setAccessible(true);
         $classProperty->setValue($targetEntity, $value);
     }
     return $targetEntity;
 }
 /**
  * @param MetaInformationInterface $meta
  *
  * @return Document
  */
 public function createDocument(MetaInformationInterface $meta)
 {
     $document = new Document();
     $document->addField('id', $meta->getEntityId());
     $document->addField('document_name_s', $meta->getDocumentName());
     $document->setBoost($meta->getBoost());
     return $document;
 }
 /**
  * {@inheritdoc}
  */
 public function hydrate($document, MetaInformationInterface $metaInformation)
 {
     $entityId = $metaInformation->getEntityId();
     $doctrineEntity = $this->doctrine->getManager()->getRepository($metaInformation->getClassName())->find($entityId);
     if ($doctrineEntity !== null) {
         $metaInformation->setEntity($doctrineEntity);
     }
     return $this->valueHydrator->hydrate($document, $metaInformation);
 }
 /**
  * @param MetaInformationInterface $meta
  *
  * @return null|\Solarium\QueryType\Update\Query\Document\Document
  */
 public function createDocument(MetaInformationInterface $meta)
 {
     $fields = $meta->getFields();
     if (count($fields) == 0) {
         return null;
     }
     $document = parent::createDocument($meta);
     foreach ($fields as $field) {
         if (!$field instanceof Field) {
             continue;
         }
         $document->addField($field->getNameWithAlias(), $field->getValue(), $field->getBoost());
     }
     return $document;
 }
 /**
  * {@inheritdoc}
  */
 public function mapValue($fieldName, $value, MetaInformationInterface $metaInformation)
 {
     if (is_array($value)) {
         return false;
     }
     if ($metaInformation->getField($fieldName) && $metaInformation->getField($fieldName)->getter) {
         return false;
     }
     $fieldSuffix = $this->removePrefixedKeyFieldName($fieldName);
     if ($fieldSuffix === false) {
         return false;
     }
     if (array_key_exists($fieldSuffix, Field::getComplexFieldMapping())) {
         return false;
     }
     return true;
 }
Beispiel #8
0
 /**
  * {@inheritdoc}
  */
 public function hydrate($document, MetaInformationInterface $metaInformation)
 {
     $targetEntity = $metaInformation->getEntity();
     $reflectionClass = new \ReflectionClass($targetEntity);
     foreach ($document as $property => $value) {
         try {
             $classProperty = $reflectionClass->getProperty($this->removeFieldSuffix($property));
         } catch (\ReflectionException $e) {
             try {
                 $classProperty = $reflectionClass->getProperty($this->toCamelCase($this->removeFieldSuffix($property)));
             } catch (\ReflectionException $e) {
                 continue;
             }
         }
         $classProperty->setAccessible(true);
         $classProperty->setValue($targetEntity, $value);
     }
     return $targetEntity;
 }
 /**
  * @param MetaInformationInterface $meta
  *
  * @return null|\Solarium\QueryType\Update\Query\Document\Document
  */
 public function createDocument(MetaInformationInterface $meta)
 {
     $fields = $meta->getFields();
     if (count($fields) == 0) {
         return null;
     }
     $document = parent::createDocument($meta);
     foreach ($fields as $field) {
         if (!$field instanceof Field) {
             continue;
         }
         $value = $field->getValue();
         if ($value instanceof Collection) {
             $document->addField($field->getNameWithAlias(), $this->mapCollection($field), $field->getBoost());
         } elseif (is_object($value)) {
             $document->addField($field->getNameWithAlias(), $this->mapObject($field), $field->getBoost());
         } else {
             $document->addField($field->getNameWithAlias(), $field->getValue(), $field->getBoost());
         }
     }
     return $document;
 }
Beispiel #10
0
 /**
  * @param MetaInformationInterface $metaInformation
  */
 public function setMetaInformation($metaInformation)
 {
     $this->metaInformation = $metaInformation;
     $this->entity = $metaInformation->getEntity();
     $this->index = $metaInformation->getIndex();
 }
Beispiel #11
0
 /**
  * @param object                   $doc
  * @param MetaInformationInterface $metaInformation
  * @param Event                    $event
  */
 private function addDocumentToIndex($doc, MetaInformationInterface $metaInformation, Event $event)
 {
     try {
         $indexName = $metaInformation->getIndex();
         $client = new \FS\SolrBundle\Client\Client($this->solrClientCore);
         $client->update($doc, $indexName);
     } catch (\Exception $e) {
         $errorEvent = new ErrorEvent(null, $metaInformation, json_encode($this->solrClientCore->getOptions()), $event);
         $errorEvent->setException($e);
         $this->eventManager->dispatch(Events::ERROR, $errorEvent);
     }
 }
 /**
  * @param MetaInformationInterface $metaInformation
  *
  * @return string
  */
 protected function createFieldList(MetaInformationInterface $metaInformation)
 {
     return implode(', ', $metaInformation->getFields());
 }