8000 [VarDumper] add caster for MessageFormatter · symfony/symfony@aa24e4c · GitHub
[go: up one dir, main page]

Skip to content

Commit aa24e4c

Browse files
[VarDumper] add caster for MessageFormatter
1 parent c51592c commit aa24e4c

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\VarDumper\Caster;
13+
14+
use Symfony\Component\VarDumper\Cloner\Stub;
15+
16+
/**
17+
* @author Nicolas Grekas <p@tchwork.com>
18+
*/
19+
class IntlCaster
20+
{
21+
public static function castMessageFormatter(\MessageFormatter $c, array $a, Stub $stub, $isNested)
22+
{
23+
$a += array(
24+
Caster::PREFIX_VIRTUAL.'locale' => $c->getLocale(),
25+
Caster::PREFIX_VIRTUAL.'pattern' => $c->getPattern(),
26+
);
27+
28+
if ($errorCode = $c->getErrorCode()) {
29+
$a += array(
30+
Caster::PREFIX_VIRTUAL.'error_code' => $errorCode,
31+
Caster::PREFIX_VIRTUAL.'error_message' => $c->getErrorMessage(),
32+
);
33+
}
34+
35+
return $a;
36+
}
37+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ abstract class AbstractCloner implements ClonerInterface
117117

118118
'GMP' => array('Symfony\Component\VarDumper\Caster\GmpCaster', 'castGmp'),
119119

120+
'MessageFormatter' => array('Symfony\Component\VarDumper\Caster\IntlCaster', 'castMessageFormatter'),
121+
120122
':curl' => array('Symfony\Component\VarDumper\Caster\ResourceCaster', 'castCurl'),
121123
':dba' => array('Symfony\Component\VarDumper\Caster\ResourceCaster', 'castDba'),
122124
':dba persistent' => array('Symfony\Component\VarDumper\Caster\ResourceCaster', 'castDba'),
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\VarDumper\Tests\Caster;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\VarDumper\Test\VarDumperTestTrait;
16+
17+
/**
18+
* @requires extension intl
19+
*/
20+
class IntlCasterTest extends TestCase
21+
{
22+
use VarDumperTestTrait;
23+
24+
public function testArrayIterator()
25+
{
26+
$var = new \MessageFormatter('en', 'Hello {name}');
27+
28+
$expected = <<<EOTXT
29+
MessageFormatter {
30+
locale: "en"
31+
pattern: "Hello {name}"
32+
}
33+
EOTXT;
34+
$this->assertDumpEquals($expected, $var);
35+
}
36+
}

0 commit comments

Comments
 (0)
0