src/PortoContainers/PostOne/EventSubscriber/ShippingCourierSettingsSubscriber.php line 36

  1. <?php
  2. namespace App\PortoContainers\PostOne\EventSubscriber;
  3. use App\Entity\Shipping\ShippingCourier;
  4. use App\Event\ShippingCourierSettingsPersistedEvent;
  5. use App\PortoContainers\PostOne\Actions\HandleOauthTokensAction;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. class ShippingCourierSettingsSubscriber implements EventSubscriberInterface
  8. {
  9.     /**
  10.      * @param HandleOauthTokensAction $handleOauthTokensAction
  11.      */
  12.     public function __construct(
  13.         private readonly HandleOauthTokensAction $handleOauthTokensAction,
  14.     )
  15.     {
  16.     }
  17.     /**
  18.      * @return array
  19.      */
  20.     public static function getSubscribedEvents(): array
  21.     {
  22.         return [
  23.             ShippingCourierSettingsPersistedEvent::class => ['shippingCourierSettingsPersistAction'100],
  24.         ];
  25.     }
  26.     /**
  27.      * @param ShippingCourierSettingsPersistedEvent $event
  28.      * @return void
  29.      * @throws \Exception
  30.      */
  31.     public function shippingCourierSettingsPersistAction(ShippingCourierSettingsPersistedEvent $event): void
  32.     {
  33.         $entity $event->getEntity();
  34.         if ($entity->getCourier()->getType() !== ShippingCourier::COURIER_TYPE_POST_ONE) {
  35.             return;
  36.         }
  37.         if ($entity->getToken()) {
  38.             return;
  39.         }
  40.         $this->handleOauthTokensAction->run(
  41.             shippingCourierSettings$entity
  42.         );
  43.     }
  44. }