vendor/damienharper/auditor/src/EventSubscriber/AuditEventSubscriber.php line 33

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace DH\Auditor\EventSubscriber;
  4. use DH\Auditor\Auditor;
  5. use DH\Auditor\Event\LifecycleEvent;
  6. use Exception;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. /**
  9. * @see \DH\Auditor\Tests\EventSubscriber\AuditEventSubscriberTest
  10. */
  11. class AuditEventSubscriber implements EventSubscriberInterface
  12. {
  13. private Auditor $auditor;
  14. public function __construct(Auditor $auditor)
  15. {
  16. $this->auditor = $auditor;
  17. }
  18. public static function getSubscribedEvents(): array
  19. {
  20. return [
  21. LifecycleEvent::class => [
  22. ['onAuditEvent', -1_000_000], // should be fired last
  23. ],
  24. ];
  25. }
  26. public function onAuditEvent(LifecycleEvent $event): LifecycleEvent
  27. {
  28. foreach ($this->auditor->getProviders() as $provider) {
  29. if ($provider->supportsStorage()) {
  30. try {
  31. $provider->persist($event);
  32. } catch (Exception $e) {
  33. // do nothing to ensure other providers are called
  34. }
  35. }
  36. }
  37. return $event;
  38. }
  39. }