vendor/store.shopware.com/netinexteasycoupon/src/Routing/BalanceQueryLoader.php line 24

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace NetInventors\NetiNextEasyCoupon\Routing;
  4. use NetInventors\NetiNextEasyCoupon\Storefront\Controller\BalanceQueryController;
  5. use NetInventors\NetiNextEasyCoupon\Struct\PluginConfigStruct;
  6. use Symfony\Component\Config\Loader\Loader;
  7. use Symfony\Component\Routing\Route;
  8. use Symfony\Component\Routing\RouteCollection;
  9. /**
  10.  * @psalm-suppress PropertyNotSetInConstructor
  11.  *
  12.  * env is set in the parent class
  13.  */
  14. class BalanceQueryLoader extends Loader
  15. {
  16.     private bool               $isLoaded false;
  17.     private PluginConfigStruct $pluginConfig;
  18.     public function __construct(PluginConfigStruct $pluginConfigstring $env null)
  19.     {
  20.         if (\is_callable('parent::__construct')) {
  21.             parent::__construct($env);
  22.         }
  23.         $this->pluginConfig $pluginConfig;
  24.     }
  25.     public function load($resourcestring $type null): RouteCollection
  26.     {
  27.         if (true === $this->isLoaded) {
  28.             throw new \RuntimeException('Do not add the "BalanceQueryLoader" twice.');
  29.         }
  30.         $routes  = new RouteCollection();
  31.         $path    $this->pluginConfig->getFindVoucherUrl() . '/{voucherId}';
  32.         $name    'frontend.easy_coupon.query_voucher_balance.individual';
  33.         $methods = [ 'GET' ];
  34.         $defaults = [
  35.             '_controller'    => BalanceQueryController::class . '::queryVoucherBalance',
  36.             'XmlHttpRequest' => false,
  37.             'voucherId'      => null,
  38.         ];
  39.         $route = new Route($path$defaults);
  40.         $route->setMethods($methods);
  41.         $routes->add($name$route);
  42.         $this->isLoaded true;
  43.         return $routes;
  44.     }
  45.     public function supports($resourcestring $type null): bool
  46.     {
  47.         return 'balance_query' === $type;
  48.     }
  49. }