Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

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

Merged
merged 1 commit into from
Jan 1, 2019
Merged

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

merged 1 commit into from
Jan 1, 2019

Conversation

redecs
Copy link
Contributor

@redecs redecs 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
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

here are some minor comments.

@diimpp
Copy link
Member

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

redecs commented Dec 17, 2018

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

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

That's a new feature, thus for master.

@fabpot
Copy link
Member

fabpot commented Jan 1, 2019

Thank you @redecs.

@fabpot fabpot merged commit 0e63c61 into symfony:master Jan 1, 2019
fabpot added a commit that referenced this pull request Jan 1, 2019
…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 mentioned this pull request May 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants