public function testGetSet()
 {
     $obj = new TypesToDocumentClasses();
     $obj->set('my_real_index', 'my_real_type', 'AppBundle:Type');
     $res = $obj->get('my_real_index', 'my_real_type');
     $this->assertEquals('AppBundle:Type', $res);
     $obj->set(null, 'second_real_type', 'AppBundle:Type');
     $res = $obj->get('second_real_index', 'second_real_type');
     $this->assertEquals('AppBundle:Type', $res);
     $this->setExpectedException('InvalidArgumentException');
     $obj->get('non_existing_index', 'my_real_type');
 }
 /**
  * Converts raw array to document.
  *
  * @param array $rawData
  *
  * @return DocumentInterface
  *
  * @throws \LogicException
  */
 private function convertToDocument($rawData)
 {
     $documentClass = $this->typesToDocumentClasses->get($rawData['_index'], $rawData['_type']);
     return $this->documentConverter->convertToDocument($rawData, $documentClass);
 }
Example #3
0
 /**
  * Returns a mapping of live indices and types to the document classes in short notation that represent them
  *
  * @param string[] $documentClasses
  * @return TypesToDocumentClasses
  */
 private function getTypesToDocumentClasses(array $documentClasses)
 {
     $typesToDocumentClasses = new TypesToDocumentClasses();
     $documentClassToIndexMap = $this->documentMetadataCollector->getDocumentClassesIndices($documentClasses);
     $documentClassToTypeMap = $this->documentMetadataCollector->getDocumentClassesTypes($documentClasses);
     $getLiveIndices = false;
     // If there are duplicate type names across the indices we're querying
     if (count($documentClassToTypeMap) > count(array_unique($documentClassToTypeMap))) {
         // We'll need to get the live index name for each type, so we can correctly map the results to the appropriate objects
         $getLiveIndices = true;
     }
     foreach ($documentClassToIndexMap as $documentClass => $indexManagerName) {
         // Build mappings of indices and types to document class names, for the Converter
         $liveIndex = $getLiveIndices ? $this->indexManagerRegistry->get($indexManagerName)->getLiveIndex() : null;
         $typesToDocumentClasses->set($liveIndex, $documentClassToTypeMap[$documentClass], $documentClass);
     }
     return $typesToDocumentClasses;
 }