@@ -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
@@ -959,57 +956,31 @@ protected function doRenderThrowable(\Throwable $e, OutputInterface $output): vo
959956 */
960957 protected function configureIO (InputInterface $ input , OutputInterface $ output ): void
961958 {
962- if (true === $ input ->hasParameterOption (['--ansi ' ], true )) {
959+ if ($ input ->hasParameterOption (['--ansi ' ], true )) {
963960 $ output ->setDecorated (true );
964- } elseif (true === $ input ->hasParameterOption (['--no-ansi ' ], true )) {
961+ } elseif ($ input ->hasParameterOption (['--no-ansi ' ], true )) {
965962 $ output ->setDecorated (false );
966963 }
967964
968- if (true === $ input ->hasParameterOption (['--no-interaction ' , '-n ' ], true )) {
969- $ input ->setInteractive (false );
970- }
971-
972- switch ($ shellVerbosity = (int ) getenv ('SHELL_VERBOSITY ' )) {
973- case -2 :
974- $ output ->setVerbosity (OutputInterface::VERBOSITY_SILENT );
975- break ;
976- case -1 :
977- $ output ->setVerbosity (OutputInterface::VERBOSITY_QUIET );
978- break ;
979- case 1 :
980- $ output ->setVerbosity (OutputInterface::VERBOSITY_VERBOSE );
981- break ;
982- case 2 :
983- $ output ->setVerbosity (OutputInterface::VERBOSITY_VERY_VERBOSE );
984- break ;
985- case 3 :
986- $ output ->setVerbosity (OutputInterface::VERBOSITY_DEBUG );
987- break ;
988- default :
989- $ shellVerbosity = 0 ;
990- break ;
991- }
965+ $ shellVerbosity = match (true ) {
966+ $ input ->hasParameterOption (['--silent ' ], true ) => -2 ,
967+ $ input ->hasParameterOption (['--quiet ' , '-q ' ], true ) => -1 ,
968+ $ input ->hasParameterOption ('-vvv ' , true ) || $ input ->hasParameterOption ('--verbose=3 ' , true ) || 3 === $ input ->getParameterOption ('--verbose ' , false , true ) => 3 ,
969+ $ input ->hasParameterOption ('-vv ' , true ) || $ input ->hasParameterOption ('--verbose=2 ' , true ) || 2 === $ input ->getParameterOption ('--verbose ' , false , true ) => 2 ,
970+ $ input ->hasParameterOption ('-v ' , true ) || $ input ->hasParameterOption ('--verbose=1 ' , true ) || $ input ->hasParameterOption ('--verbose ' , true ) || $ input ->getParameterOption ('--verbose ' , false , true ) => 1 ,
971+ default => (int ) ($ _ENV ['SHELL_VERBOSITY ' ] ?? $ _SERVER ['SHELL_VERBOSITY ' ] ?? getenv ('SHELL_VERBOSITY ' )),
972+ };
992973
993- if (true === $ input ->hasParameterOption (['--silent ' ], true )) {
994- $ output ->setVerbosity (OutputInterface::VERBOSITY_SILENT );
995- $ shellVerbosity = -2 ;
996- } elseif (true === $ input ->hasParameterOption (['--quiet ' , '-q ' ], true )) {
997- $ output ->setVerbosity (OutputInterface::VERBOSITY_QUIET );
998- $ shellVerbosity = -1 ;
999- } else {
1000- if ($ input ->hasParameterOption ('-vvv ' , true ) || $ input ->hasParameterOption ('--verbose=3 ' , true ) || 3 === $ input ->getParameterOption ('--verbose ' , false , true )) {
1001- $ output ->setVerbosity (OutputInterface::VERBOSITY_DEBUG );
1002- $ shellVerbosity = 3 ;
1003- } elseif ($ input ->hasParameterOption ('-vv ' , true ) || $ input ->hasParameterOption ('--verbose=2 ' , true ) || 2 === $ input ->getParameterOption ('--verbose ' , false , true )) {
1004- $ output ->setVerbosity (OutputInterface::VERBOSITY_VERY_VERBOSE );
1005- $ shellVerbosity = 2 ;
1006- } elseif ($ input ->hasParameterOption ('-v ' , true ) || $ input ->hasParameterOption ('--verbose=1 ' , true ) || $ input ->hasParameterOption ('--verbose ' , true ) || $ input ->getParameterOption ('--verbose ' , false , true )) {
1007- $ output ->setVerbosity (OutputInterface::VERBOSITY_VERBOSE );
1008- $ shellVerbosity = 1 ;
1009- }
1010- }
974+ $ output ->setVerbosity (match ($ shellVerbosity ) {
975+ -2 => OutputInterface::VERBOSITY_SILENT ,
976+ -1 => OutputInterface::VERBOSITY_QUIET ,
977+ 1 => OutputInterface::VERBOSITY_VERBOSE ,
978+ 2 => OutputInterface::VERBOSITY_VERY_VERBOSE ,
979+ 3 => OutputInterface::VERBOSITY_DEBUG ,
980+ default => ($ shellVerbosity = 0 ) ?: $ output ->getVerbosity (),
981+ });
1011982
1012- if (0 > $ shellVerbosity ) {
983+ if (0 > $ shellVerbosity || $ input -> hasParameterOption ([ ' --no-interaction ' , ' -n ' ], true ) ) {
1013984 $ input ->setInteractive (false );
1014985 }
1015986
0 commit comments