Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #28551 [VarDumper] add caster for MessageFormatter (nicolas-g…
…rekas) This PR was merged into the 4.2-dev branch. Discussion ---------- [VarDumper] add caster for MessageFormatter | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - There are more classes in intl that could benefit from having a caster, see http://php.net/manual/en/book.intl.php Let's start with MessageFormatter. PRs welcome for adding more. Commits ------- aa24e4c [VarDumper] add caster for MessageFormatter
- Loading branch information
Showing
3 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\VarDumper\Caster; | ||
|
||
use Symfony\Component\VarDumper\Cloner\Stub; | ||
|
||
/** | ||
* @author Nicolas Grekas <p@tchwork.com> | ||
*/ | ||
class IntlCaster | ||
{ | ||
public static function castMessageFormatter(\MessageFormatter $c, array $a, Stub $stub, $isNested) | ||
{ | ||
$a += array( | ||
Caster::PREFIX_VIRTUAL.'locale' => $c->getLocale(), | ||
Caster::PREFIX_VIRTUAL.'pattern' => $c->getPattern(), | ||
); | ||
|
||
if ($errorCode = $c->getErrorCode()) { | ||
$a += array( | ||
Caster::PREFIX_VIRTUAL.'error_code' => $errorCode, | ||
Caster::PREFIX_VIRTUAL.'error_message' => $c->getErrorMessage(), | ||
); | ||
} | ||
|
||
return $a; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/Symfony/Component/VarDumper/Tests/Caster/IntlCasterTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\VarDumper\Tests\Caster; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\VarDumper\Test\VarDumperTestTrait; | ||
|
||
/** | ||
* @requires extension intl | ||
*/ | ||
class IntlCasterTest extends TestCase | ||
{ | ||
use VarDumperTestTrait; | ||
|
||
public function testArrayIterator() | ||
{ | ||
$var = new \MessageFormatter('en', 'Hello {name}'); | ||
|
||
$expected = <<<EOTXT | ||
MessageFormatter { | ||
locale: "en" | ||
pattern: "Hello {name}" | ||
} | ||
EOTXT; | ||
$this->assertDumpEquals($expected, $var); | ||
} | ||
} |