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

namespace App\Controller;

Адлан Шамавов's avatar
Адлан Шамавов committed
use App\Action\Functions;
use App\Validation\ArrayValidation;
Адлан Шамавов'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
    public function __construct(Functions $functions)
Адлан Шамавов's avatar
Адлан Шамавов committed
    {
Адлан Шамавов's avatar
Адлан Шамавов committed
        $this->functions = $functions;
    }
Адлан Шамавов's avatar
Адлан Шамавов committed
    #[Route('/', name: 'home', methods: ['POST'])]
    public function home(Request $request): Response
    {
        $array = $request->get('arr');
        $errors = ArrayValidation::validate($array);
        if (count($errors) > 0) {
            return new Response((string)$errors);
        }
        $result = $this->functions->prepareMenu($array);
        return $this->json($result);
Адлан Шамавов's avatar
Адлан Шамавов committed
    }
}