@@ -57,7 +57,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5757 $ path = $ this ->options ->get ('root-dir ' ).'/ ' .($ runtime ['dotenv_path ' ] ?? '.env ' );
5858
5959 if (!$ env || !$ input ->getOption ('empty ' )) {
60- $ vars = $ this ->loadEnv ($ path , $ env , $ runtime );
60+ $ vars = $ this ->loadEnv ($ path , $ env , $ runtime, $ projectDirCookie );
6161 $ env = $ vars [$ envKey ];
6262 }
6363
@@ -66,6 +66,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6666 }
6767
6868 $ vars = var_export ($ vars , true );
69+ $ vars = str_replace ($ projectDirCookie , "'.( \$_SERVER['APP_PROJECT_DIR'] ?? '').' " , $ vars );
6970 $ vars = <<<EOF
7071 <?php
7172
@@ -81,7 +82,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8182 return 0 ;
8283 }
8384
84- private function loadEnv (string $ path , ?string $ env , array $ runtime ): array
85+ private function loadEnv (string $ path , ?string $ env , array $ runtime, ? string & $ projectDirCookie ): array
8586 {
8687 if (!file_exists ($ autoloadFile = $ this ->config ->get ('vendor-dir ' ).'/autoload.php ' )) {
8788 throw new \RuntimeException (\sprintf ('Please run "composer install" before running this command: "%s" not found. ' , $ autoloadFile ));
@@ -98,6 +99,7 @@ private function loadEnv(string $path, ?string $env, array $runtime): array
9899 unset($ _SERVER [$ envKey ]);
99100 $ _ENV = [$ envKey => $ env ];
100101 $ _SERVER ['SYMFONY_DOTENV_VARS ' ] = implode (', ' , array_keys ($ _SERVER ));
102+ $ _SERVER ['APP_PROJECT_DIR ' ] = $ projectDirCookie = hash ('xxh128 ' , random_bytes (8 ));
101103 putenv ('SYMFONY_DOTENV_VARS= ' .$ _SERVER ['SYMFONY_DOTENV_VARS ' ]);
102104
103105 try {
0 commit comments