Skip to content

Commit 282b52b

Browse files
committed
Merge branch '2.8'
* 2.8: (31 commits) [DomCrawler] Invalid uri created from forms if base tag present [VarDumper] Add caster for OuterIterator objects [Console] update param type phpdoc for StreamOutput [Console] fix typo in OutputInterface Use stderr by default when a specific output is not injected fixed bad merge [Debug] Fix case mismatch detection [HttpKernel] Add entry point to more easily create/configure the DI extension [DX] Added a logout link in the security panel of the web debug toolbar [HttpKernel] fix broken multiline <esi:remove> [DoctrineBridge] Fixed #14840 [FrameworkBundle] add a suggest for the serializer component fixed CS removed non-working tests [WIP] #15502 Make template shortcuts be usable without Templating component Redesigned the Symfony Profiler [Yaml] Fix the parsing of float keys Make the exception output visible even in quiet mode, fixes #15680 Convert Output::write's type to an options arg where verbosity can be passed in as well [Console] Ensure the console output is only detected as decorated when both stderr and stdout support colors ...
2 parents 650c746 + 5f026ce commit 282b52b

File tree

4 files changed

+41
-6
lines changed

4 files changed

+41
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ CHANGELOG
1010
-----
1111

1212
* deprecated Translator::getMessages(), rely on TranslatorBagInterface::getCatalogue() instead.
13+
* added option `json_encoding` to JsonFileDumper
1314
* added options `as_tree`, `inline` to YamlFileDumper
1415
* added support for XLIFF target and tool attributes.
1516
* added message parameters to DataCollectorTranslator.
@@ -18,7 +19,6 @@ CHANGELOG
1819
so the class name is misleading. The `TargetOperation` class should be used for
1920
this use-case instead.
2021

21-
2222
2.7.0
2323
-----
2424

Dumper/JsonFileDumper.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,21 @@ class JsonFileDumper extends FileDumper
2525
*/
2626
public function format(MessageCatalogue $messages, $domain = 'messages')
2727
{
28-
return json_encode($messages->all($domain), defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0);
28+
return $this->formatCatalogue($messages, $domain);
29+
}
30+
31+
/**
32+
* {@inheritdoc}
33+
*/
34+
protected function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
35+
{
36+
if (isset($options['json_encoding'])) {
37+
$flags = $options['json_encoding'];
38+
} else {
39+
$flags = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0;
40+
}
41+
42+
return json_encode($messages->all($domain), $flags);
2943
}
3044

3145
/**

Tests/Dumper/JsonFileDumperTest.php

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,37 @@
1616

1717
class JsonFileDumperTest extends \PHPUnit_Framework_TestCase
1818
{
19+
private $tempDir;
20+
21+
protected function setUp()
22+
{
23+
$this->tempDir = sys_get_temp_dir();
24+
}
25+
26+
protected function tearDown()
27+
{
28+
unlink($this->tempDir.'/messages.en.json');
29+
}
30+
1931
public function testDump()
2032
{
2133
$catalogue = new MessageCatalogue('en');
2234
$catalogue->add(array('foo' => 'bar'));
2335

24-
$tempDir = sys_get_temp_dir();
2536
$dumper = new JsonFileDumper();
26-
$dumper->dump($catalogue, array('path' => $tempDir));
37+
$dumper->dump($catalogue, array('path' => $this->tempDir));
2738

28-
$this->assertEquals(file_get_contents(__DIR__.'/../fixtures/resources.json'), file_get_contents($tempDir.'/messages.en.json'));
39+
$this->assertEquals(file_get_contents(__DIR__.'/../fixtures/resources.json'), file_get_contents($this->tempDir.'/messages.en.json'));
40+
}
41+
42+
public function testDumpWithCustomEncoding()
43+
{
44+
$catalogue = new MessageCatalogue('en');
45+
$catalogue->add(array('foo' => '"bar"'));
46+
47+
$dumper = new JsonFileDumper();
48+
$dumper->dump($catalogue, array('path' => $this->tempDir, 'json_encoding' => JSON_HEX_QUOT));
2949

30-
unlink($tempDir.'/messages.en.json');
50+
$this->assertEquals(file_get_contents(__DIR__.'/../fixtures/resources.dump.json'), file_get_contents($this->tempDir.'/messages.en.json'));
3151
}
3252
}

Tests/fixtures/resources.dump.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"foo":"\u0022bar\u0022"}

0 commit comments

Comments
 (0)