vendor/shopware/platform/src/Core/Checkout/Payment/DataAbstractionLayer/PaymentHandlerIdentifierSubscriber.php line 20

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