src/TeclaConnector/EventSubscriber/SynchronizeUpdatedUserSubscriber.php line 48

  1. <?php
  2. declare(strict_types=1);
  3. /**
  4.  * Copyright (c) 2020 TECLA Consulting Group oü.
  5.  * All rights reserved.
  6.  *
  7.  * This unpublished material is proprietary to TECLA Consulting Group oü.
  8.  * All rights reserved. The methods and
  9.  * techniques described herein are considered trade secrets
  10.  * and/or confidential. Reproduction or distribution, in whole
  11.  * or in part, is forbidden except by express written permission
  12.  * of TECLA Consulting Group oü.
  13.  *
  14.  * @author    Matúš Sýkorjak <matus@tecla.no>
  15.  * @copyright 2020 TECLA Consulting Group oü
  16.  */
  17. namespace App\TeclaConnector\EventSubscriber;
  18. use App\Core\Event\UserUpdatedEvent;
  19. use App\TeclaConnector\Exception\Synchronizer\LegacySynchronizerFailedExceptionInterface;
  20. use App\TeclaConnector\Service\FailedLegacySynchronizerServiceInterface;
  21. use App\TeclaConnector\Synchronizer\User\LegacyUpdateSynchronizerInterface;
  22. use JetBrains\PhpStorm\ArrayShape;
  23. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  24. final class SynchronizeUpdatedUserSubscriber implements EventSubscriberInterface
  25. {
  26.     private LegacyUpdateSynchronizerInterface $synchronizer;
  27.     private FailedLegacySynchronizerServiceInterface $failedSynchronizerService;
  28.     public function __construct(LegacyUpdateSynchronizerInterface $synchronizerFailedLegacySynchronizerServiceInterface $failedSynchronizerService)
  29.     {
  30.         $this->synchronizer $synchronizer;
  31.         $this->failedSynchronizerService $failedSynchronizerService;
  32.     }
  33.     #[ArrayShape([UserUpdatedEvent::class => 'string'])]
  34.     public static function getSubscribedEvents(): array
  35.     {
  36.         return [
  37.             UserUpdatedEvent::class => 'onUserUpdatedEvent',
  38.         ];
  39.     }
  40.     public function onUserUpdatedEvent(UserUpdatedEvent $event): void
  41.     {
  42.         $user $event->getUser();
  43.         try {
  44.             $this->synchronizer->synchronize($user);
  45.         } catch (LegacySynchronizerFailedExceptionInterface $e) {
  46.             $this->failedSynchronizerService->create($e->getSynchronizerRequest());
  47.         }
  48.     }
  49. }