Skip to content

Commit 728bf1c

Browse files
committed
always return query bag on getArray.
1 parent 0d57187 commit 728bf1c

3 files changed

Lines changed: 5 additions & 4 deletions

File tree

‎docs/dsn.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,14 @@ Get typed query params:
9191
<?php
9292
use Enqueue\Dsn\Dsn;
9393

94-
$dsn = Dsn::parseFirst('sqs:?decimal=12&octal=0666&float=1.2&bool=1&array[0]=val');
94+
$dsn = Dsn::parseFirst('sqs:?decimal=12&octal=0666&float=1.2&bool=1&array[0]=val&array[1]=123');
9595

9696
$dsn->getDecimal('decimal'); // 12
9797
$dsn->getOctal('decimal'); // 0666
9898
$dsn->getFloat('float'); // 1.2
9999
$dsn->getBool('bool'); // true
100100
$dsn->getArray('array')->getString(0); // val
101+
$dsn->getArray('array')->getDecimal(1); // 123
101102
$dsn->getArray('array')->toArray(); // [val]
102103
```
103104

‎pkg/dsn/Dsn.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public function getBool(string $name, bool $default = null): ?bool
175175
return $this->queryBag->getBool($name, $default);
176176
}
177177

178-
public function getArray(string $name, bool $default = null): QueryBag
178+
public function getArray(string $name, array $default = []): QueryBag
179179
{
180180
return $this->queryBag->getArray($name, $default);
181181
}

‎pkg/dsn/QueryBag.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ public function getBool(string $name, bool $default = null): ?bool
8686
throw InvalidQueryParameterTypeException::create($name, 'bool');
8787
}
8888

89-
public function getArray(string $name, bool $default = null): ?self
89+
public function getArray(string $name, array $default = []): self
9090
{
9191
if (false == array_key_exists($name, $this->query)) {
92-
return $default;
92+
return new self($default);
9393
}
9494

9595
$value = $this->query[$name];

0 commit comments

Comments
 (0)