custom/plugins/CrswCleverReachOfficial/src/Controller/Storefront/AsyncProcessController.php line 46

Open in your IDE?
  1. <?php
  2. namespace Crsw\CleverReachOfficial\Controller\Storefront;
  3. use Crsw\CleverReachOfficial\Components\Utility\Bootstrap;
  4. use Crsw\CleverReachOfficial\Components\Utility\Initializer;
  5. use Crsw\CleverReachOfficial\Core\Infrastructure\ServiceRegister;
  6. use Crsw\CleverReachOfficial\Core\Infrastructure\TaskExecution\Interfaces\AsyncProcessService;
  7. use Shopware\Core\Framework\Routing\Annotation\RouteScope;
  8. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  9. use Symfony\Component\HttpFoundation\JsonResponse;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. /**
  12.  * Class AsyncProcessController
  13.  *
  14.  * @package Crsw\CleverReachOfficial\Controller\Storefront
  15.  */
  16. class AsyncProcessController extends AbstractController
  17. {
  18.     /**
  19.      * AsyncProcessController constructor.
  20.      *
  21.      * @param Initializer $initializer
  22.      */
  23.     public function __construct(
  24.         Initializer $initializer
  25.     ) {
  26.         Bootstrap::init();
  27.         $initializer->registerServices();
  28.     }
  29.     /**
  30.      * Async process starter endpoint
  31.      *
  32.      * @RouteScope(scopes={"api"})
  33.      * @Route(path="/api/v{version}/cleverreach/async/{guid}", name="api.cleverreach.async",
  34.      *      defaults={"csrf_protected"=false, "auth_required"=false}, methods={"GET", "POST"})
  35.      * @Route(path="/api/cleverreach/async/{guid}", name="api.cleverreach.async.new",
  36.      *      defaults={"csrf_protected"=false, "auth_required"=false}, methods={"GET", "POST"})
  37.      *
  38.      * @param string $guid
  39.      *
  40.      * @return JsonResponse
  41.      */
  42.     public function run(string $guid): JsonResponse
  43.     {
  44.         $this->getAsyncProcessService()->runProcess($guid);
  45.         return new JsonResponse(['success' => true]);
  46.     }
  47.     /**
  48.      * @return AsyncProcessService
  49.      */
  50.     private function getAsyncProcessService(): AsyncProcessService
  51.     {
  52.         /** @noinspection PhpIncompatibleReturnTypeInspection */
  53.         return ServiceRegister::getService(AsyncProcessService::class);
  54.     }
  55. }