|
6 | 6 |
|
7 | 7 | use Closure; |
8 | 8 | use DateTimeInterface; |
9 | | -use DateTimeZone; |
10 | 9 | use Psr\Http\Message\StreamInterface; |
11 | 10 | use SimPod\ClickHouseClient\Exception\UnsupportedParamType; |
12 | | -use SimPod\ClickHouseClient\Sql\Escaper; |
13 | 11 | use SimPod\ClickHouseClient\Exception\UnsupportedParamValue; |
| 12 | +use SimPod\ClickHouseClient\Sql\Escaper; |
14 | 13 | use SimPod\ClickHouseClient\Sql\Type; |
15 | 14 |
|
16 | 15 | use function array_keys; |
|
33 | 32 | * @phpstan-type Converter Closure(mixed, Type|string|null, bool):(StreamInterface|string) |
34 | 33 | * @phpstan-type ConverterRegistry array<string, Converter> |
35 | 34 | */ |
36 | | -final readonly class ParamValueConverterRegistry |
| 35 | +final class ParamValueConverterRegistry |
37 | 36 | { |
38 | 37 | private const CaseInsensitiveTypes = [ |
39 | 38 | 'bool', |
@@ -93,13 +92,21 @@ public function __construct(array $registry = []) |
93 | 92 |
|
94 | 93 | 'bool' => static fn (bool $value) => $value, |
95 | 94 |
|
96 | | - 'date' => self::dateConverter($this->clickHouseTimeZone), |
97 | | - 'date32' => self::dateConverter($this->clickHouseTimeZone), |
98 | | - 'datetime' => self::dateTimeConverter($this->clickHouseTimeZone), |
99 | | - 'datetime32' => self::dateTimeConverter($this->clickHouseTimeZone), |
100 | | - 'datetime64' => static fn (DateTimeInterface|string|int|float $value) => $value instanceof DateTimeInterface |
101 | | - ? $value->format('U.u') |
102 | | - : $value, |
| 95 | + 'date' => self::dateConverter(), |
| 96 | + 'date32' => self::dateConverter(), |
| 97 | + 'datetime' => self::dateTimeConverter(), |
| 98 | + 'datetime32' => self::dateTimeConverter(), |
| 99 | + 'datetime64' => static function (mixed $value) { |
| 100 | + if ($value instanceof DateTimeInterface) { |
| 101 | + return $value->format('U.u'); |
| 102 | + } |
| 103 | + |
| 104 | + if (is_string($value) || is_float($value) || is_int($value)) { |
| 105 | + return $value; |
| 106 | + } |
| 107 | + |
| 108 | + throw UnsupportedParamValue::type($value); |
| 109 | + }, |
103 | 110 |
|
104 | 111 | 'Dynamic' => self::noopConverter(), |
105 | 112 | 'Variant' => self::noopConverter(), |
|
0 commit comments