@@ -16,8 +16,9 @@ public function __construct(
1616 public bool $ trailing = false ,
1717 public array $ formatOptions = [],
1818 public ?string $ when = null ,
19- ) {
20- }
19+ public bool $ csv = false ,
20+ public bool $ withEmbedded = true ,
21+ ) {}
2122
2223 public function __toString (): string
2324 {
@@ -27,13 +28,7 @@ public function __toString(): string
2728 $ sql .= "WHEN {$ this ->when }" .PHP_EOL ;
2829 }
2930
30- if ($ this ->terminatedBy ) {
31- $ sql .= "FIELDS TERMINATED BY ' {$ this ->terminatedBy }' " ;
32- }
33-
34- if ($ this ->enclosedBy ) {
35- $ sql .= "OPTIONALLY ENCLOSED BY ' {$ this ->enclosedBy }' " .PHP_EOL ;
36- }
31+ $ sql .= $ this ->delimiterSpecification ();
3732
3833 if ($ this ->formatOptions ) {
3934 $ sql .= implode (PHP_EOL , $ this ->formatOptions ).PHP_EOL ;
@@ -54,4 +49,28 @@ public function __toString(): string
5449
5550 return $ sql ;
5651 }
52+
53+ private function delimiterSpecification (): string
54+ {
55+ $ specs = ['FIELDS ' ];
56+
57+ if ($ this ->csv ) {
58+ $ specs [] = 'CSV ' ;
59+ $ specs [] = $ this ->withEmbedded ? 'WITH EMBEDDED ' : 'WITHOUT EMBEDDED ' ;
60+ }
61+
62+ if ($ this ->terminatedBy ) {
63+ $ specs [] = "TERMINATED BY ' {$ this ->terminatedBy }' " ;
64+ }
65+
66+ if ($ this ->enclosedBy ) {
67+ $ specs [] = "OPTIONALLY ENCLOSED BY ' {$ this ->enclosedBy }' " ;
68+ }
69+
70+ if (count ($ specs ) > 1 ) {
71+ return implode (' ' , $ specs ).PHP_EOL ;
72+ }
73+
74+ return '' ;
75+ }
5776}
0 commit comments