1010final class MultipleFilesLoader implements StepBuilderInterface
1111{
1212 private ?Node \Expr $ logger ;
13- private bool $ withoutEnclosure ;
1413
1514 public function __construct (
16- private ? Node \Expr $ filePath ,
17- private ? Node \Expr $ maxLines ,
15+ private Node \Expr $ filePath ,
16+ private Node \Expr $ maxLines ,
1817 private ?Node \Expr $ delimiter = null ,
1918 private ?Node \Expr $ enclosure = null ,
2019 private ?Node \Expr $ escape = null ,
2120 private ?Node \Expr $ columns = null ,
2221 private bool $ safeMode = true ,
22+ private bool $ withNonStandard = false ,
2323 ) {
2424 $ this ->logger = null ;
25- $ this ->withoutEnclosure = false ;
2625 }
2726
2827 public function withFilePath (Node \Expr $ filePath ): self
@@ -91,9 +90,9 @@ public function withSafeMode(): self
9190 return $ this ;
9291 }
9392
94- public function withoutEnclosure (): self
93+ public function withNonStandard (): self
9594 {
96- $ this ->safeMode = true ;
95+ $ this ->withNonStandard = true ;
9796
9897 return $ this ;
9998 }
@@ -110,7 +109,77 @@ public function getNode(): Node
110109 $ arguments = [
111110 new Node \Arg (
112111 value: new Node \Expr \New_ (
113- class: $ this ->withoutEnclosure ? new Node \Name \FullyQualified ('GyroscopsGenerated \\SplFileObject ' ) : new Node \Name \FullyQualified ('SplFileObject ' ),
112+ class: $ this ->withNonStandard ? new Node \Stmt \Class_ (
113+ name: 'SplFileObject ' ,
114+ subNodes: [
115+ 'extends ' => new Node \Name \FullyQualified ('SplFileObject ' ),
116+ 'stmts ' => [
117+ new Node \Stmt \Function_ (
118+ name: 'fputcsv ' ,
119+ subNodes: [
120+ 'params ' => [
121+ new Node \Param (
122+ var: new Node \Expr \Variable ('fields ' ),
123+ type: 'array ' ,
124+ ),
125+ new Node \Param (
126+ var: new Node \Expr \Variable ('separator ' ),
127+ default: new Node \Scalar \String_ (', ' ),
128+ type: 'string ' ,
129+ ),
130+ new Node \Param (
131+ var: new Node \Expr \Variable ('enclosure ' ),
132+ default: new Node \Scalar \String_ ('" ' ),
133+ type: 'string ' ,
134+ ),
135+ new Node \Param (
136+ var: new Node \Expr \Variable ('escape ' ),
137+ default: new Node \Scalar \String_ ('\\' ),
138+ type: 'string ' ,
139+ ),
140+ new Node \Param (
141+ var: new Node \Expr \Variable ('eol ' ),
142+ default: new Node \Expr \ConstFetch (new Node \Name ('PHP_EOL ' )),
143+ type: 'string ' ,
144+ ),
145+ ],
146+ 'returnType ' => new Node \UnionType (
147+ types: [
148+ new Node \Name ('int ' ),
149+ new Node \Name ('false ' ),
150+ ],
151+ ),
152+ 'stmts ' => [
153+ new Node \Stmt \Return_ (
154+ expr: new Node \Expr \MethodCall (
155+ var: new Node \Expr \Variable ('this ' ),
156+ name: 'fwrite ' ,
157+ args: [
158+ new Node \Arg (
159+ value: new Node \Expr \BinaryOp \Concat (
160+ left: new Node \Expr \FuncCall (
161+ name: new Node \Name ('implode ' ),
162+ args: [
163+ new Node \Arg (
164+ value: new Node \Expr \Variable ('separator ' )
165+ ),
166+ new Node \Arg (
167+ value: new Node \Expr \Variable ('fields ' )
168+ ),
169+ ],
170+ ),
171+ right: new Node \Expr \Variable ('eol ' )
172+ ),
173+ ),
174+ ],
175+ ),
176+ ),
177+ ],
178+ ],
179+ ),
180+ ],
181+ ],
182+ ) : new Node \Name \FullyQualified ('SplFileObject ' ),
114183 args: [
115184 new Node \Arg (
116185 value: $ this ->filePath
0 commit comments