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

Commit367b05b

Browse files
committed
feature#12461 List CSV encoder's context options (malarzm)
This PR was merged into the 4.4 branch.Discussion----------List CSV encoder's context optionsI needed to add new option `output_utf8_bom` introduced insymfony/symfony#33896 and since context options weren't documented I figured I'll list them all. Format and text is based on XML's part of the docs.Commits-------b600aa0 List CSV encoder's context options
2 parentsc43d73b +b600aa0 commit367b05b

File tree

1 file changed

+47
-7
lines changed

1 file changed

+47
-7
lines changed

‎components/serializer.rst‎

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -817,13 +817,6 @@ The ``CsvEncoder``
817817

818818
The ``CsvEncoder`` encodes to and decodes from CSV.
819819

820-
You can pass the context key ``as_collection`` in order to have the results
821-
always as a collection.
822-
823-
..deprecated::4.2
824-
825-
Relying on the default value ``false`` is deprecated since Symfony 4.2.
826-
827820
The ``XmlEncoder``
828821
~~~~~~~~~~~~~~~~~~
829822

@@ -1260,6 +1253,52 @@ These are the options available:
12601253
``remove_empty_tags``
12611254
If set to true, removes all empty tags in the generated XML (default: ``false``).
12621255

1256+
The ``CsvEncoder``
1257+
------------------
1258+
1259+
This encoder transforms arrays into CSV and vice versa.
1260+
1261+
Context
1262+
~~~~~~~
1263+
1264+
The ``encode()`` method defines a third optional parameter called ``context``
1265+
which defines the configuration options for the CsvEncoder an associative array::
1266+
1267+
$csvEncoder->encode($array, 'csv', $context);
1268+
1269+
These are the options available:
1270+
1271+
``csv_delimiter``
1272+
Sets the field delimiter separating values (one character only, default: ``,``).
1273+
1274+
``csv_enclosure``
1275+
Sets the field enclosure (one character only, default: ``"``).
1276+
1277+
``csv_escape_char``
1278+
Sets the escape character (at most one character, default: empty string).
1279+
1280+
``csv_key_separator``
1281+
Sets the separator for array's keys during its flattening (default: ``.``).
1282+
1283+
``csv_headers``
1284+
Sets the headers for the data (default: ``[]``, inferred from input data's keys).
1285+
1286+
``csv_escape_formulas``
1287+
Escapes fields containg formulas by prepending them with a ``\t`` character (default: ``false``).
1288+
1289+
``as_collection``
1290+
Always returns results as a collection, even if only one line is decoded (default: ``false``).
1291+
1292+
..deprecated::4.2
1293+
1294+
Relying on the default value ``false`` is deprecated since Symfony 4.2.
1295+
1296+
``no_headers``
1297+
Disables header in the encoded CSV (default: ``false``).
1298+
1299+
``output_utf8_bom``
1300+
Outputs special `UTF-8 BOM`_ along with encoded data (default: ``false``).
1301+
12631302
Handling Constructor Arguments
12641303
------------------------------
12651304

@@ -1514,6 +1553,7 @@ Learn more
15141553
.. _YAML:https://yaml.org/
15151554
.. _CSV:https://tools.ietf.org/html/rfc4180
15161555
.. _`RFC 7807`:https://tools.ietf.org/html/rfc7807
1556+
.. _`UTF-8 BOM`:https://en.wikipedia.org/wiki/Byte_order_mark
15171557
.. _`Value Objects`:https://en.wikipedia.org/wiki/Value_object
15181558
.. _`API Platform`:https://api-platform.com
15191559
.. _`list of PHP timezones`:https://www.php.net/manual/en/timezones.php

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp