-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Yaml] Allow dumping empty array as YAML sequence #21471
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
Conversation
$dump = $this->dumper->dump(array(), 9, 0, Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE); | ||
$this->assertEquals('[]', $dump); | ||
|
||
$dump = $this->dumper->dump(new \ArrayObject(), 0, 0, Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE | Yaml::DUMP_OBJECT_AS_MAP); |
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.
I would not expect an empty sequence as the result with this input.
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.
Agreed. Fixed.
$dump = $this->dumper->dump(new \ArrayObject(), 0, 0, Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE | Yaml::DUMP_OBJECT_AS_MAP); | ||
$this->assertEquals('[]', $dump); | ||
|
||
$dump = $this->dumper->dump(new \stdClass(), 0, 0, Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE | Yaml::DUMP_OBJECT_AS_MAP); |
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.
same here
@xabbuh I let you merge this one? |
@fabpot Sure, can I understand your comment as a +1 vote? |
@@ -29,6 +29,7 @@ class Yaml | |||
const DUMP_OBJECT_AS_MAP = 64; | |||
const DUMP_MULTI_LINE_LITERAL_BLOCK = 128; | |||
const PARSE_CONSTANT = 256; | |||
const DUMP_EMPTY_ARRAY_AS_SEQUENCE = 512; |
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.
alpha order?
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.
Do you want me to sort all constants alphabetically? I don't see this convention being used elsewhere in Symfony.
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.
I would keep it this way. Otherwise, it's becoming hard to add new flags as you need to be extra careful to not reuse one of the existing flag values.
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.
can't we change the values of the consts?
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.
I like the way it is now, the more recent addition are last with a higher number. I don't see why we should order them.
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.
Sorry for being late here, but I had no time during the weekend to do the final review. This value must be adjusted as 512 is already used by the new tags support feature (see #21678).
@@ -1,6 +1,15 @@ | |||
CHANGELOG | |||
========= | |||
|
|||
3.2.3 |
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.
wrong version
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.
Fixed.
@@ -1,6 +1,15 @@ | |||
CHANGELOG | |||
========= | |||
|
|||
3.2.5 |
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.
That's still not right. New features are only added in minor versions. So this needs to be 3.3
.
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.
Fixed again :-)
4376c7e
to
87ffaf2
Compare
Thank you @c960657. |
…0657) This PR was squashed before being merged into the 3.3-dev branch (closes #21471). Discussion ---------- [Yaml] Allow dumping empty array as YAML sequence | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #9870, #15937, #16266 | License | MIT | Doc PR | PHP arrays are dumped as either YAML sequences or mappings, depending on whether the array has continuos integer keys or not. An empty array is always dumped as a YAML mapping. Sometimes you want it dumped as a YAML sequence instead. Commits ------- 87ffaf2 Bump version number af7067c Dump empty object as mapping a6d94c1 [Yaml] Allow dumping empty array as YAML sequence
PHP arrays are dumped as either YAML sequences or mappings, depending on whether the array has continuos integer keys or not.
An empty array is always dumped as a YAML mapping. Sometimes you want it dumped as a YAML sequence instead.