Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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

Merged
fabpot merged 2 commits intosymfony:3.2fromxabbuh:pr-22392
May 11, 2017

Conversation

@xabbuh
Copy link
Member

QA
Branch?3.2
Bug fix?yes
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#22392
LicenseMIT
Doc PR

Copy link
Member

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

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

👍

@stof
Copy link
Member

Please also add a test with an empty ArrayObject or stdClass, to ensure it keeps being dumped as{} and not[].

@xabbuh
Copy link
MemberAuthor

done

@goetas
Copy link
Contributor

goetas commentedApr 13, 2017
edited
Loading

Hi, I'm not sure is the best approach to solve the issue.
The following test will fail:

// 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 sincecastObjectToArray removes all theArrarObject instances

@goetas
Copy link
Contributor

I will also try to find a solution

@xabbuh
Copy link
MemberAuthor

Status: Needs work

@goetas
Copy link
Contributor

Here is my version of the fix#22419

@goetas
Copy link
Contributor

goetas commentedApr 13, 2017
edited
Loading

Question: why#21471 is considered as a new feature? IMO should be a bugfix and included in the 3.2 branch.
Empty arrays should be serialized as[ ], and empty arrayobject instances should be serialized as{ }. The same behavior is used withjson_encode.

The only feature in#21471 should bethis that allows to dump an empty arrayobject (or a stdclass) as[ ] instead of{ }

@xabbuhxabbuhforce-pushed thepr-22392 branch 3 times, most recently frome52ff8e tofe515b3CompareApril 13, 2017 12:13
@stof
Copy link
Member

Question: why#21471 is considered as a new feature?

This relies on adding a new constant for the configuration flag => this is a new feature for the component

@goetas
Copy link
Contributor

@xabbuh did you check my work at#22419

@goetas
Copy link
Contributor

@stof i see, thanks

@goetas
Copy link
Contributor

@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)) {
Copy link
Contributor

@goetasgoetasApr 13, 2017
edited
Loading

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
Copy link
Contributor

goetas commentedApr 13, 2017
edited
Loading

Did not knowstdClass can be used in aforeach loop. Looks to be "iterable" even ifis_iterable says is nothttps://3v4l.org/bY9IC

@stof
Copy link
Member

@goetas it does not pass theiterable typehint either. but iterating over a non-iterable object iterates over public properties in PHP.

@goetas
Copy link
Contributor

@stof Is so beautiful to learn things about PHP every day after so many years☺️

@stof
Copy link
Member

Seehttps://3v4l.org/tu1Z0 for the proof btw

@goetas
Copy link
Contributor

Do this PR need still work?

For me is 👍

@fabpot
Copy link
Member

Thank you@xabbuh.

@fabpotfabpot merged commit3cca48c intosymfony:3.2May 11, 2017
fabpot added a commit that referenced this pull requestMay 11, 2017
…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
@xabbuhxabbuh deleted the pr-22392 branchMay 11, 2017 18:45
@fabpotfabpot mentioned this pull requestMay 17, 2017
@fabpotfabpot mentioned this pull requestMay 29, 2017
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

+1 more reviewer

@goetasgoetasgoetas left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

3.2

Development

Successfully merging this pull request may close these issues.

6 participants

@xabbuh@stof@goetas@fabpot@nicolas-grekas@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp