@@ -363,14 +363,23 @@ private function validateOutputDir(InputInterface $input, OutputStyle $io): void
363363
364364 private function retrieveConfig (InputInterface $ input , OutputInterface $ output , OutputStyle $ io ): Configuration
365365 {
366+ $ prefix = $ input ->getOption (self ::PREFIX_OPT );
367+
366368 if ($ input ->getOption (self ::NO_CONFIG_OPT )) {
367369 $ io ->writeln (
368370 'Loading without configuration file. ' ,
369- OutputStyle ::VERBOSITY_DEBUG
371+ OutputInterface ::VERBOSITY_DEBUG
370372 );
371373
372374 $ config = Configuration::load ();
373- $ config = $ config ->withPrefix ($ input ->getOption (self ::PREFIX_OPT ));
375+
376+ if (null !== $ prefix ) {
377+ $ config ->withPrefix ($ prefix );
378+ }
379+
380+ if (null === $ config ->getPrefix ()) {
381+ $ config = $ config ->withPrefix ($ this ->generateRandomPrefix ());
382+ }
374383
375384 return $ this ->retrievePaths ($ input , $ config );
376385 }
@@ -395,7 +404,7 @@ private function retrieveConfig(InputInterface $input, OutputInterface $output,
395404 'Config file "<comment>%s</comment>" not found. Skipping. ' ,
396405 $ configFile
397406 ),
398- OutputStyle ::VERBOSITY_DEBUG
407+ OutputInterface ::VERBOSITY_DEBUG
399408 );
400409
401410 return self ::retrieveConfig ($ input , $ output , $ io );
@@ -411,7 +420,7 @@ private function retrieveConfig(InputInterface $input, OutputInterface $output,
411420 if (null === $ configFile ) {
412421 $ io ->writeln (
413422 'Loading without configuration file. ' ,
414- OutputStyle ::VERBOSITY_DEBUG
423+ OutputInterface ::VERBOSITY_DEBUG
415424 );
416425 } elseif (false === file_exists ($ configFile )) {
417426 throw new RuntimeException (
@@ -426,14 +435,22 @@ private function retrieveConfig(InputInterface $input, OutputInterface $output,
426435 'Using the configuration file "%s". ' ,
427436 $ configFile
428437 ),
429- OutputStyle ::VERBOSITY_DEBUG
438+ OutputInterface ::VERBOSITY_DEBUG
430439 );
431440 }
432441
433442 $ config = Configuration::load ($ configFile );
434443 $ config = $ this ->retrievePaths ($ input , $ config );
435444
436- return $ config ->withPrefix ($ input ->getOption (self ::PREFIX_OPT ));
445+ if (null !== $ prefix ) {
446+ $ config ->withPrefix ($ prefix );
447+ }
448+
449+ if (null === $ config ->getPrefix ()) {
450+ $ config = $ config ->withPrefix ($ this ->generateRandomPrefix ());
451+ }
452+
453+ return $ config ;
437454 }
438455
439456 private function retrievePaths (InputInterface $ input , Configuration $ config ): Configuration
@@ -456,4 +473,9 @@ private function makeAbsolutePath(string $path): string
456473
457474 return $ path ;
458475 }
476+
477+ private function generateRandomPrefix (): string
478+ {
479+ return uniqid ('_PhpScoper ' , false );
480+ }
459481}
0 commit comments