Skip to content
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

[Serializer] CsvEncoder no header option (encode / decode) #29283

Merged
merged 1 commit into from Jan 1, 2019

Conversation

Projects
None yet
5 participants
@redecs
Copy link
Contributor

commented Nov 22, 2018

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

This PR wants to introduce a new context option for the CsvEncoder, CsvEncoder::NO_HEADERS_KEY (boolean), that allows CSV encoding/decoding when you don't have/need a header.

By default this is assumed to be false, so the headers are included in the CSV output or assumed to be present in the CSV input.

When the option is set to true, the following behaviour occurs.

Encoding

The following PHP input

array(array('a','b'), array('c', 'd'))

will generate this CSV output

a,b
c,d

Decoding

Considering the CSV input to be

a,b
c,d

the following PHP array will be returned

array (
  0 => array (
    0 => 'a',
    1 => 'b',
  ),
  1 => array (
    0 => 'c',
    1 => 'd',
  ),
)

@nicolas-grekas nicolas-grekas added this to the next milestone Nov 22, 2018

@redecs redecs changed the title csv encoder no header option (encode / decode) [Serializer] CsvEncoder no header option (encode / decode) Nov 26, 2018

@nicolas-grekas
Copy link
Member

left a comment

here are some minor comments.

@diimpp

This comment has been minimized.

Copy link

commented Dec 16, 2018

@redecs thank you for submitting PR. Do you plan to fix styling issue from review? I would like to see this feature in a core, please let me know, if I should fix it on your behalf.

@redecs redecs force-pushed the redecs:issue_27447 branch from 7eb2dbc to 7e938fd Dec 17, 2018

@redecs

This comment has been minimized.

Copy link
Contributor Author

commented Dec 17, 2018

@diimpp Just pushed the CS fixes.
@nicolas-grekas any chance this will get "backported" to 3.4?

@nicolas-grekas
Copy link
Member

left a comment

That's a new feature, thus for master.

@fabpot fabpot force-pushed the redecs:issue_27447 branch from 7e938fd to 0e63c61 Jan 1, 2019

@fabpot

This comment has been minimized.

Copy link
Member

commented Jan 1, 2019

Thank you @redecs.

@fabpot fabpot merged commit 0e63c61 into symfony:master Jan 1, 2019

1 of 3 checks passed

continuous-integration/appveyor/pr Waiting for AppVeyor build to complete
Details
continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
fabbot.io Your code looks good.
Details

fabpot added a commit that referenced this pull request Jan 1, 2019

feature #29283 [Serializer] CsvEncoder no header option (encode / dec…
…ode) (redecs)

This PR was squashed before being merged into the 4.3-dev branch (closes #29283).

Discussion
----------

[Serializer] CsvEncoder no header option (encode / decode)

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

This PR wants to introduce a new context option for the CsvEncoder, `CsvEncoder::NO_HEADERS_KEY` (boolean), that allows CSV encoding/decoding when you don't have/need a header.

By default this is assumed to be false, so the headers are included in the CSV output or assumed to be present in the CSV input.

When the option is set to true, the following behaviour occurs.

Encoding
===
The following PHP input
```php
array(array('a','b'), array('c', 'd'))
```
will generate this CSV output
```csv
a,b
c,d
```

Decoding
===
Considering the CSV input to be
```csv
a,b
c,d
```
the following PHP array will be returned
```php
array (
  0 => array (
    0 => 'a',
    1 => 'b',
  ),
  1 => array (
    0 => 'c',
    1 => 'd',
  ),
)
```

Commits
-------

0e63c61 [Serializer] CsvEncoder no header option (encode / decode)

@nicolas-grekas nicolas-grekas modified the milestones: next, 4.3 Apr 30, 2019

@fabpot fabpot referenced this pull request May 9, 2019

Merged

Release v4.3.0-BETA1 #31435

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.