From 88ca27c17c99c0a8ef5f64ab97113fbbd3fe0541 Mon Sep 17 00:00:00 2001 From: Daniel Subiabre Date: Mon, 9 Dec 2024 13:03:38 +0100 Subject: [PATCH] Update gateway mapping --- src/Mapping/Gateway/GatewayMapper.php | 18 ------------------ src/State/Gateway/GatewayStateProvider.php | 20 ++++++++++++++------ 2 files changed, 14 insertions(+), 24 deletions(-) delete mode 100644 src/Mapping/Gateway/GatewayMapper.php diff --git a/src/Mapping/Gateway/GatewayMapper.php b/src/Mapping/Gateway/GatewayMapper.php deleted file mode 100644 index 16e06a7..0000000 --- a/src/Mapping/Gateway/GatewayMapper.php +++ /dev/null @@ -1,18 +0,0 @@ -name = $gateway::getName(); - $resource->supports = $gateway::getSupportedChargeTypes(); - - return $resource; - } -} diff --git a/src/State/Gateway/GatewayStateProvider.php b/src/State/Gateway/GatewayStateProvider.php index 4c3e477..3397d2a 100644 --- a/src/State/Gateway/GatewayStateProvider.php +++ b/src/State/Gateway/GatewayStateProvider.php @@ -5,16 +5,15 @@ use ApiPlatform\Metadata as API; use ApiPlatform\Metadata\Operation; use ApiPlatform\State\ProviderInterface; -use App\ApiResource\Gateway\Gateway; +use App\ApiResource\Gateway\GatewayApiResource; +use App\Gateway\GatewayInterface; use App\Gateway\GatewayLocator; -use App\Mapping\Gateway\GatewayMapper; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; class GatewayStateProvider implements ProviderInterface { public function __construct( private GatewayLocator $gateways, - private GatewayMapper $gatewayMapper, ) {} public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null @@ -31,20 +30,29 @@ private function getGateways(): array { $gateways = []; foreach ($this->gateways->getAll() as $gateway) { - $gateways[] = $this->gatewayMapper->toResource($gateway); + $gateways[] = $this->toResource($gateway); } return $gateways; } - private function getGateway(string $name): Gateway + private function getGateway(string $name): GatewayApiResource { try { $gateway = $this->gateways->get($name); - return $this->gatewayMapper->toResource($gateway); + return $this->toResource($gateway); } catch (\Exception $e) { throw new NotFoundHttpException('Not Found'); } } + + private function toResource(GatewayInterface $gateway): GatewayApiResource + { + $resource = new GatewayApiResource(); + $resource->name = $gateway::getName(); + $resource->supports = $gateway::getSupportedChargeTypes(); + + return $resource; + } }