-
Notifications
You must be signed in to change notification settings - Fork 1
/
CarRepository.php
38 lines (31 loc) · 1.02 KB
/
CarRepository.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
declare(strict_types=1);
namespace App\Elasticsearch\Repository;
use App\Elasticsearch\Hydrator\CarsHydratorInterface;
use App\Elasticsearch\Service\ApiClientInterface;
use App\Elasticsearch\ValueObject\Criteria\Criteria;
use App\Elasticsearch\ValueObject\Query;
use App\Elasticsearch\ValueObject\Sorter\RecommendedSorter;
use App\Enum\Index;
use App\Repository\CarRepositoryInterface;
use App\ValueObject\Cars;
use App\ValueObject\CriteriaInterface;
use App\ValueObject\Pagination;
final class CarRepository implements CarRepositoryInterface
{
private Index $index;
public function __construct(
private ApiClientInterface $client,
private CarsHydratorInterface $hydrator
)
{
$this->index = Index::CARS();
}
public function find(Pagination $pagination, ?CriteriaInterface $criteria = null): Cars
{
$query = new Query($pagination, $criteria ?? new Criteria);
$query->setSorter(new RecommendedSorter);
$response = $this->client->search($this->index, $query);
return $this->hydrator->hydrate($response);
}
}