Skip to content
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

[Translation][File dumper] allow get file content without writing in file. #15786

Merged
merged 2 commits into from
Sep 22, 2015

Conversation

aitboudad
Copy link
Contributor

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Fixed tickets #14881
Tests pass? yes
License MIT

@@ -63,26 +63,34 @@ public function setBackup($backup)
*/
public function dump(MessageCatalogue $messages, $options = array())
{
if (!array_key_exists('path', $options)) {
throw new \InvalidArgumentException('The file dumper needs a path option.');
if (!array_key_exists('path', $options) && !array_key_exists('format_callback', $options)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the name format_callback looks weird to me. This callback is not responsible for any formatting, but for saving

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's about save_handler ?

* added options `as_tree`, `inline` to YamlFileDumper
* added option `save_handler` to FileDumper.
* added option `json_encoding` to JsonFileDumper.
* added options `as_tree`, `inline` to YamlFileDumper.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The three dots should be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@aitboudad
Copy link
Contributor Author

ping @symfony/deciders

@Tobion
Copy link
Contributor

Tobion commented Sep 18, 2015

This looks like a workaround for a bad architecture. It doesn't make sense that the formating is tied to dumping to files at all. We could alternatively refactor out the formatting part of the FileDumpers.

So basically refactor the formatCatalogue out of the dumpers into a Formatter for each type. Then the file dumper would just accept a formatter (and file extension + path as now) and put in content in a file. And people who do not want to save the content to a file would just simply use the formatter alone.

@aitboudad
Copy link
Contributor Author

@Tobion thanks for pointing me in the right direction. Seems making formatCatalogue public is enough, can you review it now ?

$this->assertEquals(file_get_contents(__DIR__.'/../fixtures/resources.ini'), file_get_contents($tempDir.'/messages.en.ini'));

unlink($tempDir.'/messages.en.ini');
$this->assertEquals(file_get_contents(__DIR__.'/../fixtures/resources.ini'), $dumper->formatCatalogue($catalogue, 'messages'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertStringEqualsFile?!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, didn't know it :)

@Tobion
Copy link
Contributor

Tobion commented Sep 18, 2015

I see format is deprecated since 2.8. IMO the abstract should be removed from it, so people do not have to implement the deprecated method.

@aitboudad
Copy link
Contributor Author

yes I already removed the abstract, see #15832

@Tobion
Copy link
Contributor

Tobion commented Sep 18, 2015

It don't like that formatting and dumping is still in one class. But this way it might be good enough 👍

@fabpot
Copy link
Member

fabpot commented Sep 22, 2015

Thank you @aitboudad.

@fabpot fabpot merged commit 805acc9 into symfony:2.8 Sep 22, 2015
fabpot added a commit that referenced this pull request Sep 22, 2015
…out writing in file. (aitboudad)

This PR was merged into the 2.8 branch.

Discussion
----------

[Translation][File dumper] allow get file content without writing in file.

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Fixed tickets  | #14881
| Tests pass?   | yes
| License       | MIT

Commits
-------

805acc9 fixed typo.
9b877cf [Translation][File dumper] allow get file content without writing in file.
@aitboudad aitboudad deleted the trans_file_dumper branch September 22, 2015 14:11
@fabpot fabpot mentioned this pull request Nov 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants