Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Adapter.php
Go to the documentation of this file.
1 <?php
7 
13 
21 class Adapter implements AdapterInterface
22 {
28  protected $mapper;
29 
35  protected $responseFactory;
36 
40  private $resource;
41 
45  private $aggregationBuilder;
46 
50  private $temporaryStorageFactory;
51 
59  public function __construct(
62  ResourceConnection $resource,
63  AggregationBuilder $aggregationBuilder,
64  TemporaryStorageFactory $temporaryStorageFactory
65  ) {
66  $this->mapper = $mapper;
67  $this->responseFactory = $responseFactory;
68  $this->resource = $resource;
69  $this->aggregationBuilder = $aggregationBuilder;
70  $this->temporaryStorageFactory = $temporaryStorageFactory;
71  }
72 
77  public function query(RequestInterface $request)
78  {
79  $query = $this->mapper->buildQuery($request);
80  $temporaryStorage = $this->temporaryStorageFactory->create();
81  $table = $temporaryStorage->storeDocumentsFromSelect($query);
82 
83  $documents = $this->getDocuments($table);
84 
85  $aggregations = $this->aggregationBuilder->build($request, $table, $documents);
86  $response = [
87  'documents' => $documents,
88  'aggregations' => $aggregations,
89  ];
90  return $this->responseFactory->create($response);
91  }
92 
100  private function getDocuments(Table $table)
101  {
102  $connection = $this->getConnection();
103  $select = $connection->select();
104  $select->from($table->getName(), ['entity_id', 'score']);
105  return $connection->fetchAssoc($select);
106  }
107 
113  private function getConnection()
114  {
115  return $this->resource->getConnection();
116  }
117 }
$response
Definition: 404.php:11
$resource
Definition: bulk.php:12
query(RequestInterface $request)
Definition: Adapter.php:77
__construct(Mapper $mapper, ResponseFactory $responseFactory, ResourceConnection $resource, AggregationBuilder $aggregationBuilder, TemporaryStorageFactory $temporaryStorageFactory)
Definition: Adapter.php:59
$connection
Definition: bulk.php:13
$table
Definition: trigger.php:14