Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace Doctrine\DBAL\Logging;
6
 
7
use Doctrine\DBAL\Driver\Middleware\AbstractStatementMiddleware;
8
use Doctrine\DBAL\Driver\Result as ResultInterface;
9
use Doctrine\DBAL\Driver\Statement as StatementInterface;
10
use Doctrine\DBAL\ParameterType;
11
use Doctrine\Deprecations\Deprecation;
12
use Psr\Log\LoggerInterface;
13
 
14
use function array_slice;
15
use function func_get_args;
16
use function func_num_args;
17
 
18
final class Statement extends AbstractStatementMiddleware
19
{
20
    private LoggerInterface $logger;
21
    private string $sql;
22
 
23
    /** @var array<int,mixed>|array<string,mixed> */
24
    private array $params = [];
25
 
26
    /** @var array<int,int>|array<string,int> */
27
    private array $types = [];
28
 
29
    /** @internal This statement can be only instantiated by its connection. */
30
    public function __construct(StatementInterface $statement, LoggerInterface $logger, string $sql)
31
    {
32
        parent::__construct($statement);
33
 
34
        $this->logger = $logger;
35
        $this->sql    = $sql;
36
    }
37
 
38
    /**
39
     * {@inheritdoc}
40
     *
41
     * @deprecated Use {@see bindValue()} instead.
42
     */
43
    public function bindParam($param, &$variable, $type = ParameterType::STRING, $length = null)
44
    {
45
        Deprecation::trigger(
46
            'doctrine/dbal',
47
            'https://github.com/doctrine/dbal/pull/5563',
48
            '%s is deprecated. Use bindValue() instead.',
49
            __METHOD__,
50
        );
51
 
52
        if (func_num_args() < 3) {
53
            Deprecation::trigger(
54
                'doctrine/dbal',
55
                'https://github.com/doctrine/dbal/pull/5558',
56
                'Not passing $type to Statement::bindParam() is deprecated.'
57
                    . ' Pass the type corresponding to the parameter being bound.',
58
            );
59
        }
60
 
61
        $this->params[$param] = &$variable;
62
        $this->types[$param]  = $type;
63
 
64
        return parent::bindParam($param, $variable, $type, ...array_slice(func_get_args(), 3));
65
    }
66
 
67
    /**
68
     * {@inheritdoc}
69
     */
70
    public function bindValue($param, $value, $type = ParameterType::STRING)
71
    {
72
        if (func_num_args() < 3) {
73
            Deprecation::trigger(
74
                'doctrine/dbal',
75
                'https://github.com/doctrine/dbal/pull/5558',
76
                'Not passing $type to Statement::bindValue() is deprecated.'
77
                    . ' Pass the type corresponding to the parameter being bound.',
78
            );
79
        }
80
 
81
        $this->params[$param] = $value;
82
        $this->types[$param]  = $type;
83
 
84
        return parent::bindValue($param, $value, $type);
85
    }
86
 
87
    /**
88
     * {@inheritdoc}
89
     */
90
    public function execute($params = null): ResultInterface
91
    {
92
        $this->logger->debug('Executing statement: {sql} (parameters: {params}, types: {types})', [
93
            'sql'    => $this->sql,
94
            'params' => $params ?? $this->params,
95
            'types'  => $this->types,
96
        ]);
97
 
98
        return parent::execute($params);
99
    }
100
}