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

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\DBAL3;
  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\Bridge\Doctrine\Middleware\Debug\DebugDataHolder;
  16. use Symfony\Bridge\Doctrine\Middleware\Debug\Query;
  17. use Symfony\Component\Stopwatch\Stopwatch;
  18. /**
  19. * @author Laurent VOULLEMIER <laurent.voullemier@gmail.com>
  20. *
  21. * @internal
  22. */
  23. final class Statement extends AbstractStatementMiddleware
  24. {
  25. private $query;
  26. private $debugDataHolder;
  27. private $connectionName;
  28. private $stopwatch;
  29. public function __construct(
  30. StatementInterface $statement,
  31. DebugDataHolder $debugDataHolder,
  32. string $connectionName,
  33. string $sql,
  34. ?Stopwatch $stopwatch = null
  35. ) {
  36. $this->stopwatch = $stopwatch;
  37. $this->connectionName = $connectionName;
  38. $this->debugDataHolder = $debugDataHolder;
  39. $this->query = new Query($sql);
  40. parent::__construct($statement);
  41. }
  42. public function bindParam($param, &$variable, $type = ParameterType::STRING, $length = null): bool
  43. {
  44. $this->query->setParam($param, $variable, $type);
  45. return parent::bindParam($param, $variable, $type, ...\array_slice(\func_get_args(), 3));
  46. }
  47. public function bindValue($param, $value, $type = ParameterType::STRING): bool
  48. {
  49. $this->query->setValue($param, $value, $type);
  50. return parent::bindValue($param, $value, $type);
  51. }
  52. public function execute($params = null): ResultInterface
  53. {
  54. if (null !== $params) {
  55. $this->query->setValues($params);
  56. }
  57. // clone to prevent variables by reference to change
  58. $this->debugDataHolder->addQuery($this->connectionName, $query = clone $this->query);
  59. if ($this->stopwatch) {
  60. $this->stopwatch->start('doctrine', 'doctrine');
  61. }
  62. $query->start();
  63. try {
  64. return parent::execute($params);
  65. } finally {
  66. $query->stop();
  67. if ($this->stopwatch) {
  68. $this->stopwatch->stop('doctrine');
  69. }
  70. }
  71. }
  72. }