Loading src/Action/Functions.php +8 −10 Original line number Diff line number Diff line Loading @@ -158,7 +158,6 @@ class Functions return (int)$dateInterval->format("%a") + 1; } /** * Вернет все пятницы 13 в году * @param int $year год, в котором необходимо произвести расчет Loading @@ -177,4 +176,3 @@ class Functions } } } No newline at end of file src/Controller/HomeController.php +57 −0 Original line number Diff line number Diff line Loading @@ -3,8 +3,11 @@ namespace App\Controller; use App\Action\Functions; use App\Validation\ArrayValidation; use DateTimeImmutable; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Attribute\Route; class HomeController extends AbstractController Loading @@ -16,6 +19,60 @@ class HomeController extends AbstractController $this->functions = $functions; } #[Route('/func1', name: 'home', methods: ['POST'])] public function func1(Request $request): Response { $array = $request->get('arr'); if (!ArrayValidation::validateFunc1($array)) { return new Response("Invalid array"); } $array = $this->functions->sortPrice($array); return $this->json($array); } #[Route('/func2', name: 'func2', methods: ['POST'])] public function func2(Request $request): Response { $id = $request->query->getInt('id'); $array = $request->get('arr'); if (!ArrayValidation::validateFunc2($array)) { return new Response("Invalid array"); } $result = $this->functions->search($array, $id); return $this->json($result); } #[Route('/func3', name: 'func3', methods: ['POST'])] public function home(Request $request): Response { $array = $request->get('arr'); $result = $this->functions->uniqElements($array); return $this->json($result); } #[Route('/func4', name: 'func4', methods: ['POST'])] public function func4(Request $request): Response { $array = $request->get('arr'); if (!ArrayValidation::validateFunc4($array)) { return new Response("Invalid array"); } $result = $this->functions->prepareMenu($array); return $this->json($result); } #[Route('/func5/{day}/{month}/{year}', name: 'func5')] public function func5(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]); } #[Route('/{year}', name: 'home', methods: ['GET'])] public function home(int $year): Response { Loading src/Validation/ArrayValidation.php 0 → 100644 +26 −0 Original line number Diff line number Diff line <?php namespace App\Validation; class ArrayValidation { public static function validateFunc1(array $array): bool { $prices = array_column($array, 'price'); $counts = array_column($array, 'count'); return ctype_digit(implode('',$prices)) && ctype_digit(implode('', $counts)); } public static function validateFunc2(array $array): bool { $ids = array_column($array, 'id'); $ages = array_column($array, 'age'); return ctype_digit(implode('', $ids)) && ctype_digit(implode('', $ages)); } public static function validateFunc4(array $array): bool { $depths = array_column($array, 'depth'); return ctype_digit(implode('', $depths)); } } No newline at end of file Loading
src/Action/Functions.php +8 −10 Original line number Diff line number Diff line Loading @@ -158,7 +158,6 @@ class Functions return (int)$dateInterval->format("%a") + 1; } /** * Вернет все пятницы 13 в году * @param int $year год, в котором необходимо произвести расчет Loading @@ -177,4 +176,3 @@ class Functions } } } No newline at end of file
src/Controller/HomeController.php +57 −0 Original line number Diff line number Diff line Loading @@ -3,8 +3,11 @@ namespace App\Controller; use App\Action\Functions; use App\Validation\ArrayValidation; use DateTimeImmutable; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Attribute\Route; class HomeController extends AbstractController Loading @@ -16,6 +19,60 @@ class HomeController extends AbstractController $this->functions = $functions; } #[Route('/func1', name: 'home', methods: ['POST'])] public function func1(Request $request): Response { $array = $request->get('arr'); if (!ArrayValidation::validateFunc1($array)) { return new Response("Invalid array"); } $array = $this->functions->sortPrice($array); return $this->json($array); } #[Route('/func2', name: 'func2', methods: ['POST'])] public function func2(Request $request): Response { $id = $request->query->getInt('id'); $array = $request->get('arr'); if (!ArrayValidation::validateFunc2($array)) { return new Response("Invalid array"); } $result = $this->functions->search($array, $id); return $this->json($result); } #[Route('/func3', name: 'func3', methods: ['POST'])] public function home(Request $request): Response { $array = $request->get('arr'); $result = $this->functions->uniqElements($array); return $this->json($result); } #[Route('/func4', name: 'func4', methods: ['POST'])] public function func4(Request $request): Response { $array = $request->get('arr'); if (!ArrayValidation::validateFunc4($array)) { return new Response("Invalid array"); } $result = $this->functions->prepareMenu($array); return $this->json($result); } #[Route('/func5/{day}/{month}/{year}', name: 'func5')] public function func5(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]); } #[Route('/{year}', name: 'home', methods: ['GET'])] public function home(int $year): Response { Loading
src/Validation/ArrayValidation.php 0 → 100644 +26 −0 Original line number Diff line number Diff line <?php namespace App\Validation; class ArrayValidation { public static function validateFunc1(array $array): bool { $prices = array_column($array, 'price'); $counts = array_column($array, 'count'); return ctype_digit(implode('',$prices)) && ctype_digit(implode('', $counts)); } public static function validateFunc2(array $array): bool { $ids = array_column($array, 'id'); $ages = array_column($array, 'age'); return ctype_digit(implode('', $ids)) && ctype_digit(implode('', $ages)); } public static function validateFunc4(array $array): bool { $depths = array_column($array, 'depth'); return ctype_digit(implode('', $depths)); } } No newline at end of file