@@ -25,10 +25,6 @@ class CsvEncoder implements EncoderInterface, DecoderInterface
25
25
public const FORMAT = 'csv ' ;
26
26
public const DELIMITER_KEY = 'csv_delimiter ' ;
27
27
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 ' ;
32
28
public const KEY_SEPARATOR_KEY = 'csv_key_separator ' ;
33
29
public const HEADERS_KEY = 'csv_headers ' ;
34
30
public const ESCAPE_FORMULAS_KEY = 'csv_escape_formulas ' ;
@@ -44,7 +40,6 @@ class CsvEncoder implements EncoderInterface, DecoderInterface
44
40
private array $ defaultContext = [
45
41
self ::DELIMITER_KEY => ', ' ,
46
42
self ::ENCLOSURE_KEY => '" ' ,
47
- self ::ESCAPE_CHAR_KEY => '' ,
48
43
self ::END_OF_LINE => "\n" ,
49
44
self ::ESCAPE_FORMULAS_KEY => false ,
50
45
self ::HEADERS_KEY => [],
@@ -56,10 +51,6 @@ class CsvEncoder implements EncoderInterface, DecoderInterface
56
51
57
52
public function __construct (array $ defaultContext = [])
58
53
{
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
-
63
54
$ this ->defaultContext = array_merge ($ this ->defaultContext , $ defaultContext );
64
55
}
65
56
@@ -88,7 +79,7 @@ public function encode(mixed $data, string $format, array $context = []): string
88
79
}
89
80
}
90
81
91
- [$ delimiter , $ enclosure , $ escapeChar , $ keySeparator , $ headers , $ escapeFormulas , $ outputBom ] = $ this ->getCsvOptions ($ context );
82
+ [$ delimiter , $ enclosure , $ keySeparator , $ headers , $ escapeFormulas , $ outputBom ] = $ this ->getCsvOptions ($ context );
92
83
93
84
foreach ($ data as &$ value ) {
94
85
$ flattened = [];
@@ -101,15 +92,15 @@ public function encode(mixed $data, string $format, array $context = []): string
101
92
$ endOfLine = $ context [self ::END_OF_LINE ] ?? $ this ->defaultContext [self ::END_OF_LINE ];
102
93
103
94
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 );
105
96
if ("\n" !== $ endOfLine && 0 === fseek ($ handle , -1 , \SEEK_CUR )) {
106
97
fwrite ($ handle , $ endOfLine );
107
98
}
108
99
}
109
100
110
101
$ headers = array_fill_keys ($ headers , '' );
111
102
foreach ($ data as $ row ) {
112
- fputcsv ($ handle , array_replace ($ headers , $ row ), $ delimiter , $ enclosure, $ escapeChar );
103
+ fputcsv ($ handle , array_replace ($ headers , $ row ), $ delimiter , $ enclosure );
113
104
if ("\n" !== $ endOfLine && 0 === fseek ($ handle , -1 , \SEEK_CUR )) {
114
105
fwrite ($ handle , $ endOfLine );
115
106
}
@@ -150,9 +141,9 @@ public function decode(string $data, string $format, array $context = []): mixed
150
141
$ headerCount = [];
151
142
$ result = [];
152
143
153
- [$ delimiter , $ enclosure , $ escapeChar , $ keySeparator , , , , $ asCollection ] = $ this ->getCsvOptions ($ context );
144
+ [$ delimiter , $ enclosure , $ keySeparator , , , , $ asCollection ] = $ this ->getCsvOptions ($ context );
154
145
155
- while (false !== ($ cols = fgetcsv ($ handle , 0 , $ delimiter , $ enclosure, $ escapeChar ))) {
146
+ while (false !== ($ cols = fgetcsv ($ handle , 0 , $ delimiter , $ enclosure ))) {
156
147
$ nbCols = \count ($ cols );
157
148
158
149
if (null === $ headers ) {
@@ -244,7 +235,6 @@ private function getCsvOptions(array $context): array
244
235
{
245
236
$ delimiter = $ context [self ::DELIMITER_KEY ] ?? $ this ->defaultContext [self ::DELIMITER_KEY ];
246
237
$ enclosure = $ context [self ::ENCLOSURE_KEY ] ?? $ this ->defaultContext [self ::ENCLOSURE_KEY ];
247
- $ escapeChar = $ context [self ::ESCAPE_CHAR_KEY ] ?? $ this ->defaultContext [self ::ESCAPE_CHAR_KEY ];
248
238
$ keySeparator = $ context [self ::KEY_SEPARATOR_KEY ] ?? $ this ->defaultContext [self ::KEY_SEPARATOR_KEY ];
249
239
$ headers = $ context [self ::HEADERS_KEY ] ?? $ this ->defaultContext [self ::HEADERS_KEY ];
250
240
$ escapeFormulas = $ context [self ::ESCAPE_FORMULAS_KEY ] ?? $ this ->defaultContext [self ::ESCAPE_FORMULAS_KEY ];
@@ -255,7 +245,7 @@ private function getCsvOptions(array $context): array
255
245
throw new InvalidArgumentException (\sprintf ('The "%s" context variable must be an array or null, given "%s". ' , self ::HEADERS_KEY , get_debug_type ($ headers )));
256
246
}
257
247
258
- return [$ delimiter , $ enclosure , $ escapeChar , $ keySeparator , $ headers , $ escapeFormulas , $ outputBom , $ asCollection ];
248
+ return [$ delimiter , $ enclosure , $ keySeparator , $ headers , $ escapeFormulas , $ outputBom , $ asCollection ];
259
249
}
260
250
261
251
/**
0 commit comments