Newer
Older
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
namespace App\Restaurants\Request;
use App\Shared\Service\ValidationService;
use Symfony\Component\HttpFoundation\Request;
class RestaurantListingRequest
{
public int $page = 1;
public int $limit = 12;
public ?string $restaurant_type_id = null;
public ?string $kitchen_id = null;
public function __construct(
private readonly ValidationService $validation,
) {
$this->populate();
$this->checkAndCorrectParams();
}
private function checkAndCorrectParams(): void
{
if (!$this->validation->isPageValid($this->page)) {
$this->page = 1;
}
if (!$this->validation->isLimitValid($this->limit)) {
$this->limit = 12;
}
if (!$this->validation->isUuidValid($this->restaurant_type_id)) {
$this->restaurant_type_id = null;
}
if (!$this->validation->isUuidValid($this->kitchen_id)) {
$this->kitchen_id = null;
}
}
private function populate(): void
{
foreach (
$this->getRequest()->query->getIterator() as $property => $value
) {
if (property_exists($this, $property)) {
$this->{$property} = $value;
}
}
}
public function getRequest(): Request
{
return Request::createFromGlobals();
}
}