From bf6655a534a6775d30cafa67bd801276bda1d98d Mon Sep 17 00:00:00 2001 From: polo Date: Tue, 13 Aug 2024 23:45:21 +0200 Subject: =?UTF-8?q?VERSION=200.2=20doctrine=20ORM=20et=20entit=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vendor/doctrine/dbal/src/ExpandArrayParameters.php | 128 +++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 vendor/doctrine/dbal/src/ExpandArrayParameters.php (limited to 'vendor/doctrine/dbal/src/ExpandArrayParameters.php') diff --git a/vendor/doctrine/dbal/src/ExpandArrayParameters.php b/vendor/doctrine/dbal/src/ExpandArrayParameters.php new file mode 100644 index 0000000..253861c --- /dev/null +++ b/vendor/doctrine/dbal/src/ExpandArrayParameters.php @@ -0,0 +1,128 @@ + */ + private array $convertedSQL = []; + + /** @var list */ + private array $convertedParameters = []; + + /** @var array,string|ParameterType|Type> */ + private array $convertedTypes = []; + + /** + * @param array|array $parameters + * @psalm-param WrapperParameterTypeArray $types + */ + public function __construct( + private readonly array $parameters, + private readonly array $types, + ) { + } + + public function acceptPositionalParameter(string $sql): void + { + $index = $this->originalParameterIndex; + + if (! array_key_exists($index, $this->parameters)) { + throw MissingPositionalParameter::new($index); + } + + $this->acceptParameter($index, $this->parameters[$index]); + + $this->originalParameterIndex++; + } + + public function acceptNamedParameter(string $sql): void + { + $name = substr($sql, 1); + + if (! array_key_exists($name, $this->parameters)) { + throw MissingNamedParameter::new($name); + } + + $this->acceptParameter($name, $this->parameters[$name]); + } + + public function acceptOther(string $sql): void + { + $this->convertedSQL[] = $sql; + } + + public function getSQL(): string + { + return implode('', $this->convertedSQL); + } + + /** @return list */ + public function getParameters(): array + { + return $this->convertedParameters; + } + + private function acceptParameter(int|string $key, mixed $value): void + { + if (! isset($this->types[$key])) { + $this->convertedSQL[] = '?'; + $this->convertedParameters[] = $value; + + return; + } + + $type = $this->types[$key]; + + if (! $type instanceof ArrayParameterType) { + $this->appendTypedParameter([$value], $type); + + return; + } + + if (count($value) === 0) { + $this->convertedSQL[] = 'NULL'; + + return; + } + + $this->appendTypedParameter($value, ArrayParameterType::toElementParameterType($type)); + } + + /** @return array,string|ParameterType|Type> */ + public function getTypes(): array + { + return $this->convertedTypes; + } + + /** @param list $values */ + private function appendTypedParameter(array $values, string|ParameterType|Type $type): void + { + $this->convertedSQL[] = implode(', ', array_fill(0, count($values), '?')); + + $index = count($this->convertedParameters); + + foreach ($values as $value) { + $this->convertedParameters[] = $value; + $this->convertedTypes[$index] = $type; + + $index++; + } + } +} -- cgit v1.2.3