src/V4/Controller/Tab/TabDataPersisterAction.php line 19

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