src/Controller/Customer/UpdateModuleAccessAction.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Customer;
  3. use App\DataProvider\Module\ModuleItemDataProvider;
  4. use App\Model\Customer\Customer;
  5. use App\Model\Exception\ModuleNotFoundException;
  6. use App\Model\Module\Module;
  7. use App\Model\ModuleConfiguration\ModuleConfiguration;
  8. use App\Service\Cache\CacheManager;
  9. use App\Service\Customer\CustomerModuleManager;
  10. use Doctrine\Common\Annotations\AnnotationException;
  11. use ImagickException;
  12. use ReflectionException;
  13. use Symfony\Component\HttpClient\Exception\InvalidArgumentException;
  14. use Symfony\Component\HttpFoundation\JsonResponse;
  15. use Symfony\Component\HttpFoundation\Request;
  16. use Symfony\Component\HttpFoundation\Response;
  17. use Symfony\Component\Serializer\Exception\ExceptionInterface;
  18. use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
  19. use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
  20. use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
  21. use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
  22. use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
  23. final class UpdateModuleAccessAction
  24. {
  25.     /**
  26.      * @param Customer               $data
  27.      * @param Request                $request
  28.      * @param CustomerModuleManager  $customerModuleManager
  29.      * @param ModuleItemDataProvider $moduleItemDataProvider
  30.      * @param CacheManager           $cacheManager
  31.      *
  32.      * @return Response
  33.      *
  34.      * @throws AnnotationException
  35.      * @throws ClientExceptionInterface
  36.      * @throws DecodingExceptionInterface
  37.      * @throws ExceptionInterface
  38.      * @throws ImagickException
  39.      * @throws ModuleNotFoundException
  40.      * @throws RedirectionExceptionInterface
  41.      * @throws ReflectionException
  42.      * @throws ServerExceptionInterface
  43.      * @throws TransportExceptionInterface
  44.      * @throws \Psr\Cache\InvalidArgumentException
  45.      */
  46.     public function __invoke(
  47.         Customer $data,
  48.         Request $request,
  49.         CustomerModuleManager $customerModuleManager,
  50.         ModuleItemDataProvider $moduleItemDataProvider,
  51.         CacheManager $cacheManager
  52.     ): Response {
  53.         $content json_decode($request->getContent(), true);
  54.         if (empty($content['moduleId'])) {
  55.             throw new InvalidArgumentException('Aucun module spécifié pour mise à jour des droits');
  56.         }
  57.         $response $customerModuleManager->enableOrDisableModuleForCustomer(
  58.             $moduleItemDataProvider->getItem(
  59.                 Module::class,
  60.                 $content['moduleId']
  61.             ),
  62.             $data
  63.         );
  64.         $cacheManager->invalidateTag([$cacheManager->getCustomerPrefix().'_'.ModuleConfiguration::class]);
  65.         $cacheManager->invalidateTag([$cacheManager->getCustomerPrefix().'_'.Module::class]);
  66.         return new JsonResponse($responseResponse::HTTP_OK);
  67.     }
  68. }