@@ -62,6 +62,10 @@ class Loop
62
62
* @var bool
63
63
*/
64
64
private $ useFilePayloads = false ;
65
+ /**
66
+ * @var bool
67
+ */
68
+ private $ inheritEnv = false ;
65
69
66
70
/**
67
71
* @param array<int|string,Worker|callable> $workers
@@ -91,7 +95,8 @@ public function __construct(
91
95
* rethrow?: bool,
92
96
* requireFiles?: array<string>,
93
97
* cwd?: string,
94
- * use_file_payloads?: bool,
98
+ * useFilePayloads?: bool,
99
+ * inheritEnv?: bool
95
100
* } $options
96
101
*
97
102
* @throws ProcessException
@@ -102,10 +107,14 @@ public static function executeClosure(Closure $closure, int $timeout = 30, array
102
107
{
103
108
$ loop = new self ([$ closure ], 1 , true , $ timeout , $ options );
104
109
105
- if (!empty ($ options ['use_file_payloads ' ])) {
110
+ if (!empty ($ options ['useFilePayloads ' ])) {
106
111
$ loop ->setUseFilePayloads (true );
107
112
}
108
113
114
+ if (!empty ($ options ['inheritEnv ' ])) {
115
+ $ loop ->setInheritEnv (true );
116
+ }
117
+
109
118
$ loop ->run ();
110
119
$ results = $ loop ->getResults ();
111
120
$ result = $ results [0 ];
@@ -215,7 +224,7 @@ private function startWorker(): void
215
224
}
216
225
217
226
try {
218
- $ w = Running::fromWorker ($ runnableWorker , $ this ->useFilePayloads );
227
+ $ w = Running::fromWorker ($ runnableWorker , $ this ->useFilePayloads , $ this -> inheritEnv );
219
228
$ this ->started [$ w ->getId ()] = $ w ;
220
229
$ this ->running [$ w ->getId ()] = $ w ;
221
230
$ this ->peakParallelism = max ((int )$ this ->peakParallelism , count ($ this ->running ));
@@ -407,4 +416,9 @@ private function buildWorker(string $id, callable $worker): Worker
407
416
{
408
417
return new Worker ($ id , $ worker , [], []);
409
418
}
419
+
420
+ public function setInheritEnv (bool $ inheritEnv ):void
421
+ {
422
+ $ this ->inheritEnv = $ inheritEnv ;
423
+ }
410
424
}
0 commit comments