| Total Complexity | 6 |
| Total Lines | 31 |
| Duplicated Lines | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 15 | final class AuditEventSubscriber implements EventSubscriberInterface |
||
| 16 | { |
||
| 17 | private Auditor $auditor; |
||
| 18 | |||
| 19 | public function __construct(Auditor $auditor) |
||
| 20 | { |
||
| 21 | $this->auditor = $auditor; |
||
| 22 | } |
||
| 23 | |||
| 24 | public static function getSubscribedEvents(): array |
||
| 25 | { |
||
| 26 | return [ |
||
| 27 | LifecycleEvent::class => [ |
||
| 28 | ['onAuditEvent', -1_000_000], // should be fired last |
||
|
|
|||
| 29 | ], |
||
| 30 | ]; |
||
| 31 | } |
||
| 32 | |||
| 33 | public function onAuditEvent(LifecycleEvent $event): LifecycleEvent |
||
| 34 | { |
||
| 35 | foreach ($this->auditor->getProviders() as $provider) { |
||
| 36 | if ($provider->supportsStorage()) { |
||
| 37 | try { |
||
| 38 | $provider->persist($event); |
||
| 39 | } catch (Exception) { |
||
| 40 | // do nothing to ensure other providers are called |
||
| 41 | } |
||
| 42 | } |
||
| 43 | } |
||
| 44 | |||
| 45 | return $event; |
||
| 46 | } |
||
| 48 |