Skip to content

Commit

Permalink
fix: support Array(Tuple) params (#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
simPod authored Oct 17, 2024
1 parent bff3805 commit 4384ce7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/Param/ParamValueConverterRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,11 @@ public function __construct()
? $v
: sprintf('[%s]', implode(
',',
array_map(fn (mixed $v) => $this->get($type->params)($v, $type, true), $v),
array_map(function (mixed $v) use ($type) {
$innerType = Type::fromString($type->params);

return $this->get($innerType)($v, $innerType, true);
}, $v),
)),
'Tuple' => function (array|string $v, Type $type) {
if (is_string($v)) {
Expand Down
4 changes: 3 additions & 1 deletion tests/Param/ParamValueConverterRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ public function testConvert(string $type, mixed $value, mixed $expected): void
public static function providerConvert(): Generator
{
yield 'Array' => ['Array(String)', "['foo','bar']", "['foo','bar']"];
yield 'Array LC' => ['Array(LowCardinality(String))', "['foo','bar']", "['foo','bar']"];
yield 'Array (array)' => ['Array(String)', ['foo', 'bar'], "['foo','bar']"];
yield 'Array Tuple' => ['Array(Tuple(String, String))', [['foo', 'bar']], "[('foo','bar')]"];
yield 'Tuple' => ['Tuple(String, Int8)', "('k',1)", "('k',1)"];
yield 'Tuple (array)' => ['Tuple(String, Int8)', ['k', 1], "('k',1)"];

Expand Down Expand Up @@ -250,7 +252,7 @@ public static function providerConvert(): Generator
yield 'IPv6' => ['IPv6', '2001:0000:130F:0000:0000:09C0:876A:130B', '2001:0:130f::9c0:876a:130b'];
}

public function testThrowsOnUknownType(): void
public function testThrowsOnUnknownType(): void
{
$registry = new ParamValueConverterRegistry();

Expand Down

0 comments on commit 4384ce7

Please sign in to comment.