<?php namespace Doctrine\DBAL; use Doctrine\DBAL\ArrayParameters\Exception\MissingNamedParameter; use Doctrine\DBAL\ArrayParameters\Exception\MissingPositionalParameter; use Doctrine\DBAL\SQL\Parser\Visitor; use Doctrine\DBAL\Types\Type; use function array_fill; use function array_key_exists; use function count; use function implode; use function substr; final class ExpandArrayParameters implements Visitor { /** @var array<int,mixed>|array<string,mixed> */ private array $originalParameters; /** @var array<int,Type|int|string|null>|array<string,Type|int|string|null> */ private array $originalTypes; private int $originalParameterIndex = 0; /** @var list<string> */ private array $convertedSQL = []; /** @var list<mixed> */ private array $convertedParameters = []; /** @var array<int,Type|int|string|null> */ private array $convertedTypes = []; /** * @param array<int, mixed>|array<string, mixed> $parameters * @param array<int,Type|int|string|null>|array<string,Type|int|string|null> $types */ public function __construct(array $parameters, array $types) { $this->originalParameters = $parameters; $this->originalTypes = $types; } public function acceptPositionalParameter(string $sql): void { $index = $this->originalParameterIndex; if (! array_key_exists($index, $this->originalParameters)) { throw MissingPositionalParameter::new($index); } $this->acceptParameter($index, $this->originalParameters[$index]); $this->originalParameterIndex++; } public function acceptNamedParameter(string $sql): void { $name = substr($sql, 1); if (! array_key_exists($name, $this->originalParameters)) { throw MissingNamedParameter::new($name); } $this->acceptParameter($name, $this->originalParameters[$name]); } public function acceptOther(string $sql): void { $this->convertedSQL[] = $sql; } public function getSQL(): string { return implode('', $this->convertedSQL); } /** @return list<mixed> */ public function getParameters(): array { return $this->convertedParameters; } /** * @param int|string $key * @param mixed $value */ private function acceptParameter($key, $value): void { if (! isset($this->originalTypes[$key])) { $this->convertedSQL[] = '?'; $this->convertedParameters[] = $value; return; } $type = $this->originalTypes[$key]; if ( $type !== ArrayParameterType::INTEGER && $type !== ArrayParameterType::STRING && $type !== ArrayParameterType::ASCII ) { $this->appendTypedParameter([$value], $type); return; } if (count($value) === 0) { $this->convertedSQL[] = 'NULL'; return; } $this->appendTypedParameter($value, ArrayParameterType::toElementParameterType($type)); } /** @return array<int,Type|int|string|null> */ public function getTypes(): array { return $this->convertedTypes; } /** * @param list<mixed> $values * @param Type|int|string|null $type */ private function appendTypedParameter(array $values, $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++; } } }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
ArrayParameters | Folder | 0755 |
|
|
Cache | Folder | 0755 |
|
|
Connections | Folder | 0755 |
|
|
Driver | Folder | 0755 |
|
|
Event | Folder | 0755 |
|
|
Exception | Folder | 0755 |
|
|
Id | Folder | 0755 |
|
|
Logging | Folder | 0755 |
|
|
Platforms | Folder | 0755 |
|
|
Portability | Folder | 0755 |
|
|
Query | Folder | 0755 |
|
|
SQL | Folder | 0755 |
|
|
Schema | Folder | 0755 |
|
|
Tools | Folder | 0755 |
|
|
Types | Folder | 0755 |
|
|
ArrayParameterType.php | File | 982 B | 0644 |
|
ColumnCase.php | File | 429 B | 0644 |
|
Configuration.php | File | 6.52 KB | 0644 |
|
Connection.php | File | 62.62 KB | 0644 |
|
ConnectionException.php | File | 917 B | 0644 |
|
Driver.php | File | 1.62 KB | 0644 |
|
DriverManager.php | File | 8.95 KB | 0644 |
|
Events.php | File | 1.58 KB | 0644 |
|
Exception.php | File | 4.95 KB | 0644 |
|
ExpandArrayParameters.php | File | 3.69 KB | 0644 |
|
FetchMode.php | File | 333 B | 0644 |
|
LockMode.php | File | 419 B | 0644 |
|
ParameterType.php | File | 982 B | 0644 |
|
Query.php | File | 1.16 KB | 0644 |
|
Result.php | File | 7.85 KB | 0644 |
|
Statement.php | File | 7.46 KB | 0644 |
|
TransactionIsolationLevel.php | File | 601 B | 0644 |
|
VersionAwarePlatformDriver.php | File | 1.02 KB | 0644 |
|