Skip to content
HomeController.php 934 B
Newer Older
Адлан Шамавов's avatar
Адлан Шамавов committed
<?php

namespace App\Controller;

Адлан Шамавов's avatar
Адлан Шамавов committed
use App\Action\Functions;
use DateTimeImmutable;
Адлан Шамавов's avatar
Адлан Шамавов committed
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
Адлан Шамавов's avatar
Адлан Шамавов committed
use Symfony\Component\HttpFoundation\Request;
Адлан Шамавов's avatar
Адлан Шамавов committed
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;

class HomeController extends AbstractController
{
Адлан Шамавов's avatar
Адлан Шамавов committed
    private Functions $functions;
Адлан Шамавов's avatar
Адлан Шамавов committed

Адлан Шамавов's avatar
Адлан Шамавов committed
    public function __construct(Functions $functions)
Адлан Шамавов's avatar
Адлан Шамавов committed
    {
Адлан Шамавов's avatar
Адлан Шамавов committed
        $this->functions = $functions;
    }
Адлан Шамавов's avatar
Адлан Шамавов committed
    #[Route('/{day}/{month}/{year}', name: 'home')]
    public function home(int $day, int $month, int $year): Response
    {
        $dateAsString = $year . "-" . $month . "-" . $day;
        try {
            $result = $this->functions->howDaysToNy(new DateTimeImmutable($dateAsString));
        } catch (\Exception $e) {
            return new Response($e->getMessage());
        }
        return $this->json(["Days before NY:" => $result]);
Адлан Шамавов's avatar
Адлан Шамавов committed
    }
}