@@ -33,10 +33,6 @@ public function __construct(WritableStreamInterface $output, $delimiter = ',', $
33
33
throw new \BadMethodCallException ('Custom escape character only supported on PHP 5.5.4+ ' ); // @codeCoverageIgnore
34
34
}
35
35
36
- if ($ eol !== "\n" && PHP_VERSION_ID < 80100 ) {
37
- throw new \BadMethodCallException ('Custom EOL character only supported on PHP 8.1+ ' ); // @codeCoverageIgnore
38
- }
39
-
40
36
$ this ->output = $ output ;
41
37
$ this ->delimiter = $ delimiter ;
42
38
$ this ->enclosure = $ enclosure ;
@@ -63,14 +59,14 @@ public function write($data)
63
59
64
60
$ written = false ;
65
61
if (is_array ($ data )) {
66
- // custom escape character requires PHP 5.5.4 +, custom EOL requires PHP 8.1 + (see constructor check)
62
+ // custom EOL requires PHP 8.1 +, custom escape character requires PHP 5.5.4 + (see constructor check)
67
63
// @codeCoverageIgnoreStart
68
- if ($ this -> escapeChar === '\\' && $ this -> eol === "\n" ) {
69
- $ written = fputcsv ($ this ->temp , $ data , $ this ->delimiter , $ this ->enclosure );
70
- } elseif ($ this -> eol === "\n" ) {
64
+ if (\ PHP_VERSION_ID >= 80100 ) {
65
+ $ written = fputcsv ($ this ->temp , $ data , $ this ->delimiter , $ this ->enclosure , $ this -> escapeChar , $ this -> eol );
66
+ } elseif (\ PHP_VERSION_ID >= 50504 ) {
71
67
$ written = fputcsv ($ this ->temp , $ data , $ this ->delimiter , $ this ->enclosure , $ this ->escapeChar );
72
68
} else {
73
- $ written = fputcsv ($ this ->temp , $ data , $ this ->delimiter , $ this ->enclosure , $ this -> escapeChar , $ this -> eol );
69
+ $ written = fputcsv ($ this ->temp , $ data , $ this ->delimiter , $ this ->enclosure );
74
70
}
75
71
// @codeCoverageIgnoreEnd
76
72
}
@@ -84,6 +80,11 @@ public function write($data)
84
80
$ data = stream_get_contents ($ this ->temp );
85
81
ftruncate ($ this ->temp , 0 );
86
82
83
+ // manually replace custom EOL on PHP < 8.1
84
+ if (\PHP_VERSION_ID < 80100 && $ this ->eol !== "\n" ) {
85
+ $ data = \substr ($ data , 0 , -1 ) . $ this ->eol ;
86
+ }
87
+
87
88
return $ this ->output ->write ($ data );
88
89
}
89
90
0 commit comments