<?php
namespace App\Domain\Gateway\UseCases\GenerateGateway;
use App\Domain\Gateway\Entities\Exception\GatewayGeneratorNotSupportedException;
use App\Domain\Gateway\Entities\GatewayManagerInterface;
final class GenerateGateway
{
private GatewayManagerInterface $gatewayManager;
public function __construct(GatewayManagerInterface $gatewayManager)
{
$this->gatewayManager = $gatewayManager;
}
/**
* @param GenerateGatewayRequest $request
* @param GenerateGatewayPresenter $presenter
*
* @throws GatewayGeneratorNotSupportedException
*/
public function execute(GenerateGatewayRequest $request, GenerateGatewayPresenter $presenter): void
{
$generator = $this->gatewayManager->getGenerator($request->getSlug());
if (null === $generator) {
throw new GatewayGeneratorNotSupportedException($request->getSlug());
}
$presenter->present(
new GenerateGatewayResponse(
$request->getSlug(),
$generator->generate(),
$generator::FORMAT,
$generator::ITEM_TAG
)
);
}
}