14
14
namespace Webmozarts \Console \Parallelization ;
15
15
16
16
use Symfony \Component \Console \Input \Input ;
17
- use Symfony \Component \Console \Input \InputDefinition ;
18
17
use Symfony \Component \Console \Input \InputInterface ;
19
18
use Symfony \Component \Console \Output \OutputInterface ;
20
19
use Throwable ;
21
20
use Webmozart \Assert \Assert ;
22
21
use Webmozarts \Console \Parallelization \ErrorHandler \ErrorHandler ;
23
- use Webmozarts \Console \Parallelization \Input \InputOptionsSerializer ;
22
+ use Webmozarts \Console \Parallelization \Input \ChildCommandFactory ;
24
23
use Webmozarts \Console \Parallelization \Input \ParallelizationInput ;
25
24
use Webmozarts \Console \Parallelization \Logger \Logger ;
26
25
use Webmozarts \Console \Parallelization \Process \ProcessLauncher ;
27
26
use Webmozarts \Console \Parallelization \Process \ProcessLauncherFactory ;
28
- use function array_filter ;
29
- use function array_map ;
30
- use function array_merge ;
31
- use function array_slice ;
32
- use function implode ;
33
27
use function mb_strlen ;
34
28
use function sprintf ;
35
29
@@ -50,10 +44,6 @@ final class ParallelExecutor
50
44
*/
51
45
private $ getItemName ;
52
46
53
- private string $ commandName ;
54
-
55
- private InputDefinition $ commandDefinition ;
56
-
57
47
private ErrorHandler $ errorHandler ;
58
48
59
49
/**
@@ -93,9 +83,7 @@ final class ParallelExecutor
93
83
94
84
private string $ progressSymbol ;
95
85
96
- private string $ phpExecutable ;
97
-
98
- private string $ scriptPath ;
86
+ private ChildCommandFactory $ childCommandFactory ;
99
87
100
88
private string $ workingDirectory ;
101
89
@@ -133,8 +121,6 @@ public function __construct(
133
121
callable $ fetchItems ,
134
122
callable $ runSingleCommand ,
135
123
callable $ getItemName ,
136
- string $ commandName ,
137
- InputDefinition $ commandDefinition ,
138
124
ErrorHandler $ errorHandler ,
139
125
$ childSourceStream ,
140
126
int $ batchSize ,
@@ -144,23 +130,19 @@ public function __construct(
144
130
callable $ runBeforeBatch ,
145
131
callable $ runAfterBatch ,
146
132
string $ progressSymbol ,
147
- string $ phpExecutable ,
148
- string $ scriptPath ,
133
+ ChildCommandFactory $ childCommandFactory ,
149
134
string $ workingDirectory ,
150
135
?array $ extraEnvironmentVariables ,
151
136
ProcessLauncherFactory $ processLauncherFactory ,
152
137
callable $ processTick
153
138
) {
154
139
self ::validateSegmentSize ($ segmentSize );
155
140
self ::validateBatchSize ($ batchSize );
156
- self ::validateScriptPath ($ scriptPath );
157
141
self ::validateProgressSymbol ($ progressSymbol );
158
142
159
143
$ this ->fetchItems = $ fetchItems ;
160
144
$ this ->runSingleCommand = $ runSingleCommand ;
161
145
$ this ->getItemName = $ getItemName ;
162
- $ this ->commandName = $ commandName ;
163
- $ this ->commandDefinition = $ commandDefinition ;
164
146
$ this ->errorHandler = $ errorHandler ;
165
147
$ this ->childSourceStream = $ childSourceStream ;
166
148
$ this ->batchSize = $ batchSize ;
@@ -170,8 +152,7 @@ public function __construct(
170
152
$ this ->runBeforeBatch = $ runBeforeBatch ;
171
153
$ this ->runAfterBatch = $ runAfterBatch ;
172
154
$ this ->progressSymbol = $ progressSymbol ;
173
- $ this ->phpExecutable = $ phpExecutable ;
174
- $ this ->scriptPath = $ scriptPath ;
155
+ $ this ->childCommandFactory = $ childCommandFactory ;
175
156
$ this ->workingDirectory = $ workingDirectory ;
176
157
$ this ->extraEnvironmentVariables = $ extraEnvironmentVariables ;
177
158
$ this ->processLauncherFactory = $ processLauncherFactory ;
@@ -365,20 +346,8 @@ private function createProcessLauncher(
365
346
InputInterface $ input ,
366
347
Logger $ logger
367
348
): ProcessLauncher {
368
- $ enrichedChildCommand = array_merge (
369
- $ this ->createChildCommand ($ input ),
370
- // Forward all the options except for "processes" to the children
371
- // this way the children can inherit the options such as env
372
- // or no-debug.
373
- InputOptionsSerializer::serialize (
374
- $ this ->commandDefinition ,
375
- $ input ,
376
- ['child ' , 'processes ' ],
377
- ),
378
- );
379
-
380
349
return $ this ->processLauncherFactory ->create (
381
- $ enrichedChildCommand ,
350
+ $ this -> childCommandFactory -> createChildCommand ( $ input ) ,
382
351
$ this ->workingDirectory ,
383
352
$ this ->extraEnvironmentVariables ,
384
353
$ numberOfProcesses ,
@@ -389,32 +358,6 @@ private function createProcessLauncher(
389
358
);
390
359
}
391
360
392
- /**
393
- * @return list<string>
394
- */
395
- private function createChildCommand (InputInterface $ input ): array
396
- {
397
- return array_filter ([
398
- $ this ->phpExecutable ,
399
- $ this ->scriptPath ,
400
- $ this ->commandName ,
401
- implode (
402
- ' ' ,
403
- // TODO: this looks suspicious: why do we need to take the first arg?
404
- // why is this not a specific arg?
405
- // why do we include optional arguments? (cf. options)
406
- // maybe has to do with the item arg but in that case it is incorrect...
407
- array_filter (
408
- array_slice (
409
- array_map ('strval ' , $ input ->getArguments ()),
410
- 1 ,
411
- ),
412
- ),
413
- ),
414
- '--child ' ,
415
- ]);
416
- }
417
-
418
361
/**
419
362
* Called whenever data is received in the main process from a child process.
420
363
*
@@ -459,18 +402,6 @@ private static function validateSegmentSize(int $segmentSize): void
459
402
);
460
403
}
461
404
462
- private static function validateScriptPath (string $ scriptPath ): void
463
- {
464
- Assert::fileExists (
465
- $ scriptPath ,
466
- sprintf (
467
- 'The script file could not be found at the path "%s" (working directory: %s) ' ,
468
- $ scriptPath ,
469
- getcwd (),
470
- ),
471
- );
472
- }
473
-
474
405
private static function validateProgressSymbol (string $ progressSymbol ): void
475
406
{
476
407
$ symbolLength = mb_strlen ($ progressSymbol );
0 commit comments