Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7190720

Browse files
committed
[VarDumper] add caster for NumberFormatter
1 parent 7ae5722 commit 7190720

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

src/Symfony/Component/VarDumper/Caster/IntlCaster.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,19 @@ public static function castMessageFormatter(\MessageFormatter $c, array $a, Stub
3434

3535
return $a;
3636
}
37+
38+
public static function castNumberFormatter(\NumberFormatter $c, array $a, Stub $stub, $isNested)
39+
{
40+
$a += array(
41+
Caster::PREFIX_VIRTUAL.'locale' => $c->getLocale(),
42+
Caster::PREFIX_VIRTUAL.'pattern' => $c->getPattern(),
43+
);
44+
if ($errorCode = $c->getErrorCode()) {
45+
$a += array(
46+
Caster::PREFIX_VIRTUAL.'error_code' => $errorCode,
47+
Caster::PREFIX_VIRTUAL.'error_message' => $c->getErrorMessage(),
48+
);
49+
}
50+
return $a;
51+
}
3752
}

src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ abstract class AbstractCloner implements ClonerInterface
118118
'GMP' => array('Symfony\Component\VarDumper\Caster\GmpCaster', 'castGmp'),
119119

120120
'MessageFormatter' => array('Symfony\Component\VarDumper\Caster\IntlCaster', 'castMessageFormatter'),
121+
'NumberFormatter' => array('Symfony\Component\VarDumper\Caster\IntlCaster', 'castNumberFormatter'),
121122

122123
':curl' => array('Symfony\Component\VarDumper\Caster\ResourceCaster', 'castCurl'),
123124
':dba' => array('Symfony\Component\VarDumper\Caster\ResourceCaster', 'castDba'),

src/Symfony/Component/VarDumper/Tests/Caster/IntlCasterTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ public function testArrayIterator()
3030
locale: "en"
3131
pattern: "Hello {name}"
3232
}
33+
EOTXT;
34+
$this->assertDumpEquals($expected, $var);
35+
}
36+
37+
public function testCastNumberFormatter()
38+
{
39+
$var = new \NumberFormatter('en', \NumberFormatter::DECIMAL);
40+
$expected = <<<EOTXT
41+
NumberFormatter {
42+
locale: "en"
43+
pattern: "#,##0.###"
44+
}
3345
EOTXT;
3446
$this->assertDumpEquals($expected, $var);
3547
}

0 commit comments

Comments
 (0)