src/V4/Controller/Prospect/GetProspectFormAction.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\V4\Controller\Prospect;
  3. use App\Model\Form\FormSchema;
  4. use App\V4\Model\Prospect\Prospect;
  5. use App\V4\Service\Prospect\ProspectFormHandler;
  6. use App\V4\Voters\ProspectVoter;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\JsonResponse;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\Serializer\Exception\ExceptionInterface;
  11. class GetProspectFormAction extends AbstractController
  12. {
  13.     /**
  14.      * @var ProspectFormHandler
  15.      */
  16.     private $prospectFormHandler;
  17.     /**
  18.      * @param ProspectFormHandler $prospectFormHandler
  19.      */
  20.     public function __construct(ProspectFormHandler $prospectFormHandler)
  21.     {
  22.         $this->prospectFormHandler $prospectFormHandler;
  23.     }
  24.     /**
  25.      * @param Request  $request
  26.      * @param Prospect $data
  27.      * @param string   $id
  28.      *
  29.      * @return FormSchema|JsonResponse
  30.      *
  31.      * @throws ExceptionInterface
  32.      */
  33.     public function __invoke(Request $requestProspect $datastring $id)
  34.     {
  35.         $this->denyAccessUnlessGranted(ProspectVoter::PROSPECT_ADD_EDIT);
  36.         switch ($id) {
  37.             // We are probably in the case of a new prospect, the "id" will be hardcoded
  38.             case Prospect::GROUP_TYPE_BUSINESS:
  39.                 $prospectType Prospect::GROUP_TYPE_BUSINESS;
  40.                 break;
  41.             case Prospect::GROUP_TYPE_INDIVIDUAL:
  42.                 $prospectType Prospect::GROUP_TYPE_INDIVIDUAL;
  43.                 break;
  44.             // We are probably in the case of an existing prospect, we can rely on the data
  45.             default:
  46.                 $prospectType $data->getType();
  47.         }
  48.         return $this->prospectFormHandler->getProspectForm(
  49.             $data,
  50.             $prospectType,
  51.             (bool) $request->query->get('isLegacy'false)
  52.         );
  53.     }
  54. }