vendor/shopware/core/Checkout/Payment/DataAbstractionLayer/PaymentHandlerIdentifierSubscriber.php line 19

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Checkout\Payment\DataAbstractionLayer;
  3. use Shopware\Core\Checkout\Payment\PaymentEvents;
  4. use Shopware\Core\Checkout\Payment\PaymentMethodEntity;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityLoadedEvent;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. class PaymentHandlerIdentifierSubscriber implements EventSubscriberInterface
  8. {
  9.     public static function getSubscribedEvents(): array
  10.     {
  11.         return [
  12.             PaymentEvents::PAYMENT_METHOD_LOADED_EVENT => 'formatHandlerIdentifier',
  13.         ];
  14.     }
  15.     public function formatHandlerIdentifier(EntityLoadedEvent $event): void
  16.     {
  17.         /** @var PaymentMethodEntity $entity */
  18.         foreach ($event->getEntities() as $entity) {
  19.             $explodedHandlerIdentifier explode('\\'$entity->getHandlerIdentifier());
  20.             if (count($explodedHandlerIdentifier) < 2) {
  21.                 $entity->setFormattedHandlerIdentifier($entity->getHandlerIdentifier());
  22.                 continue;
  23.             }
  24.             $formattedHandlerIdentifier 'handler_'
  25.                 mb_strtolower(array_shift($explodedHandlerIdentifier))
  26.                 . '_'
  27.                 mb_strtolower(array_pop($explodedHandlerIdentifier));
  28.             $entity->setFormattedHandlerIdentifier($formattedHandlerIdentifier);
  29.         }
  30.     }
  31. }