Exemplo n.º 1
0
 /**
  * Tests if getAlias() throws Exception.
  *
  * @expectedException        \DomainException
  */
 public function testGetAliasException()
 {
     /** @var \ONGR\ElasticsearchBundle\Document\DocumentInterface $stub */
     $stub = $this->getMockBuilder('\\ONGR\\ElasticsearchBundle\\Document\\DocumentInterface')->getMock();
     $converter = new Converter([], []);
     $converter->convertToArray($stub);
 }
Exemplo n.º 2
0
 /**
  * Converts document to array.
  *
  * @param DocumentInterface $document
  *
  * @return array
  */
 private function convertToArray($document)
 {
     $manager = $this->getManager();
     if (!$this->converter) {
         $this->converter = new Converter($manager->getTypesMapping(), $manager->getBundlesMapping());
     }
     return $this->converter->convertToArray($document);
 }
Exemplo n.º 3
0
 /**
  * Adds document for removal.
  *
  * @param object $document
  */
 public function remove($document)
 {
     $data = $this->converter->convertToArray($document, [], ['_id']);
     if (!isset($data['_id'])) {
         throw new \LogicException('In order to use remove() method document class must have property with @Id annotation.');
     }
     $type = $this->getMetadataCollector()->getDocumentType(get_class($document));
     $this->bulk('delete', $type, ['_id' => $data['_id']]);
 }
 /**
  * {@inheritdoc}
  */
 protected function convertDocument(array $document)
 {
     return $this->converter->assignArrayToObject($document, new $this->alias['namespace'](), $this->alias['aliases']);
 }
Exemplo n.º 5
0
 /**
  * Adds document to next flush.
  *
  * @param DocumentInterface $document
  */
 public function persist(DocumentInterface $document)
 {
     $documentArray = $this->converter->convertToArray($document);
     $typeMapping = $this->getMetadataCollector()->getDocumentMapping($document);
     $this->bulk('index', $typeMapping['type'], $documentArray);
 }
 /**
  * {@inheritdoc}
  */
 public function offsetGet($offset)
 {
     return $this->converter->convertToDocument($this->raw['hits'][$offset]);
 }