Skip to content

[Yaml] dump customization option with dumper flags #17578

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

Merged
merged 1 commit into from
Feb 5, 2016

Conversation

xabbuh
Copy link
Member

@xabbuh xabbuh commented Jan 27, 2016

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? yes
Tests pass? yes
Fixed tickets #17520
License MIT
Doc PR symfony/symfony-docs#6226

@javiereguiluz
Copy link
Member

@xabbuh thanks for working on this nice feature!

I have a proposal regarding the new constants. You propose to define the constants in Dumper class, which forces you to add a new use and to remember in which Yaml class the constant is defined:

use Symfony\Component\Yaml\Yaml;
use Symfony\Component\Yaml\Dumper;

Yaml::dump(array('foo' => new A(), 'bar' => 1), 0, 0, false, Dumper::DUMP_OBJECT);

I propose to define these constants in the main Yaml class. This saves you one use and eases the learning curve, because Yaml constants are .... in Yaml class:

use Symfony\Component\Yaml\Yaml;

Yaml::dump(array('foo' => new A(), 'bar' => 1), 0, 0, false, Yaml::DUMP_OBJECT);

What do you think about this?

@fabpot
Copy link
Member

fabpot commented Feb 1, 2016

👍

@xabbuh
Copy link
Member Author

xabbuh commented Feb 1, 2016

@javiereguiluz Your suggestion sounds reasonable to me as the Yaml class should be the main class users of the component deal with. What do the others think?

@fabpot
Copy link
Member

fabpot commented Feb 1, 2016

Good suggestion

@@ -42,17 +44,23 @@ public function setIndentation($num)
* @param int $inline The level where you switch to inline YAML
* @param int $indent The level of indentation (used internally)
* @param bool $exceptionOnInvalidType true if an exception must be thrown on invalid types (a PHP resource or object), false otherwise
* @param bool $objectSupport true if object support is enabled, false otherwise
* @param int $flags A bit field of DUMP_* constants to customize the dumped YAML string
Copy link
Contributor

Choose a reason for hiding this comment

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

is bit correct or is integer better?

Copy link
Member Author

Choose a reason for hiding this comment

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

Bit is right. Each future dumper option will get its own bit so that we can use PHP's bitwise operators to check if a particular dumper option was requested.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@xabbuh
Copy link
Member Author

xabbuh commented Feb 1, 2016

@javiereguiluz I moved the constant to the Yaml class.

ping @symfony/deciders

{
if (is_bool($flags)) {
@trigger_error('Passing a boolean flag to toogle object support is deprecated since version 3.1 and will be removed in 4.0. Use the Dumper::DUMP_OBJECT flag instead.', E_USER_DEPRECATED);
Copy link
Contributor

Choose a reason for hiding this comment

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

Dumper::DUMP_OBJECT -> Yaml::DUMP_OBJECT

Copy link
Member Author

Choose a reason for hiding this comment

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

@DavidBadura Thanks for catching all these silly mistakes.

{
if (is_bool($flags)) {
@trigger_error('Passing a boolean flag to toogle object support is deprecated since version 3.1 and will be removed in 4.0. Use the DUMP_OBJECT flag instead.', E_USER_DEPRECATED);
Copy link
Member

Choose a reason for hiding this comment

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

typo: toggle

Copy link
Member Author

Choose a reason for hiding this comment

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

good catch, fixed everywhere

After:

```php
Yaml::dump(array('foo' => new A(), 'bar' => 1), 0, 0, false, Dumper::DUMP_OBJECT);
Copy link
Contributor

Choose a reason for hiding this comment

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

And here ;)

Copy link
Member Author

Choose a reason for hiding this comment

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

oh, c'mon :D

@webmozart
Copy link
Contributor

👍

@xabbuh xabbuh merged commit 286103b into symfony:master Feb 5, 2016
xabbuh added a commit that referenced this pull request Feb 5, 2016
…bbuh)

This PR was merged into the 3.1-dev branch.

Discussion
----------

[Yaml] dump customization option with dumper flags

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

Commits
-------

286103b [Yaml] dump customization option with dumper flags
@xabbuh xabbuh deleted the issue-17520 branch February 5, 2016 07:59
@xabbuh xabbuh mentioned this pull request Feb 5, 2016
7 tasks
fabpot added a commit that referenced this pull request Feb 6, 2016
…ger (xabbuh)

This PR was merged into the 3.1-dev branch.

Discussion
----------

[TwigBridge] deprecate the boolean object support trigger

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

This reflects the changes done in the Yaml component in #17578.

Commits
-------

27243c6 deprecate the boolean object support trigger
fabpot added a commit that referenced this pull request Feb 9, 2016
…r (xabbuh)

This PR was merged into the 3.1-dev branch.

Discussion
----------

[Yaml] introduce flags to customize the parser behavior

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

Since #17578 it is possible to customise dumped YAML strings with an optional bit field. This pull request does the same for the parser part of the Yaml component.

Commits
-------

9cb8552 introduce flags to customize the parser behavior
@fabpot fabpot mentioned this pull request May 13, 2016
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.

8 participants