From b600aa07523f2214d259175d7c1a2e39d584f239 Mon Sep 17 00:00:00 2001 From: Maciej Malarz Date: Thu, 10 Oct 2019 21:32:03 +0200 Subject: [PATCH] List CSV encoder's context options --- components/serializer.rst | 54 ++++++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 7 deletions(-) diff --git a/components/serializer.rst b/components/serializer.rst index 94c1ca0d5b1..fd44a459530 100644 --- a/components/serializer.rst +++ b/components/serializer.rst @@ -810,13 +810,6 @@ The ``CsvEncoder`` The ``CsvEncoder`` encodes to and decodes from CSV. -You can pass the context key ``as_collection`` in order to have the results -always as a collection. - -.. deprecated:: 4.2 - - Relying on the default value ``false`` is deprecated since Symfony 4.2. - The ``XmlEncoder`` ~~~~~~~~~~~~~~~~~~ @@ -1254,6 +1247,52 @@ These are the options available: ``remove_empty_tags`` If set to true, removes all empty tags in the generated XML. +The ``CsvEncoder`` +------------------ + +This encoder transforms arrays into CSV and vice versa. + +Context +~~~~~~~ + +The ``encode()`` method defines a third optional parameter called ``context`` +which defines the configuration options for the CsvEncoder an associative array:: + + $csvEncoder->encode($array, 'csv', $context); + +These are the options available: + +``csv_delimiter`` + Sets the field delimiter separating values (one character only, default: ``,``). + +``csv_enclosure`` + Sets the field enclosure (one character only, default: ``"``). + +``csv_escape_char`` + Sets the escape character (at most one character, default: empty string). + +``csv_key_separator`` + Sets the separator for array's keys during its flattening (default: ``.``). + +``csv_headers`` + Sets the headers for the data (default: ``[]``, inferred from input data's keys). + +``csv_escape_formulas`` + Escapes fields containg formulas by prepending them with a ``\t`` character (default: ``false``). + +``as_collection`` + Always returns results as a collection, even if only one line is decoded (default: ``false``). + +.. deprecated:: 4.2 + + Relying on the default value ``false`` is deprecated since Symfony 4.2. + +``no_headers`` + Disables header in the encoded CSV (default: ``false``). + +``output_utf8_bom`` + Outputs special `UTF-8 BOM`_ along with encoded data (default: ``false``). + Handling Constructor Arguments ------------------------------ @@ -1506,6 +1545,7 @@ Learn more .. _YAML: http://yaml.org/ .. _CSV: https://tools.ietf.org/html/rfc4180 .. _`RFC 7807`: https://tools.ietf.org/html/rfc7807 +.. _`UTF-8 BOM`: https://en.wikipedia.org/wiki/Byte_order_mark .. _`Value Objects`: https://en.wikipedia.org/wiki/Value_object .. _`API Platform`: https://api-platform.com .. _`list of PHP timezones`: https://www.php.net/manual/en/timezones.php pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy