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

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