コード例 #1
0
 /**
  * Test if function throws exception if ES type names are not unique.
  */
 public function testGetBundleMappingWithDocumentSubdirectory()
 {
     $mapping = $this->metadataCollector->getMappings(['AcmeBazBundle']);
     $this->assertArrayHasKey('product', $mapping);
     $this->assertNotEmpty($mapping['product']['objects']);
     $this->assertEquals('ONGR\\ElasticsearchBundle\\Tests\\app\\fixture\\Acme\\BazBundle\\Document\\Object\\CategoryObject', $mapping['product']['objects'][0]);
 }
コード例 #2
0
 /**
  * Converts raw array to document.
  *
  * @param array      $rawData
  * @param Repository $repository
  *
  * @return DocumentInterface
  *
  * @throws \LogicException
  */
 public function convertToDocument($rawData, $repository)
 {
     $types = $this->metadataCollector->getMappings($repository->getManager()->getConfig()['mappings']);
     if (isset($types[$rawData['_type']])) {
         $metadata = $types[$rawData['_type']];
     } else {
         throw new \LogicException("Got document of unknown type '{$rawData['_type']}'.");
     }
     $data = isset($rawData['_source']) ? $rawData['_source'] : array_map('reset', $rawData['fields']);
     /** @var DocumentInterface $object */
     $object = $this->assignArrayToObject($data, new $metadata['namespace'](), $metadata['aliases']);
     $this->setObjectFields($object, $rawData, ['_id', '_score', 'fields _parent', 'fields _ttl']);
     return $object;
 }
コード例 #3
0
 /**
  * Converts raw array to document.
  *
  * @param array   $rawData
  * @param Manager $manager
  *
  * @return object
  *
  * @throws \LogicException
  */
 public function convertToDocument($rawData, Manager $manager)
 {
     $types = $this->metadataCollector->getMappings($manager->getConfig()['mappings']);
     if (isset($types[$rawData['_type']])) {
         $metadata = $types[$rawData['_type']];
     } else {
         throw new \LogicException("Got document of unknown type '{$rawData['_type']}'.");
     }
     switch (true) {
         case isset($rawData['_source']):
             $rawData = array_merge($rawData, $rawData['_source']);
             break;
         case isset($rawData['fields']):
             $rawData = array_merge($rawData, $rawData['fields']);
             break;
         default:
             // Do nothing.
             break;
     }
     $object = $this->assignArrayToObject($rawData, new $metadata['namespace'](), $metadata['aliases']);
     return $object;
 }
コード例 #4
0
 /**
  * Test if function throws exception if ES type names are not unique.
  *
  * @expectedException \LogicException
  */
 public function testGetBundleMappingWithTwoSameESTypes()
 {
     $this->metadataCollector->getMappings(['AcmeBarBundle', 'AcmeBarBundle']);
 }