示例#1
0
 /**
  * Verify that all types are in indices using the same connection object and return that object
  *
  * @param array $documentClasses
  * @return ConnectionManager
  */
 private function getConnection(array $documentClasses)
 {
     $connection = null;
     foreach ($documentClasses as $documentClass) {
         $indexManagerName = $this->documentMetadataCollector->getDocumentClassIndex($documentClass);
         $indexManager = $this->indexManagerRegistry->get($indexManagerName);
         if (!is_null($connection) && $indexManager->getConnection()->getConnectionName() != $connection->getConnectionName()) {
             throw new \InvalidArgumentException(sprintf('All searched types must be in indices within the same connection'));
         }
         $connection = $indexManager->getConnection();
     }
     return $connection;
 }
 /**
  * Returns the index manager managing a given Elasticsearch entity
  *
  * @param DocumentInterface $entity
  * @return IndexManager
  */
 public function getByEntity(DocumentInterface $entity)
 {
     $indexManagerName = $this->metadataCollector->getDocumentClassIndex(get_class($entity));
     return $this->get($indexManagerName);
 }