1<?php
2
3namespace Doctrine\DBAL\Driver\OCI8;
4
5use Doctrine\DBAL\SQL\Parser\Visitor;
6
7use function count;
8use function implode;
9
10/**
11 * Converts positional (?) into named placeholders (:param<num>).
12 *
13 * Oracle does not support positional parameters, hence this method converts all
14 * positional parameters into artificially named parameters.
15 *
16 * @internal This class is not covered by the backward compatibility promise
17 */
18final class ConvertPositionalToNamedPlaceholders implements Visitor
19{
20    /** @var list<string> */
21    private $buffer = [];
22
23    /** @var array<int,string> */
24    private $parameterMap = [];
25
26    public function acceptOther(string $sql): void
27    {
28        $this->buffer[] = $sql;
29    }
30
31    public function acceptPositionalParameter(string $sql): void
32    {
33        $position = count($this->parameterMap) + 1;
34        $param    = ':param' . $position;
35
36        $this->parameterMap[$position] = $param;
37
38        $this->buffer[] = $param;
39    }
40
41    public function acceptNamedParameter(string $sql): void
42    {
43        $this->buffer[] = $sql;
44    }
45
46    public function getSQL(): string
47    {
48        return implode('', $this->buffer);
49    }
50
51    /**
52     * @return array<int,string>
53     */
54    public function getParameterMap(): array
55    {
56        return $this->parameterMap;
57    }
58}
59