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
<?php
namespace App\Restaurants\Request;
use App\Shared\Error\NotFoundError;
use App\Shared\Service\ValidationService;
use Symfony\Component\HttpFoundation\Request;
class RestaurantDetailRequest
{
public string $detailId;
public function __construct(
private readonly ValidationService $validation,
) {
$this->populate();
$this->checkAndCorrectParams();
}
private function checkAndCorrectParams(): void
{
if (!$this->validation->isUuidValid($this->detailId)) {
throw new NotFoundError('Restaurant not found');
}
}
private function populate(): void
{
$requestUrl = $this->getRequest()->getUri();
$index = strrpos($requestUrl, "/") + 1;
$restaurantId = substr($requestUrl, $index);
if (property_exists($this, "detailId")) {
$this->{"detailId"} = $restaurantId;
}
}
public function getRequest(): Request
{
return Request::createFromGlobals();
}
}