vendor/doctrine/dbal/src/Logging/Connection.php line 46

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Doctrine\DBAL\Logging;
  4. use Doctrine\DBAL\Driver\Connection as ConnectionInterface;
  5. use Doctrine\DBAL\Driver\Middleware\AbstractConnectionMiddleware;
  6. use Doctrine\DBAL\Driver\Result;
  7. use Doctrine\DBAL\Driver\Statement as DriverStatement;
  8. use Psr\Log\LoggerInterface;
  9. final class Connection extends AbstractConnectionMiddleware
  10. {
  11.     /** @var LoggerInterface */
  12.     private $logger;
  13.     /**
  14.      * @internal This connection can be only instantiated by its driver.
  15.      */
  16.     public function __construct(ConnectionInterface $connectionLoggerInterface $logger)
  17.     {
  18.         parent::__construct($connection);
  19.         $this->logger $logger;
  20.     }
  21.     public function __destruct()
  22.     {
  23.         $this->logger->info('Disconnecting');
  24.     }
  25.     public function prepare(string $sql): DriverStatement
  26.     {
  27.         return new Statement(
  28.             parent::prepare($sql),
  29.             $this->logger,
  30.             $sql
  31.         );
  32.     }
  33.     public function query(string $sql): Result
  34.     {
  35.         $this->logger->debug('Executing query: {sql}', ['sql' => $sql]);
  36.         return parent::query($sql);
  37.     }
  38.     public function exec(string $sql): int
  39.     {
  40.         $this->logger->debug('Executing statement: {sql}', ['sql' => $sql]);
  41.         return parent::exec($sql);
  42.     }
  43.     /**
  44.      * {@inheritDoc}
  45.      */
  46.     public function beginTransaction()
  47.     {
  48.         $this->logger->debug('Beginning transaction');
  49.         return parent::beginTransaction();
  50.     }
  51.     /**
  52.      * {@inheritDoc}
  53.      */
  54.     public function commit()
  55.     {
  56.         $this->logger->debug('Committing transaction');
  57.         return parent::commit();
  58.     }
  59.     /**
  60.      * {@inheritDoc}
  61.      */
  62.     public function rollBack()
  63.     {
  64.         $this->logger->debug('Rolling back transaction');
  65.         return parent::rollBack();
  66.     }
  67. }