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

[Serializer] add a context key to return always as collection for XmlEncoder#25369

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

Conversation

@Simperfit
Copy link
Contributor

@SimperfitSimperfit commentedDec 7, 2017
edited by nicolas-grekas
Loading

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

This PR add a newas_collection context key in order to return always as a collection instead of returning a single elements when there are only one array.

there are only one PR for the CsvEncoder don't wanted to have only One PR containing the two changes. It feel better to have two PR that fix the behaviour on two different things. it's easy to review and to revert if it break something (which should not since we are testing the behaviour).

@Simperfit
Copy link
ContributorAuthor

Travis failure is unrelated.

@nicolas-grekasnicolas-grekas added this to the4.1 milestoneDec 8, 2017
* @param int|null $loadOptions A bit field of LIBXML_* constants
*/
publicfunction__construct(string$rootNodeName ='response',int$loadOptions =null)
publicfunction__construct(string$rootNodeName ='response',int$loadOptions =null/*, bool $alwaysCollection = false */)

Choose a reason for hiding this comment

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

args can be appended to constructors, no need for the "BC layer"


if (1 ===count($value) &&key($value)) {
$data[key($value)] =current($value);

Choose a reason for hiding this comment

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

?

}

/**
* @group collection

Choose a reason for hiding this comment

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

why adding this?

$source = <<<'XML'
<?xml version="1.0"?>
<order_rows nodeType="order_row" virtualEntity="true">
<order_row>

Choose a reason for hiding this comment

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

indentation is strange, is it normal?

);

$this->assertEquals($expected,$this->encoder->decode($source,'xml'));
}

Choose a reason for hiding this comment

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

missing blank line after

Simperfit reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

added

@SimperfitSimperfitforce-pushed thefeature/add-a-constructor-arguement-to-return-xml-alsways-as-collection branch 2 times, most recently from8dab446 to658fb0eCompareDecember 9, 2017 08:00
@Simperfit
Copy link
ContributorAuthor

AppVeyor failure is not related.

@Simperfit
Copy link
ContributorAuthor

Status: Needs Review

@SimperfitSimperfitforce-pushed thefeature/add-a-constructor-arguement-to-return-xml-alsways-as-collection branch from658fb0e toa582455CompareDecember 14, 2017 07:11
* @param int|null $loadOptions A bit field of LIBXML_* constants
*/
publicfunction__construct(string$rootNodeName ='response',int$loadOptions =null)
publicfunction__construct(string$rootNodeName ='response',int$loadOptions =null,bool$alwaysCollection =false)
Copy link
Member

Choose a reason for hiding this comment

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

$forceCollection?

@SimperfitSimperfitforce-pushed thefeature/add-a-constructor-arguement-to-return-xml-alsways-as-collection branch froma582455 to6f749bcCompareJanuary 5, 2018 12:07
@dunglas
Copy link
Member

@Simperfit can you rebase to force the CI to run again?

@SimperfitSimperfitforce-pushed thefeature/add-a-constructor-arguement-to-return-xml-alsways-as-collection branch from6f749bc to7a3d918CompareJanuary 11, 2018 11:14
@Simperfit
Copy link
ContributorAuthor

done@dunglas

@Simperfit
Copy link
ContributorAuthor

This is ready to be merged.


foreach ($valueas$key =>$val) {
if (is_array($val) &&1 ===count($val)) {
if (is_array($val) &&1 ===count($val) && (!$this->forceCollection || !is_array($val[0]))) {
Copy link
Member

Choose a reason for hiding this comment

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

After a second thought, wouldn't it be better to allow to change this behavior through the context instead of forcing to register a new instance of the class?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I think it will be easier to use if we don't create a new instance. Ill do the modification on both PRs

@SimperfitSimperfitforce-pushed thefeature/add-a-constructor-arguement-to-return-xml-alsways-as-collection branch 2 times, most recently from89a4381 tof1daa3fCompareFebruary 2, 2018 11:08
@Simperfit
Copy link
ContributorAuthor

@dunglas it now use a context key.


foreach ($valueas$key =>$val) {
if (is_array($val) &&1 ===count($val)) {
if (is_array($val) &&1 ===count($val) && (!(isset($context['forceCollection']) &&$context['forceCollection']) || !is_array($val[0]))) {

Choose a reason for hiding this comment

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

should use snake_case also I suppose

$value[$subnode->nodeName][] =$val;
}
}

Choose a reason for hiding this comment

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

let's keep this line :)

@SimperfitSimperfitforce-pushed thefeature/add-a-constructor-arguement-to-return-xml-alsways-as-collection branch 2 times, most recently from8f3a88d tob0daf42CompareFebruary 5, 2018 09:08
@Simperfit
Copy link
ContributorAuthor

done@nicolas-grekas

@SimperfitSimperfitforce-pushed thefeature/add-a-constructor-arguement-to-return-xml-alsways-as-collection branch fromb0daf42 to7c8709eCompareFebruary 5, 2018 09:10
*
* @param string $rootNodeName
* @param int|null $loadOptions A bit field of LIBXML_* constants
* @param int|null $loadOptions A bit field of LIBXML_* constants

Choose a reason for hiding this comment

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

let's revert this: it's unrelated, and breaks merges


foreach ($valueas$key =>$val) {
if (is_array($val) &&1 ===count($val)) {
if (is_array($val) &&1 ===count($val) && (!(isset($context['as_collection']) &&$context['as_collection']) || !is_array($val[0]))) {

Choose a reason for hiding this comment

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

usingempty() would make the code simpler I suppose
I don't understand the last condition!is_array($val[0]) - it feels unrelated. Is it?

Copy link
ContributorAuthor

@SimperfitSimperfitFeb 16, 2018
edited
Loading

Choose a reason for hiding this comment

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

I just looked after it and!is_array($val[0]) makes it possible to return the value directly instead of having two arrays:

$expected = array(            '@nodeType' => 'order_row',            '@virtualEntity' => 'true',            'order_row' => array(array(                'id' => 16,                'test' => 16,            )),        );

vs

$expected = array(            '@nodeType' => 'order_row',            '@virtualEntity' => 'true',            'order_row' => array(array(                'id' => array(16),                'test' => array(16),            )),        );

Do you mean replacing

is_array($val) && 1 === count($val)

to

!empty($val)

it's not possible

@SimperfitSimperfitforce-pushed thefeature/add-a-constructor-arguement-to-return-xml-alsways-as-collection branch from7c8709e to5319a86CompareFebruary 16, 2018 08:54
@SimperfitSimperfitforce-pushed thefeature/add-a-constructor-arguement-to-return-xml-alsways-as-collection branch from5319a86 toadb428dCompareFebruary 16, 2018 09:06
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.

Please update the main description so that people looking at this PR can understand what's going on here.
Please also check if a doc PR should be done.

@SimperfitSimperfit changed the title[Serializer] add a contruct key to return always as collection for XmlEncoder[Serializer] add a context key to return always as collection for XmlEncoderFeb 19, 2018
@Simperfit
Copy link
ContributorAuthor

@nicolas-grekas done.

@dunglas
Copy link
Member

Thank you@Simperfit.

@dunglasdunglas merged commitadb428d intosymfony:masterFeb 19, 2018
dunglas added a commit that referenced this pull requestFeb 19, 2018
…lection for XmlEncoder (Simperfit)This PR was merged into the 4.1-dev branch.Discussion----------[Serializer] add a context key to return always as collection for XmlEncoder| Q             | A| ------------- | ---| Branch?       | 4.1| Bug fix?      | no| New feature?  | yes| BC breaks?    | no| Deprecations? | no <!-- don't forget to update UPGRADE-*.md files -->| Tests pass?   | yes| Fixed tickets |#25227| License       | MIT| Doc PR        |This PR add a new `as_collection` context key in order to return always as a collection instead of returning a single elements when there are only one array.there are only one PR for the CsvEncoder don't wanted to have only One PR containing the two changes. It feel better to have two PR that fix the behaviour on two different things. it's easy to review and to revert if it break something (which should not since we are testing the behaviour).Commits-------adb428d [Serializer] add a context key to return always as collection for XmlEncoder
@fabpotfabpot mentioned this pull requestMay 7, 2018
fabpot added a commit that referenced this pull requestJun 30, 2018
…default value (ogizanagi)This PR was merged into the 4.2-dev branch.Discussion----------[Serializer] Deprecate CsvEncoder as_collection false default value| Q             | A| ------------- | ---| Branch?       | master <!-- see below -->| Bug fix?      | no| New feature?  | no <!-- don't forget to update src/**/CHANGELOG.md files -->| BC breaks?    | no     <!-- seehttps://symfony.com/bc -->| Deprecations? | yes <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files -->| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->| Fixed tickets | N/A   <!-- #-prefixed issue number(s), if any -->| License       | MIT| Doc PR        | N/AAs already expressed in#25369 and related issues, this behavior is quite counter-intuitive. It may be fine for write-API with a single document in the body but I think such CSV APIs are way less common than file-based ones, expecting collections. So I think this behavior should be opt-in explicitly in required cases, always dealing with collections by default.This is still an arbitrary decision, but trying to make it based on use-cases and user's experience with CSV.Note: perhaps we could find a better name for this as the semantic of setting `as_collection` to `false` to get the single row directly would not be really obvious.Also, it could throw an exception when getting multiple rows where only one was expected.Commits-------bce59c8 [Serializer] Deprecate CsvEncoder as_collection false default value
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot left review comments

@dunglasdunglasdunglas approved these changes

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

Assignees

No one assigned

Projects

None yet

Milestone

4.1

Development

Successfully merging this pull request may close these issues.

6 participants

@Simperfit@dunglas@fabpot@nicolas-grekas@javiereguiluz@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp