Loading src/Controller/CountFriday13Controller.php 0 → 100644 +28 −0 Original line number Diff line number Diff line <?php namespace App\Controller; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Attribute\Route; use function App\Repository\countFriday13; class CountFriday13Controller extends AbstractController { /** * git Контроллер вернет все пятницы 13 в году используя countFriday13 функцию * @param Request $request * @return Response */ #[Route('/count/friday13', name: 'app_count_friday13')] public function index(Request $request): Response { $year = $request->toArray()['year']; $returnableArray = countFriday13($year); return new JsonResponse($returnableArray, Response::HTTP_OK); } } src/Repository/CountFriday13Repository.php 0 → 100644 +23 −0 Original line number Diff line number Diff line <?php namespace App\Repository; use DateTimeImmutable; /** * Вернет все пятницы 13 в году * @param int $yaer год, в котором необходимо произвести расчет * @return DateTimeImmutable[] */ function countFriday13(int $year): iterable { $date = new DateTimeImmutable(); $AllFri13 = []; for ($i = 1; $i<=12; $i++ ){ $next13 = $date->setDate($year, $i, 13); if ($next13->format("D") === 'Fri'){ $AllFri13[] = $next13; } } return $AllFri13; } Loading
src/Controller/CountFriday13Controller.php 0 → 100644 +28 −0 Original line number Diff line number Diff line <?php namespace App\Controller; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Attribute\Route; use function App\Repository\countFriday13; class CountFriday13Controller extends AbstractController { /** * git Контроллер вернет все пятницы 13 в году используя countFriday13 функцию * @param Request $request * @return Response */ #[Route('/count/friday13', name: 'app_count_friday13')] public function index(Request $request): Response { $year = $request->toArray()['year']; $returnableArray = countFriday13($year); return new JsonResponse($returnableArray, Response::HTTP_OK); } }
src/Repository/CountFriday13Repository.php 0 → 100644 +23 −0 Original line number Diff line number Diff line <?php namespace App\Repository; use DateTimeImmutable; /** * Вернет все пятницы 13 в году * @param int $yaer год, в котором необходимо произвести расчет * @return DateTimeImmutable[] */ function countFriday13(int $year): iterable { $date = new DateTimeImmutable(); $AllFri13 = []; for ($i = 1; $i<=12; $i++ ){ $next13 = $date->setDate($year, $i, 13); if ($next13->format("D") === 'Fri'){ $AllFri13[] = $next13; } } return $AllFri13; }