@@ -25,10 +25,6 @@ class CsvEncoder implements EncoderInterface, DecoderInterface
2525 public const FORMAT = 'csv ' ;
2626 public const DELIMITER_KEY = 'csv_delimiter ' ;
2727 public const ENCLOSURE_KEY = 'csv_enclosure ' ;
28- /**
29- * @deprecated since Symfony 7.2, to be removed in 8.0
30- */
31- public const ESCAPE_CHAR_KEY = 'csv_escape_char ' ;
3228 public const KEY_SEPARATOR_KEY = 'csv_key_separator ' ;
3329 public const HEADERS_KEY = 'csv_headers ' ;
3430 public const ESCAPE_FORMULAS_KEY = 'csv_escape_formulas ' ;
@@ -44,7 +40,6 @@ class CsvEncoder implements EncoderInterface, DecoderInterface
4440 private array $ defaultContext = [
4541 self ::DELIMITER_KEY => ', ' ,
4642 self ::ENCLOSURE_KEY => '" ' ,
47- self ::ESCAPE_CHAR_KEY => '' ,
4843 self ::END_OF_LINE => "\n" ,
4944 self ::ESCAPE_FORMULAS_KEY => false ,
5045 self ::HEADERS_KEY => [],
@@ -56,10 +51,6 @@ class CsvEncoder implements EncoderInterface, DecoderInterface
5651
5752 public function __construct (array $ defaultContext = [])
5853 {
59- if (\array_key_exists (self ::ESCAPE_CHAR_KEY , $ defaultContext )) {
60- trigger_deprecation ('symfony/serializer ' , '7.2 ' , 'Setting the "csv_escape_char" option is deprecated. The option will be removed in 8.0. ' );
61- }
62-
6354 $ this ->defaultContext = array_merge ($ this ->defaultContext , $ defaultContext );
6455 }
6556
@@ -88,7 +79,7 @@ public function encode(mixed $data, string $format, array $context = []): string
8879 }
8980 }
9081
91- [$ delimiter , $ enclosure , $ escapeChar , $ keySeparator , $ headers , $ escapeFormulas , $ outputBom ] = $ this ->getCsvOptions ($ context );
82+ [$ delimiter , $ enclosure , $ keySeparator , $ headers , $ escapeFormulas , $ outputBom ] = $ this ->getCsvOptions ($ context );
9283
9384 foreach ($ data as &$ value ) {
9485 $ flattened = [];
@@ -101,15 +92,15 @@ public function encode(mixed $data, string $format, array $context = []): string
10192 $ endOfLine = $ context [self ::END_OF_LINE ] ?? $ this ->defaultContext [self ::END_OF_LINE ];
10293
10394 if (!($ context [self ::NO_HEADERS_KEY ] ?? $ this ->defaultContext [self ::NO_HEADERS_KEY ])) {
104- fputcsv ($ handle , $ headers , $ delimiter , $ enclosure, $ escapeChar );
95+ fputcsv ($ handle , $ headers , $ delimiter , $ enclosure );
10596 if ("\n" !== $ endOfLine && 0 === fseek ($ handle , -1 , \SEEK_CUR )) {
10697 fwrite ($ handle , $ endOfLine );
10798 }
10899 }
109100
110101 $ headers = array_fill_keys ($ headers , '' );
111102 foreach ($ data as $ row ) {
112- fputcsv ($ handle , array_replace ($ headers , $ row ), $ delimiter , $ enclosure, $ escapeChar );
103+ fputcsv ($ handle , array_replace ($ headers , $ row ), $ delimiter , $ enclosure );
113104 if ("\n" !== $ endOfLine && 0 === fseek ($ handle , -1 , \SEEK_CUR )) {
114105 fwrite ($ handle , $ endOfLine );
115106 }
@@ -150,9 +141,9 @@ public function decode(string $data, string $format, array $context = []): mixed
150141 $ headerCount = [];
151142 $ result = [];
152143
153- [$ delimiter , $ enclosure , $ escapeChar , $ keySeparator , , , , $ asCollection ] = $ this ->getCsvOptions ($ context );
144+ [$ delimiter , $ enclosure , $ keySeparator , , , , $ asCollection ] = $ this ->getCsvOptions ($ context );
154145
155- while (false !== ($ cols = fgetcsv ($ handle , 0 , $ delimiter , $ enclosure, $ escapeChar ))) {
146+ while (false !== ($ cols = fgetcsv ($ handle , 0 , $ delimiter , $ enclosure ))) {
156147 $ nbCols = \count ($ cols );
157148
158149 if (null === $ headers ) {
@@ -244,7 +235,6 @@ private function getCsvOptions(array $context): array
244235 {
245236 $ delimiter = $ context [self ::DELIMITER_KEY ] ?? $ this ->defaultContext [self ::DELIMITER_KEY ];
246237 $ enclosure = $ context [self ::ENCLOSURE_KEY ] ?? $ this ->defaultContext [self ::ENCLOSURE_KEY ];
247- $ escapeChar = $ context [self ::ESCAPE_CHAR_KEY ] ?? $ this ->defaultContext [self ::ESCAPE_CHAR_KEY ];
248238 $ keySeparator = $ context [self ::KEY_SEPARATOR_KEY ] ?? $ this ->defaultContext [self ::KEY_SEPARATOR_KEY ];
249239 $ headers = $ context [self ::HEADERS_KEY ] ?? $ this ->defaultContext [self ::HEADERS_KEY ];
250240 $ escapeFormulas = $ context [self ::ESCAPE_FORMULAS_KEY ] ?? $ this ->defaultContext [self ::ESCAPE_FORMULAS_KEY ];
@@ -255,7 +245,7 @@ private function getCsvOptions(array $context): array
255245 throw new InvalidArgumentException (\sprintf ('The "%s" context variable must be an array or null, given "%s". ' , self ::HEADERS_KEY , get_debug_type ($ headers )));
256246 }
257247
258- return [$ delimiter , $ enclosure , $ escapeChar , $ keySeparator , $ headers , $ escapeFormulas , $ outputBom , $ asCollection ];
248+ return [$ delimiter , $ enclosure , $ keySeparator , $ headers , $ escapeFormulas , $ outputBom , $ asCollection ];
259249 }
260250
261251 /**
0 commit comments