<?php
declare(strict_types=1);
namespace NetInventors\NetiNextEasyCoupon\Routing;
use NetInventors\NetiNextEasyCoupon\Storefront\Controller\BalanceQueryController;
use NetInventors\NetiNextEasyCoupon\Struct\PluginConfigStruct;
use Symfony\Component\Config\Loader\Loader;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
/**
* @psalm-suppress PropertyNotSetInConstructor
*
* env is set in the parent class
*/
class BalanceQueryLoader extends Loader
{
private bool $isLoaded = false;
private PluginConfigStruct $pluginConfig;
public function __construct(PluginConfigStruct $pluginConfig, string $env = null)
{
if (\is_callable('parent::__construct')) {
parent::__construct($env);
}
$this->pluginConfig = $pluginConfig;
}
public function load($resource, string $type = null): RouteCollection
{
if (true === $this->isLoaded) {
throw new \RuntimeException('Do not add the "BalanceQueryLoader" twice.');
}
$routes = new RouteCollection();
$path = $this->pluginConfig->getFindVoucherUrl() . '/{voucherId}';
$name = 'frontend.easy_coupon.query_voucher_balance.individual';
$methods = [ 'GET' ];
$defaults = [
'_controller' => BalanceQueryController::class . '::queryVoucherBalance',
'XmlHttpRequest' => false,
'voucherId' => null,
];
$route = new Route($path, $defaults);
$route->setMethods($methods);
$routes->add($name, $route);
$this->isLoaded = true;
return $routes;
}
public function supports($resource, string $type = null): bool
{
return 'balance_query' === $type;
}
}