summaryrefslogtreecommitdiff
path: root/vendor/doctrine/dbal/src/Driver/PgSQL/ConvertParameters.php
blob: 795f12d2fa428719534d3c0db729436301179c13 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php

declare(strict_types=1);

namespace Doctrine\DBAL\Driver\PgSQL;

use Doctrine\DBAL\SQL\Parser\Visitor;

use function count;
use function implode;

final class ConvertParameters implements Visitor
{
    /** @var list<string> */
    private array $buffer = [];

    /** @var array<array-key, int> */
    private array $parameterMap = [];

    public function acceptPositionalParameter(string $sql): void
    {
        $position                      = count($this->parameterMap) + 1;
        $this->parameterMap[$position] = $position;
        $this->buffer[]                = '$' . $position;
    }

    public function acceptNamedParameter(string $sql): void
    {
        $position                 = count($this->parameterMap) + 1;
        $this->parameterMap[$sql] = $position;
        $this->buffer[]           = '$' . $position;
    }

    public function acceptOther(string $sql): void
    {
        $this->buffer[] = $sql;
    }

    public function getSQL(): string
    {
        return implode('', $this->buffer);
    }

    /** @return array<array-key, int> */
    public function getParameterMap(): array
    {
        return $this->parameterMap;
    }
}