vendor/symfony/doctrine-bridge/Middleware/Debug/Statement.php line 72

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Bridge\Doctrine\Middleware\Debug;
  11. use Doctrine\DBAL\Driver\Middleware\AbstractStatementMiddleware;
  12. use Doctrine\DBAL\Driver\Result as ResultInterface;
  13. use Doctrine\DBAL\Driver\Statement as StatementInterface;
  14. use Doctrine\DBAL\ParameterType;
  15. use Symfony\Component\Stopwatch\Stopwatch;
  16. /**
  17.  * @author Laurent VOULLEMIER <laurent.voullemier@gmail.com>
  18.  *
  19.  * @internal
  20.  */
  21. final class Statement extends AbstractStatementMiddleware
  22. {
  23.     private $debugDataHolder;
  24.     private $connectionName;
  25.     private $query;
  26.     private $stopwatch;
  27.     public function __construct(StatementInterface $statementDebugDataHolder $debugDataHolderstring $connectionNamestring $sqlStopwatch $stopwatch null)
  28.     {
  29.         parent::__construct($statement);
  30.         $this->debugDataHolder $debugDataHolder;
  31.         $this->connectionName $connectionName;
  32.         $this->query = new Query($sql);
  33.         $this->stopwatch $stopwatch;
  34.     }
  35.     public function bindParam($param, &$variable$type ParameterType::STRING$length null): bool
  36.     {
  37.         $this->query->setParam($param$variable$type);
  38.         return parent::bindParam($param$variable$type, ...\array_slice(\func_get_args(), 3));
  39.     }
  40.     public function bindValue($param$value$type ParameterType::STRING): bool
  41.     {
  42.         $this->query->setValue($param$value$type);
  43.         return parent::bindValue($param$value$type);
  44.     }
  45.     public function execute($params null): ResultInterface
  46.     {
  47.         if (null !== $params) {
  48.             $this->query->setValues($params);
  49.         }
  50.         // clone to prevent variables by reference to change
  51.         $this->debugDataHolder->addQuery($this->connectionName$query = clone $this->query);
  52.         if ($this->stopwatch) {
  53.             $this->stopwatch->start('doctrine''doctrine');
  54.         }
  55.         $query->start();
  56.         try {
  57.             $result parent::execute($params);
  58.         } finally {
  59.             $query->stop();
  60.             if ($this->stopwatch) {
  61.                 $this->stopwatch->stop('doctrine');
  62.             }
  63.         }
  64.         return $result;
  65.     }
  66. }