Skip to content
Snippets Groups Projects
Commit 17fe374e authored by Akex's avatar Akex Committed by Александр Плохих
Browse files

make controller

parent 295a6342
No related branches found
No related tags found
1 merge request!6make controller
<?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);
}
}
<?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;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment