vendor/abap/payment-bundle/src/Handler/NotifyRequest/CompositeNotifyRequestHandler.php line 25

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Abap\PaymentBundle\Handler\NotifyRequest;
  4. final class CompositeNotifyRequestHandler implements NotifyRequestHandlerInterface
  5. {
  6.     private array $gatewaysConfig;
  7.     private array $handlers = [];
  8.     public function __construct(array $gatewaysConfig)
  9.     {
  10.         $this->gatewaysConfig $gatewaysConfig;
  11.     }
  12.     public function add(NotifyRequestHandlerInterface $handlerstring $serviceId): void
  13.     {
  14.         str_replace('\\''_'$serviceId);
  15.         $this->handlers[$serviceId] = $handler;
  16.     }
  17.     public function handle(string $gatewayNamestring $paymentClass null): void
  18.     {
  19.         if (!array_key_exists($gatewayName$this->gatewaysConfig)) {
  20.             throw new \InvalidArgumentException(sprintf('Gateway "%s" is not supported for notify request.'$gatewayName));
  21.         }
  22.         $gatewayConfig $this->gatewaysConfig[$gatewayName];
  23.         $paymentClass $gatewayConfig['storage'];
  24.         $handler $this->getHandler($gatewayConfig['notify_request_handler']);
  25.         $handler->handle($gatewayName$paymentClass);
  26.     }
  27.     private function getHandler(string $serviceId): NotifyRequestHandlerInterface
  28.     {
  29.         str_replace('\\''_'$serviceId);
  30.         if (str_starts_with($serviceId'@')) {
  31.             $serviceId substr($serviceIdstrlen('@'));
  32.         }
  33.         if (!array_key_exists($serviceId$this->handlers)) {
  34.             throw new \InvalidArgumentException("Handler {$serviceId} not found");
  35.         }
  36.         return $this->handlers[$serviceId];
  37.     }
  38. }