Skip to content

missing: yaml:dump() option to export multi-line strings as string literal #16604

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

Closed
schorsch3000 opened this issue Nov 19, 2015 · 3 comments
Closed

Comments

@schorsch3000
Copy link

Hi,
i Need to dump datastructures as Yaml, having multiline-strings as String-literals.
yaml::parse is able to read string in this format, mit you can't dump it.

So for now i have hacked the dumper to do what i need, but that's not nice.
I would happily implement that correct, write tests and documentation and send a pull-request, but i would like to here if that is something you would like to see in your code.
Also we should talk about how to trigger that behavior. Should i just add another Parameter $useStringLiteral = false ?

Greetings Schorsch

@xabbuh xabbuh added the Yaml label Nov 20, 2015
@fonsecas72
Copy link

Hi there, can you please provide some samples of the current and expected behaviour?
I think it would ease things :)
🐝

@schorsch3000
Copy link
Author

Sure.
Maybe i should explain my needs before:
i have config-files which are written by people and by a script. These configfiles are in YAML, have mostly small values, like numbers, booleans or pathes, but also multiline-text.
So a human would write something like this:

boolean: true
number: 42
path: /dev/null
name: John Doe
loremIpsum: |
  Lorem ipsum dolor sit amet,
  consetetur sadipscing elitr,
  sed diam nonumy eirmod tempor
  invidunt ut labore et dolore
  magna aliquyam erat, sed
  diam voluptua. At vero eos
  et accusam et justo duo
  dolores et ea rebum.
  Stet clita kasd gubergren,
  no sea takimata sanctus
  est Lorem ipsum dolor
  sit amet.

Which is valid YAML, and YAML::parse() is fine to parse.

So maybe my script needs to increase the number in this configurationfile.

<?php
include 'vendor/autoload.php';
$config=Symfony\Component\Yaml\Yaml::parse(file_get_contents('test.yaml'));
$config['number']++;
echo \Symfony\Component\Yaml\Yaml::dump($config);

which will result in:

boolean: true
number: 43
path: /dev/null
name: 'John Doe'
loremIpsum: "Lorem ipsum dolor sit amet,\nconsetetur sadipscing elitr,\nsed diam nonumy eirmod tempor\ninvidunt ut labore et dolore\nmagna aliquyam erat, sed\ndiam voluptua. At vero eos\net accusam et justo duo\ndolores et ea rebum.\nStet clita kasd gubergren,\nno sea takimata sanctus\nest Lorem ipsum dolor\nsit amet."

Which is totally fine and valid YAML, but quite annoying to edit by hand.

Also what's up with your bee? :)

@sstok
Copy link
Contributor

sstok commented Dec 9, 2015

👍 Yes please!

@xabbuh xabbuh added this to the 3.1 milestone Feb 8, 2016
fabpot added a commit that referenced this issue Mar 1, 2016
…cks (xabbuh)

This PR was merged into the 3.1-dev branch.

Discussion
----------

[Yaml] option to dump multi line strings as scalar blocks

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #16236, #16604, #17912, #17391
| License       | MIT
| Doc PR        | TODO

Commits
-------

eff6902 option to dump multi line strings as scalar blocks
@fabpot fabpot closed this as completed Mar 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants