@@ -33,10 +33,6 @@ public function __construct(WritableStreamInterface $output, $delimiter = ',', $
3333 throw new \BadMethodCallException ('Custom escape character only supported on PHP 5.5.4+ ' ); // @codeCoverageIgnore
3434 }
3535
36- if ($ eol !== "\n" && PHP_VERSION_ID < 80100 ) {
37- throw new \BadMethodCallException ('Custom EOL character only supported on PHP 8.1+ ' ); // @codeCoverageIgnore
38- }
39-
4036 $ this ->output = $ output ;
4137 $ this ->delimiter = $ delimiter ;
4238 $ this ->enclosure = $ enclosure ;
@@ -63,14 +59,14 @@ public function write($data)
6359
6460 $ written = false ;
6561 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)
6763 // @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 ) {
7167 $ written = fputcsv ($ this ->temp , $ data , $ this ->delimiter , $ this ->enclosure , $ this ->escapeChar );
7268 } 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 );
7470 }
7571 // @codeCoverageIgnoreEnd
7672 }
@@ -84,6 +80,11 @@ public function write($data)
8480 $ data = stream_get_contents ($ this ->temp );
8581 ftruncate ($ this ->temp , 0 );
8682
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+
8788 return $ this ->output ->write ($ data );
8889 }
8990
0 commit comments