<?php
namespace App\V4\Controller\Section;
use ApiPlatform\Core\Exception\ResourceClassNotSupportedException;
use App\Model\Form\FormSchema;
use App\V4\Service\Section\SectionFormHandler;
use App\V4\Voters\SectionVoter;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
class GetSectionFormAction extends AbstractController
{
/**
* @var SectionFormHandler
*/
private $sectionFormHandler;
/**
* @param SectionFormHandler $sectionFormHandler
*/
public function __construct(SectionFormHandler $sectionFormHandler)
{
$this->sectionFormHandler = $sectionFormHandler;
}
/**
* @param Request $request
* @param string|null $id
*
* @return FormSchema|array
*
* @throws ResourceClassNotSupportedException
*/
public function __invoke(Request $request, string $id = null)
{
$this->denyAccessUnlessGranted(SectionVoter::SECTION_ADD_EDIT);
return $this->sectionFormHandler->getSectionForm($id, $request->get('customerId'));
}
}