@@ -62,6 +62,10 @@ class Loop
6262 * @var bool
6363 */
6464 private $ useFilePayloads = false ;
65+ /**
66+ * @var bool
67+ */
68+ private $ inheritEnv = false ;
6569
6670 /**
6771 * @param array<int|string,Worker|callable> $workers
@@ -91,7 +95,8 @@ public function __construct(
9195 * rethrow?: bool,
9296 * requireFiles?: array<string>,
9397 * cwd?: string,
94- * use_file_payloads?: bool,
98+ * useFilePayloads?: bool,
99+ * inheritEnv?: bool
95100 * } $options
96101 *
97102 * @throws ProcessException
@@ -102,10 +107,14 @@ public static function executeClosure(Closure $closure, int $timeout = 30, array
102107 {
103108 $ loop = new self ([$ closure ], 1 , true , $ timeout , $ options );
104109
105- if (!empty ($ options ['use_file_payloads ' ])) {
110+ if (!empty ($ options ['useFilePayloads ' ])) {
106111 $ loop ->setUseFilePayloads (true );
107112 }
108113
114+ if (!empty ($ options ['inheritEnv ' ])) {
115+ $ loop ->setInheritEnv (true );
116+ }
117+
109118 $ loop ->run ();
110119 $ results = $ loop ->getResults ();
111120 $ result = $ results [0 ];
@@ -215,7 +224,7 @@ private function startWorker(): void
215224 }
216225
217226 try {
218- $ w = Running::fromWorker ($ runnableWorker , $ this ->useFilePayloads );
227+ $ w = Running::fromWorker ($ runnableWorker , $ this ->useFilePayloads , $ this -> inheritEnv );
219228 $ this ->started [$ w ->getId ()] = $ w ;
220229 $ this ->running [$ w ->getId ()] = $ w ;
221230 $ this ->peakParallelism = max ((int )$ this ->peakParallelism , count ($ this ->running ));
@@ -407,4 +416,9 @@ private function buildWorker(string $id, callable $worker): Worker
407416 {
408417 return new Worker ($ id , $ worker , [], []);
409418 }
419+
420+ public function setInheritEnv (bool $ inheritEnv ):void
421+ {
422+ $ this ->inheritEnv = $ inheritEnv ;
423+ }
410424}
0 commit comments