vendor/damienharper/doctrine-audit-bundle/src/DoctrineAuditBundle/Event/AuditSubscriber.php line 34

Open in your IDE?
  1. <?php
  2. namespace DH\DoctrineAuditBundle\Event;
  3. use DH\DoctrineAuditBundle\Manager\AuditManager;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. class AuditSubscriber implements EventSubscriberInterface
  6. {
  7.     /**
  8.      * @var AuditManager
  9.      */
  10.     private $manager;
  11.     public function __construct(AuditManager $manager)
  12.     {
  13.         $this->manager $manager;
  14.     }
  15.     public static function getSubscribedEvents(): array
  16.     {
  17.         return [
  18.             LifecycleEvent::class => 'onAuditEvent',
  19.         ];
  20.     }
  21.     /**
  22.      * @param LifecycleEvent $event
  23.      *
  24.      * @throws \Doctrine\DBAL\DBALException
  25.      *
  26.      * @return LifecycleEvent
  27.      */
  28.     public function onAuditEvent(LifecycleEvent $event): LifecycleEvent
  29.     {
  30.         $payload $event->getPayload();
  31.         $auditTable $payload['table'];
  32.         unset($payload['table']);
  33.         $fields = [
  34.             'type' => ':type',
  35.             'object_id' => ':object_id',
  36.             'discriminator' => ':discriminator',
  37.             'transaction_hash' => ':transaction_hash',
  38.             'diffs' => ':diffs',
  39.             'blame_id' => ':blame_id',
  40.             'blame_user' => ':blame_user',
  41.             'blame_user_fqdn' => ':blame_user_fqdn',
  42.             'blame_user_firewall' => ':blame_user_firewall',
  43.             'ip' => ':ip',
  44.             'created_at' => ':created_at',
  45.         ];
  46.         $query sprintf(
  47.             'INSERT INTO %s (%s) VALUES (%s)',
  48.             $auditTable,
  49.             implode(', 'array_keys($fields)),
  50.             implode(', 'array_values($fields))
  51.         );
  52.         $storage $this->manager->selectStorageSpace($this->manager->getConfiguration()->getEntityManager());
  53.         $statement $storage->getConnection()->prepare($query);
  54.         foreach ($payload as $key => $value) {
  55.             $statement->bindValue($key$value);
  56.         }
  57.         $statement->execute();
  58.         return $event;
  59.     }
  60. }