src/V4/Controller/Section/SectionDataPersisterAction.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\V4\Controller\Section;
  3. use App\V4\Service\Section\SectionFormHandler;
  4. use Doctrine\Common\Annotations\AnnotationException;
  5. use Psr\Cache\InvalidArgumentException;
  6. use ReflectionException;
  7. use Symfony\Component\HttpFoundation\JsonResponse;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\Serializer\Exception\ExceptionInterface;
  10. use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
  11. use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
  12. use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
  13. use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
  14. use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
  15. class SectionDataPersisterAction
  16. {
  17.     /**
  18.      * @var SectionFormHandler
  19.      */
  20.     private $sectionFormHandler;
  21.     /**
  22.      * @param SectionFormHandler $sectionFormHandler
  23.      */
  24.     public function __construct(SectionFormHandler $sectionFormHandler)
  25.     {
  26.         $this->sectionFormHandler $sectionFormHandler;
  27.     }
  28.     /**
  29.      * @param Request     $request
  30.      * @param null        $data
  31.      * @param string|null $id
  32.      *
  33.      * @return object|JsonResponse|null
  34.      *
  35.      * @throws AnnotationException
  36.      * @throws ClientExceptionInterface
  37.      * @throws DecodingExceptionInterface
  38.      * @throws ExceptionInterface
  39.      * @throws InvalidArgumentException
  40.      * @throws RedirectionExceptionInterface
  41.      * @throws ServerExceptionInterface
  42.      * @throws TransportExceptionInterface
  43.      * @throws ReflectionException
  44.      */
  45.     public function __invoke(Request $request$data null, ?string $id null)
  46.     {
  47.         //@todo refacto probablement sécurité a rajouter
  48.         if (Request::METHOD_DELETE === $request->getMethod() && null !== $data) {
  49.             $this->sectionFormHandler->remove($data);
  50.             return new JsonResponse([]);
  51.         }
  52.         return new JsonResponse($this->sectionFormHandler->handleForm(json_decode($request->getContent(), true), $id));
  53.     }
  54. }