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

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 Shopware\Core\Framework\Feature;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter;
  9. class PaymentHandlerIdentifierSubscriber implements EventSubscriberInterface
  10. {
  11.     public static function getSubscribedEvents(): array
  12.     {
  13.         return [
  14.             PaymentEvents::PAYMENT_METHOD_LOADED_EVENT => 'formatHandlerIdentifier',
  15.         ];
  16.     }
  17.     public function formatHandlerIdentifier(EntityLoadedEvent $event): void
  18.     {
  19.         /** @var PaymentMethodEntity $entity */
  20.         foreach ($event->getEntities() as $entity) {
  21.             $explodedHandlerIdentifier explode('\\'$entity->getHandlerIdentifier());
  22.             if (Feature::isActive('FEATURE_NEXT_9351')) {
  23.                 $last $explodedHandlerIdentifier[count($explodedHandlerIdentifier) - 1];
  24.                 $entity->setShortName((new CamelCaseToSnakeCaseNameConverter())->normalize((string) $last));
  25.             }
  26.             if (count($explodedHandlerIdentifier) < 2) {
  27.                 $entity->setFormattedHandlerIdentifier($entity->getHandlerIdentifier());
  28.                 continue;
  29.             }
  30.             $formattedHandlerIdentifier 'handler_'
  31.                 mb_strtolower(array_shift($explodedHandlerIdentifier))
  32.                 . '_'
  33.                 mb_strtolower(array_pop($explodedHandlerIdentifier));
  34.             $entity->setFormattedHandlerIdentifier($formattedHandlerIdentifier);
  35.         }
  36.     }
  37. }