Skip to content

Commit 23ec0c8

Browse files
committed
[fs] Use enqueue/dsn to parse DSN
1 parent b8e2c71 commit 23ec0c8

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

Dsn.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,20 @@ public function getInt(string $name, int $default = null): ?int
165165
return (int) $value;
166166
}
167167

168+
public function getOctal(string $name, int $default = null): ?int
169+
{
170+
$value = $this->getQueryParameter($name);
171+
if (null === $value) {
172+
return $default;
173+
}
174+
175+
if (false == preg_match('/^[\+\-]?[0-9]*$/', $value)) {
176+
throw InvalidQueryParameterTypeException::create($name, 'integer');
177+
}
178+
179+
return intval($value, 8);
180+
}
181+
168182
public function getFloat(string $name, float $default = null): ?float
169183
{
170184
$value = $this->getQueryParameter($name);

Tests/DsnTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,16 @@ public function testShouldParseQueryParameterAsInt(string $parameter, int $expec
107107
$this->assertSame($expected, $dsn->getInt('aName'));
108108
}
109109

110+
/**
111+
* @dataProvider provideOctalQueryParameters
112+
*/
113+
public function testShouldParseQueryParameterAsOctalInt(string $parameter, int $expected)
114+
{
115+
$dsn = new Dsn('foo:?aName='.$parameter);
116+
117+
$this->assertSame($expected, $dsn->getOctal('aName'));
118+
}
119+
110120
public function testShouldReturnDefaultIntIfNotSet()
111121
{
112122
$dsn = new Dsn('foo:');
@@ -204,6 +214,13 @@ public static function provideIntQueryParameters()
204214
yield ['+123', 123];
205215

206216
yield ['-123', -123];
217+
218+
yield ['010', 10];
219+
}
220+
221+
public static function provideOctalQueryParameters()
222+
{
223+
yield ['010', 8];
207224
}
208225

209226
public static function provideFloatQueryParameters()

0 commit comments

Comments
 (0)