Loading src/Controller/HomeController.php +10 −20 Original line number Diff line number Diff line Loading @@ -8,6 +8,8 @@ use App\Requests\{ SearchRequest, UniqElementsRequest, MenuRequest, HowDaysToNyRequest, CountFriday13Request, DiffDaysRequest }; use DateTimeImmutable; Loading Loading @@ -49,34 +51,22 @@ class HomeController extends AbstractController return $this->json($result); } #[Route( '/howDaysToNy/{day}/{month}/{year}', name: 'howDaysToNy', requirements: [ 'day' => '(?<!-)(?<!\d)\d+', 'month' => '(?<!-)(?<!\d)\d+', 'year' => '(?<!-)(?<!\d)\d+' ], methods: ['GET'] )] public function howDaysToNy(int $day, int $month, int $year): Response #[Route('/howDaysToNy', name: 'howDaysToNy', methods: ['GET'])] public function howDaysToNy(HowDaysToNyRequest $request): Response { $dateAsString = $year . "-" . $month . "-" . $day; $date = $request->getRequest()->get('date'); try { $result = $this->functions->howDaysToNy(new DateTimeImmutable($dateAsString)); $result = $this->functions->howDaysToNy(new DateTimeImmutable($date)); } catch (\Exception $e) { return new Response($e->getMessage()); } return $this->json(["Days before NY:" => $result]); } #[Route( '/countFriday13/{year}', name: 'countFriday13', requirements: ['year' => '(?<!-)(?<!\d)\d+'], methods: ['GET'])] public function countFriday13(int $year): Response #[Route('/countFriday13', name: 'countFriday13', methods: ['GET'])] public function countFriday13(CountFriday13Request $request): Response { $year = $request->getRequest()->get('year'); $fridays = array(); try { foreach ($this->functions->countFriday13($year) as $date) { Loading @@ -88,7 +78,7 @@ class HomeController extends AbstractController return $this->json($fridays); } #[Route('/diffDays/', name: 'diffDays')] // 01-01-2024 #[Route('/diffDays', name: 'diffDays')] // 01-01-2024 public function diffDays(DiffDaysRequest $request): Response { try { Loading src/Requests/CountFriday13Request.php 0 → 100644 +21 −0 Original line number Diff line number Diff line <?php namespace App\Requests; use Symfony\Component\Validator\Constraints as Assert; class CountFriday13Request extends BaseRequest { #[Assert\Type('int')] #[Assert\Positive] public int $year; protected function populate(): void { foreach ($this->getRequest()->query->all() as $property => $value) { if (property_exists($this, $property)) { $this->{$property} = $value; } } } } No newline at end of file src/Requests/HowDaysToNyRequest.php 0 → 100644 +11 −0 Original line number Diff line number Diff line <?php namespace App\Requests; use Symfony\Component\Validator\Constraints as Assert; class HowDaysToNyRequest extends BaseRequest { #[Assert\Type('date')] public $date; } Loading
src/Controller/HomeController.php +10 −20 Original line number Diff line number Diff line Loading @@ -8,6 +8,8 @@ use App\Requests\{ SearchRequest, UniqElementsRequest, MenuRequest, HowDaysToNyRequest, CountFriday13Request, DiffDaysRequest }; use DateTimeImmutable; Loading Loading @@ -49,34 +51,22 @@ class HomeController extends AbstractController return $this->json($result); } #[Route( '/howDaysToNy/{day}/{month}/{year}', name: 'howDaysToNy', requirements: [ 'day' => '(?<!-)(?<!\d)\d+', 'month' => '(?<!-)(?<!\d)\d+', 'year' => '(?<!-)(?<!\d)\d+' ], methods: ['GET'] )] public function howDaysToNy(int $day, int $month, int $year): Response #[Route('/howDaysToNy', name: 'howDaysToNy', methods: ['GET'])] public function howDaysToNy(HowDaysToNyRequest $request): Response { $dateAsString = $year . "-" . $month . "-" . $day; $date = $request->getRequest()->get('date'); try { $result = $this->functions->howDaysToNy(new DateTimeImmutable($dateAsString)); $result = $this->functions->howDaysToNy(new DateTimeImmutable($date)); } catch (\Exception $e) { return new Response($e->getMessage()); } return $this->json(["Days before NY:" => $result]); } #[Route( '/countFriday13/{year}', name: 'countFriday13', requirements: ['year' => '(?<!-)(?<!\d)\d+'], methods: ['GET'])] public function countFriday13(int $year): Response #[Route('/countFriday13', name: 'countFriday13', methods: ['GET'])] public function countFriday13(CountFriday13Request $request): Response { $year = $request->getRequest()->get('year'); $fridays = array(); try { foreach ($this->functions->countFriday13($year) as $date) { Loading @@ -88,7 +78,7 @@ class HomeController extends AbstractController return $this->json($fridays); } #[Route('/diffDays/', name: 'diffDays')] // 01-01-2024 #[Route('/diffDays', name: 'diffDays')] // 01-01-2024 public function diffDays(DiffDaysRequest $request): Response { try { Loading
src/Requests/CountFriday13Request.php 0 → 100644 +21 −0 Original line number Diff line number Diff line <?php namespace App\Requests; use Symfony\Component\Validator\Constraints as Assert; class CountFriday13Request extends BaseRequest { #[Assert\Type('int')] #[Assert\Positive] public int $year; protected function populate(): void { foreach ($this->getRequest()->query->all() as $property => $value) { if (property_exists($this, $property)) { $this->{$property} = $value; } } } } No newline at end of file
src/Requests/HowDaysToNyRequest.php 0 → 100644 +11 −0 Original line number Diff line number Diff line <?php namespace App\Requests; use Symfony\Component\Validator\Constraints as Assert; class HowDaysToNyRequest extends BaseRequest { #[Assert\Type('date')] public $date; }