Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Yaml] respect inline level when dumping objects as maps#22409
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
xabbuh commentedApr 12, 2017
| Q | A |
|---|---|
| Branch? | 3.2 |
| Bug fix? | yes |
| New feature? | no |
| BC breaks? | no |
| Deprecations? | no |
| Tests pass? | yes |
| Fixed tickets | #22392 |
| License | MIT |
| Doc PR |
nicolas-grekas left a comment
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.
👍
stof commentedApr 13, 2017
Please also add a test with an empty ArrayObject or stdClass, to ensure it keeps being dumped as |
xabbuh commentedApr 13, 2017
done |
goetas commentedApr 13, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Hi, I'm not sure is the best approach to solve the issue. // currently failspublicfunctiontestDumpingArrayObjectInstancesWithNumericKeysRespectsInlineLevel(){$deep =new \ArrayObject(array('d','e'));$inner =new \ArrayObject(array('b','c',$deep));$outer =new \ArrayObject(array('a',$inner));$yaml =$this->dumper->dump($outer,2,0, Yaml::DUMP_OBJECT_AS_MAP);$expected =<<<YAML0: a1: 0: b 1: c 2: { 0: d, 1: e }YAML;$this->assertEquals($expected,$yaml);}// This works with 3.1 branchpublicfunctiontestDumpingArrayObjectInstancesWithNumericKeysInlined(){$deep =new \ArrayObject(array('d','e'));$inner =new \ArrayObject(array('b','c',$deep));$outer =new \ArrayObject(array('a',$inner));$yaml =$this->dumper->dump($outer,0,0, Yaml::DUMP_OBJECT_AS_MAP);$expected =<<<YAML{ 0: a, 1: { 0: b, 1: c, 2: { 0: d, 1: e } } }YAML;$this->assertEquals($expected,$yaml);} and the strategy (casting array object ot array) will make really hard (if not impossible) to solve this case and with the current strategy,https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Yaml/Inline.php#L176 is never reached since |
goetas commentedApr 13, 2017
I will also try to find a solution |
xabbuh commentedApr 13, 2017
Status: Needs work |
goetas commentedApr 13, 2017
Here is my version of the fix#22419 |
goetas commentedApr 13, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Question: why#21471 is considered as a new feature? IMO should be a bugfix and included in the 3.2 branch. The only feature in#21471 should bethis that allows to dump an empty arrayobject (or a stdclass) as |
e52ff8e tofe515b3Comparestof commentedApr 13, 2017
This relies on adding a new constant for the configuration flag => this is a new feature for the component |
goetas commentedApr 13, 2017
goetas commentedApr 13, 2017
@stof i see, thanks |
goetas commentedApr 13, 2017
@xabbuh if this is the candidate PR to be merged, do you mind adding: publicfunctiontestDumpingArrayObjectInstancesWithNumericKeysRespectsInlineLevel() {$deep =new \ArrayObject(array('d','e'));$inner =new \ArrayObject(array('b','c',$deep));$outer =new \ArrayObject(array('a',$inner));$yaml =$this->dumper->dump($outer,2,0, Yaml::DUMP_OBJECT_AS_MAP);$expected =<<<YAML0: a1: 0: b 1: c 2: { 0: d, 1: e }YAML;$this->assertEquals($expected,$yaml); } ? |
| $willBeInlined =$inline -1 <=0 || !is_array($value) ||empty($value); | ||
| $dumpObjectAsInlineMap =true; | ||
| if (Yaml::DUMP_OBJECT_AS_MAP &$flags && ($valueinstanceof \ArrayObject ||$valueinstanceof \stdClass)) { |
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.
@xabbuh Should this code be put in a private static method? is identical to what we have on line 86
goetas commentedApr 13, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Did not know |
stof commentedApr 13, 2017
@goetas it does not pass the |
goetas commentedApr 13, 2017
@stof Is so beautiful to learn things about PHP every day after so many years |
stof commentedApr 13, 2017
Seehttps://3v4l.org/tu1Z0 for the proof btw |
goetas commentedApr 17, 2017
Do this PR need still work? For me is 👍 |
fabpot commentedMay 11, 2017
Thank you@xabbuh. |
…goetas, xabbuh)This PR was merged into the 3.2 branch.Discussion----------[Yaml] respect inline level when dumping objects as maps| Q | A| ------------- | ---| Branch? | 3.2| Bug fix? | yes| New feature? | no| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets |#22392| License | MIT| Doc PR |Commits-------3cca48c respect inline level when dumping objects as maps4f5c149 Test case for not in-lined map-objects