Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaa24e4c

Browse files
[VarDumper] add caster for MessageFormatter
1 parentc51592c commitaa24e4c

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+
namespaceSymfony\Component\VarDumper\Caster;
13+
14+
useSymfony\Component\VarDumper\Cloner\Stub;
15+
16+
/**
17+
* @author Nicolas Grekas <p@tchwork.com>
18+
*/
19+
class IntlCaster
20+
{
21+
publicstaticfunctioncastMessageFormatter(\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+
namespaceSymfony\Component\VarDumper\Tests\Caster;
13+
14+
usePHPUnit\Framework\TestCase;
15+
useSymfony\Component\VarDumper\Test\VarDumperTestTrait;
16+
17+
/**
18+
* @requires extension intl
19+
*/
20+
class IntlCasterTestextends TestCase
21+
{
22+
use VarDumperTestTrait;
23+
24+
publicfunctiontestArrayIterator()
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)

[8]ページ先頭

©2009-2025 Movatter.jp