@@ -186,7 +186,8 @@ public function run(?InputInterface $input = null, ?OutputInterface $output = nu
186186 }
187187 }
188188
189- $ prevShellVerbosity = getenv ('SHELL_VERBOSITY ' );
189+ $ empty = new \stdClass ();
190+ $ prevShellVerbosity = [$ _ENV ['SHELL_VERBOSITY ' ] ?? $ empty , $ _SERVER ['SHELL_VERBOSITY ' ] ?? $ empty , getenv ('SHELL_VERBOSITY ' )];
190191
191192 try {
192193 $ this ->configureIO ($ input , $ output );
@@ -228,18 +229,14 @@ public function run(?InputInterface $input = null, ?OutputInterface $output = nu
228229
229230 // SHELL_VERBOSITY is set by Application::configureIO so we need to unset/reset it
230231 // to its previous value to avoid one command verbosity to spread to other commands
231- if (false === $ prevShellVerbosity ) {
232- if (\function_exists ('putenv ' )) {
233- @putenv ('SHELL_VERBOSITY ' );
234- }
232+ if ($ empty === $ _ENV ['SHELL_VERBOSITY ' ] = $ prevShellVerbosity [0 ]) {
235233 unset($ _ENV ['SHELL_VERBOSITY ' ]);
234+ }
235+ if ($ empty === $ _SERVER ['SHELL_VERBOSITY ' ] = $ prevShellVerbosity [1 ]) {
236236 unset($ _SERVER ['SHELL_VERBOSITY ' ]);
237- } else {
238- if (\function_exists ('putenv ' )) {
239- @putenv ('SHELL_VERBOSITY= ' .$ prevShellVerbosity );
240- }
241- $ _ENV ['SHELL_VERBOSITY ' ] = $ prevShellVerbosity ;
242- $ _SERVER ['SHELL_VERBOSITY ' ] = $ prevShellVerbosity ;
237+ }
238+ if (\function_exists ('putenv ' )) {
239+ @putenv ('SHELL_VERBOSITY ' .(false === ($ prevShellVerbosity [2 ] ?? false ) ? '' : '= ' .$ prevShellVerbosity [2 ]));
243240 }
244241 }
245242
@@ -945,57 +942,31 @@ protected function doRenderThrowable(\Throwable $e, OutputInterface $output): vo
945942 */
946943 protected function configureIO (InputInterface $ input , OutputInterface $ output ): void
947944 {
948- if (true === $ input ->hasParameterOption (['--ansi ' ], true )) {
945+ if ($ input ->hasParameterOption (['--ansi ' ], true )) {
949946 $ output ->setDecorated (true );
950- } elseif (true === $ input ->hasParameterOption (['--no-ansi ' ], true )) {
947+ } elseif ($ input ->hasParameterOption (['--no-ansi ' ], true )) {
951948 $ output ->setDecorated (false );
952949 }
953950
954- if (true === $ input ->hasParameterOption (['--no-interaction ' , '-n ' ], true )) {
955- $ input ->setInteractive (false );
956- }
957-
958- switch ($ shellVerbosity = (int ) getenv ('SHELL_VERBOSITY ' )) {
959- case -2 :
960- $ output ->setVerbosity (OutputInterface::VERBOSITY_SILENT );
961- break ;
962- case -1 :
963- $ output ->setVerbosity (OutputInterface::VERBOSITY_QUIET );
964- break ;
965- case 1 :
966- $ output ->setVerbosity (OutputInterface::VERBOSITY_VERBOSE );
967- break ;
968- case 2 :
969- $ output ->setVerbosity (OutputInterface::VERBOSITY_VERY_VERBOSE );
970- break ;
971- case 3 :
972- $ output ->setVerbosity (OutputInterface::VERBOSITY_DEBUG );
973- break ;
974- default :
975- $ shellVerbosity = 0 ;
976- break ;
977- }
951+ $ shellVerbosity = match (true ) {
952+ $ input ->hasParameterOption (['--silent ' ], true ) => -2 ,
953+ $ input ->hasParameterOption (['--quiet ' , '-q ' ], true ) => -1 ,
954+ $ input ->hasParameterOption ('-vvv ' , true ) || $ input ->hasParameterOption ('--verbose=3 ' , true ) || 3 === $ input ->getParameterOption ('--verbose ' , false , true ) => 3 ,
955+ $ input ->hasParameterOption ('-vv ' , true ) || $ input ->hasParameterOption ('--verbose=2 ' , true ) || 2 === $ input ->getParameterOption ('--verbose ' , false , true ) => 2 ,
956+ $ input ->hasParameterOption ('-v ' , true ) || $ input ->hasParameterOption ('--verbose=1 ' , true ) || $ input ->hasParameterOption ('--verbose ' , true ) || $ input ->getParameterOption ('--verbose ' , false , true ) => 1 ,
957+ default => (int ) ($ _ENV ['SHELL_VERBOSITY ' ] ?? $ _SERVER ['SHELL_VERBOSITY ' ] ?? getenv ('SHELL_VERBOSITY ' )),
958+ };
978959
979- if (true === $ input ->hasParameterOption (['--silent ' ], true )) {
980- $ output ->setVerbosity (OutputInterface::VERBOSITY_SILENT );
981- $ shellVerbosity = -2 ;
982- } elseif (true === $ input ->hasParameterOption (['--quiet ' , '-q ' ], true )) {
983- $ output ->setVerbosity (OutputInterface::VERBOSITY_QUIET );
984- $ shellVerbosity = -1 ;
985- } else {
986- if ($ input ->hasParameterOption ('-vvv ' , true ) || $ input ->hasParameterOption ('--verbose=3 ' , true ) || 3 === $ input ->getParameterOption ('--verbose ' , false , true )) {
987- $ output ->setVerbosity (OutputInterface::VERBOSITY_DEBUG );
988- $ shellVerbosity = 3 ;
989- } elseif ($ input ->hasParameterOption ('-vv ' , true ) || $ input ->hasParameterOption ('--verbose=2 ' , true ) || 2 === $ input ->getParameterOption ('--verbose ' , false , true )) {
990- $ output ->setVerbosity (OutputInterface::VERBOSITY_VERY_VERBOSE );
991- $ shellVerbosity = 2 ;
992- } elseif ($ input ->hasParameterOption ('-v ' , true ) || $ input ->hasParameterOption ('--verbose=1 ' , true ) || $ input ->hasParameterOption ('--verbose ' , true ) || $ input ->getParameterOption ('--verbose ' , false , true )) {
993- $ output ->setVerbosity (OutputInterface::VERBOSITY_VERBOSE );
994- $ shellVerbosity = 1 ;
995- }
996- }
960+ $ output ->setVerbosity (match ($ shellVerbosity ) {
961+ -2 => OutputInterface::VERBOSITY_SILENT ,
962+ -1 => OutputInterface::VERBOSITY_QUIET ,
963+ 1 => OutputInterface::VERBOSITY_VERBOSE ,
964+ 2 => OutputInterface::VERBOSITY_VERY_VERBOSE ,
965+ 3 => OutputInterface::VERBOSITY_DEBUG ,
966+ default => ($ shellVerbosity = 0 ) ?: $ output ->getVerbosity (),
967+ });
997968
998- if (0 > $ shellVerbosity ) {
969+ if (0 > $ shellVerbosity || $ input -> hasParameterOption ([ ' --no-interaction ' , ' -n ' ], true ) ) {
999970 $ input ->setInteractive (false );
1000971 }
1001972
0 commit comments