@@ -292,6 +292,13 @@ final class EvoBootstrapper
292292 $ composerHome = rtrim ($ home , "/ \\" ) . DIRECTORY_SEPARATOR . '.composer ' ;
293293 }
294294
295+ // Ensure Composer sees these even if we fall back to shell execution.
296+ @putenv ('HOME= ' . $ home );
297+ @putenv ('COMPOSER_HOME= ' . $ composerHome );
298+ if (!is_dir ($ composerHome )) {
299+ @mkdir ($ composerHome , 0755 , true );
300+ }
301+
295302 $ this ->out ('Updating PHP installer package via Composer... ' );
296303 $ code = $ this ->runProcess (
297304 [
@@ -448,7 +455,7 @@ final class EvoBootstrapper
448455 2 => STDERR ,
449456 ];
450457
451- $ mergedEnv = array_merge ($ _ENV , $ env );
458+ $ mergedEnv = array_merge ($ this -> readCurrentEnvironment () , $ env );
452459 $ proc = @proc_open ($ cmd , $ descriptors , $ pipes , $ cwd ?: null , $ mergedEnv );
453460 if (is_resource ($ proc )) {
454461 $ code = proc_close ($ proc );
@@ -475,6 +482,39 @@ final class EvoBootstrapper
475482 return (int )$ exitCode ;
476483 }
477484
485+ /**
486+ * @return array<string, string>
487+ */
488+ private function readCurrentEnvironment (): array
489+ {
490+ $ env = [];
491+
492+ foreach ($ _ENV as $ k => $ v ) {
493+ if (is_string ($ k ) && is_string ($ v )) {
494+ $ env [$ k ] = $ v ;
495+ }
496+ }
497+ foreach ($ _SERVER as $ k => $ v ) {
498+ if (is_string ($ k ) && is_string ($ v )) {
499+ $ env [$ k ] = $ v ;
500+ }
501+ }
502+
503+ // Provide a sane PATH if the environment is mostly empty.
504+ if (!isset ($ env ['PATH ' ]) || trim ($ env ['PATH ' ]) === '' ) {
505+ $ path = getenv ('PATH ' );
506+ if (is_string ($ path ) && trim ($ path ) !== '' ) {
507+ $ env ['PATH ' ] = $ path ;
508+ } else {
509+ $ env ['PATH ' ] = PHP_OS_FAMILY === 'Windows '
510+ ? 'C: \\Windows \\System32 '
511+ : '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin ' ;
512+ }
513+ }
514+
515+ return $ env ;
516+ }
517+
478518 private function isFunctionDisabled (string $ name ): bool
479519 {
480520 $ disabled = (string )ini_get ('disable_functions ' );
0 commit comments