<?php
namespace App\Controller\Product;
use App\Model\Form\FormSchema;
use App\Service\Product\ProductFormHandler;
use App\Voters\ProductVoter;
use ReflectionException;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Serializer\Exception\ExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
class GetProductFormAction extends AbstractController
{
/**
* @var ProductFormHandler
*/
private $productFormHandler;
/**
* @param ProductFormHandler $productFormHandler
*/
public function __construct(ProductFormHandler $productFormHandler)
{
$this->productFormHandler = $productFormHandler;
}
/**
* @param Request $request
* @param string|null $id
*
* @return FormSchema|JsonResponse
*
* @throws ClientExceptionInterface
* @throws DecodingExceptionInterface
* @throws RedirectionExceptionInterface
* @throws ReflectionException
* @throws ServerExceptionInterface
* @throws TransportExceptionInterface
* @throws ExceptionInterface
*/
public function __invoke(Request $request, string $id = null)
{
$this->denyAccessUnlessGranted(ProductVoter::PRODUCT_ADD_EDIT);
return $this->productFormHandler->getProductForm($id, (bool) $request->query->get('isLegacy', false));
}
}