@@ -94,19 +94,20 @@ public function encode($data, string $format, array $context = [])
94
94
unset($ value );
95
95
96
96
$ headers = array_merge (array_values ($ headers ), array_diff ($ this ->extractHeaders ($ data ), $ headers ));
97
-
97
+ $ endOfLine = $ context [self ::END_OF_LINE ] ?? $ this ->defaultContext [self ::END_OF_LINE ];
98
+
98
99
if (!($ context [self ::NO_HEADERS_KEY ] ?? $ this ->defaultContext [self ::NO_HEADERS_KEY ])) {
99
100
fputcsv ($ handle , $ headers , $ delimiter , $ enclosure , $ escapeChar );
100
- if ("\n" !== ( $ context [ self :: END_OF_LINE ] ?? $ this -> defaultContext [ self :: END_OF_LINE ]) && 0 === fseek ($ handle , -1 , \SEEK_CUR )) {
101
- fwrite ($ handle , $ context [ self :: END_OF_LINE ] );
101
+ if ("\n" !== $ endOfLine && 0 === fseek ($ handle , -1 , \SEEK_CUR )) {
102
+ fwrite ($ handle , $ endOfLine );
102
103
}
103
104
}
104
105
105
106
$ headers = array_fill_keys ($ headers , '' );
106
107
foreach ($ data as $ row ) {
107
108
fputcsv ($ handle , array_replace ($ headers , $ row ), $ delimiter , $ enclosure , $ escapeChar );
108
- if ("\n" !== ( $ context [ self :: END_OF_LINE ] ?? $ this -> defaultContext [ self :: END_OF_LINE ]) && 0 === fseek ($ handle , -1 , \SEEK_CUR )) {
109
- fwrite ($ handle , $ context [ self :: END_OF_LINE ] );
109
+ if ("\n" !== $ endOfLine && 0 === fseek ($ handle , -1 , \SEEK_CUR )) {
110
+ fwrite ($ handle , $ endOfLine );
110
111
}
111
112
}
112
113
0 commit comments