diff --git a/.gitignore b/.gitignore index 716e12c3b981e6071964b614a1cfdecfd6296307..930e1e21e27cc2916f9dd36aa9e577d0fb0b2ee0 100644 --- a/.gitignore +++ b/.gitignore @@ -23,5 +23,4 @@ /public/assets/ /assets/vendor/ ###< symfony/asset-mapper ### - -/.idea +/.idea \ No newline at end of file diff --git a/src/Action/Functions.php b/src/Action/Functions.php index 852a4219d9670679348778a601406dd91f4d02d7..52d054923fba0db9ce61f6c97b473292fb744217 100644 --- a/src/Action/Functions.php +++ b/src/Action/Functions.php @@ -4,9 +4,6 @@ declare(strict_types=1); namespace App\Action; -use DateTimeImmutable; -use Exception; - class Functions { /** @@ -68,13 +65,13 @@ class Functions } /** - * Выходной массив: - * Array ( - * [0] => Array([0] => laravel, [1] => php) - * [1] => Array([0] => codeigniter, [1] => php) - * [3] => Array([0] => c++, [1] => java)) - * ) - */ + * Выходной массив: + * Array ( + * [0] => Array([0] => laravel, [1] => php) + * [1] => Array([0] => codeigniter, [1] => php) + * [3] => Array([0] => c++, [1] => java)) + * ) + */ /** * Сгруппировать подразедлы в верхние разделы меню @@ -154,5 +151,4 @@ class Functions $dateInterval = date_diff(new DateTimeImmutable($endYear), $date); return (int)$dateInterval->format("%a") + 1; } -} - +} \ No newline at end of file diff --git a/src/Controller/HomeController.php b/src/Controller/HomeController.php index 3e6117043075da3f62cf36ab7300a5f32bee8b17..b8e0ce55a65063a90b421f86c0326a24fa61525a 100644 --- a/src/Controller/HomeController.php +++ b/src/Controller/HomeController.php @@ -3,10 +3,10 @@ namespace App\Controller; use App\Action\Functions; -use DateTimeImmutable; +use App\Validation\ArrayValidation; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; -use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Attribute\Route; class HomeController extends AbstractController @@ -18,6 +18,48 @@ 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: 'home', methods: ['POST'])] + public function home(Request $request): Response + { + $array = $request->get('arr'); + $result = $this->functions->uniqElements($array); + return $this->json($result); + } + + #[Route('/func4', name: 'home', 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('/{day}/{month}/{year}', name: 'home')] public function home(int $day, int $month, int $year): Response { diff --git a/src/Validation/ArrayValidation.php b/src/Validation/ArrayValidation.php new file mode 100644 index 0000000000000000000000000000000000000000..5807a447814593f64ecf069980c81099b8be861d --- /dev/null +++ b/src/Validation/ArrayValidation.php @@ -0,0 +1,26 @@ +