コード例 #1
0
 /**
  * @param \Flowpack\ElasticSearch\Domain\Model\AbstractType $type
  * @param string $id
  * @param \Flowpack\ElasticSearch\Transfer\Response $response
  * @throws \Flowpack\ElasticSearch\Domain\Exception\DocumentPropertiesMismatchException
  * @return \Flowpack\ElasticSearch\Domain\Model\Document
  */
 public function createFromResponse(Model\AbstractType $type, $id = null, \Flowpack\ElasticSearch\Transfer\Response $response)
 {
     $content = $response->getTreatedContent();
     $verificationResults = new ErrorResult();
     if (isset($content['_index']) && $type->getIndex()->getName() !== $content['_index']) {
         $error = new Error('The received index name "%s" does not match the expected one "%s".', 1340264838, array($content['_index'], $type->getIndex()->getName()));
         $verificationResults->addError($error);
     }
     if (isset($content['_type']) && $type->getName() !== $content['_type']) {
         $error = new Error('The received type name "%s" does not match the expected one "%s".', 1340265103, array($content['_type'], $type->getName()));
         $verificationResults->addError($error);
     }
     if (isset($content['_id']) && $id !== null && $id !== $content['_id']) {
         $error = new Error('The received id "%s" does not match the expected one "%s".', 1340269758, array($content['_id'], $id));
         $verificationResults->addError($error);
     }
     if ($verificationResults->hasErrors()) {
         $exception = new \Flowpack\ElasticSearch\Domain\Exception\DocumentPropertiesMismatchException('The document\'s properties do not match the expected ones.', 1340265248);
         $exception->setErrorResult($verificationResults);
         throw $exception;
     }
     $version = $content['_version'];
     $data = $content['_source'];
     return new Model\Document($type, $data, $id, $version);
 }
コード例 #2
0
 /**
  * Gets a specific field's value from this' data
  *
  * @param string $fieldName
  * @param boolean $silent
  *
  * @throws \Flowpack\ElasticSearch\Exception
  * @return mixed
  */
 public function getField($fieldName, $silent = false)
 {
     if (!array_key_exists($fieldName, $this->data) && $silent === false) {
         throw new \Flowpack\ElasticSearch\Exception(sprintf('The field %s was not present in data of document in %s/%s.', $fieldName, $this->type->getIndex()->getName(), $this->type->getName()), 1340274696);
     }
     return $this->data[$fieldName];
 }