/** * 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); }
/** * 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); }
/** * 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']); }
/** * 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]); }