-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[Translation] added option json_options to JsonFileDumper. #15756
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,21 @@ class JsonFileDumper extends FileDumper | |
*/ | ||
public function format(MessageCatalogue $messages, $domain = 'messages') | ||
{ | ||
return json_encode($messages->all($domain), defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0); | ||
return $this->formatCatalogue($messages, $domain); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array()) | ||
{ | ||
if (isset($options['json_encoding'])) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe call this json_flags or json_options? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but can we take on #14750 (comment) ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, then fine for json_encoding... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reverted, thanks! |
||
$flags = $options['json_encoding']; | ||
} else { | ||
$flags = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0; | ||
} | ||
|
||
return json_encode($messages->all($domain), $flags); | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,18 @@ | |
|
||
class JsonFileDumperTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
private $tempDir; | ||
|
||
protected function setUp() | ||
{ | ||
$this->tempDir = sys_get_temp_dir(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should add also There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In fact, I'd suggest removing $this->tempDir and setUp() There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed |
||
} | ||
|
||
protected function tearDown() | ||
{ | ||
unlink($this->tempDir.'/messages.en.json'); | ||
} | ||
|
||
public function testDump() | ||
{ | ||
if (PHP_VERSION_ID < 50400) { | ||
|
@@ -25,12 +37,20 @@ public function testDump() | |
$catalogue = new MessageCatalogue('en'); | ||
$catalogue->add(array('foo' => 'bar')); | ||
|
||
$tempDir = sys_get_temp_dir(); | ||
$dumper = new JsonFileDumper(); | ||
$dumper->dump($catalogue, array('path' => $tempDir)); | ||
$dumper->dump($catalogue, array('path' => $this->tempDir)); | ||
|
||
$this->assertEquals(file_get_contents(__DIR__.'/../fixtures/resources.json'), file_get_contents($tempDir.'/messages.en.json')); | ||
$this->assertEquals(file_get_contents(__DIR__.'/../fixtures/resources.json'), file_get_contents($this->tempDir.'/messages.en.json')); | ||
} | ||
|
||
public function testDumpWithCustomEncoding() | ||
{ | ||
$catalogue = new MessageCatalogue('en'); | ||
$catalogue->add(array('foo' => '"bar"')); | ||
|
||
$dumper = new JsonFileDumper(); | ||
$dumper->dump($catalogue, array('path' => $this->tempDir, 'json_encoding' => JSON_HEX_QUOT)); | ||
|
||
unlink($tempDir.'/messages.en.json'); | ||
$this->assertEquals(file_get_contents(__DIR__.'/../fixtures/resources.dump.json'), file_get_contents($this->tempDir.'/messages.en.json')); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"foo":"\u0022bar\u0022"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nicolas-grekas see #15699
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
protected
methods must be set afterpublic
ones.