diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index f9238bec4..be776f1d0 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -70,6 +70,11 @@ class AutoloadGenerator */ private $apcuPrefix; + /** + * @var bool + */ + private $dryRun = false; + /** * @var bool */ @@ -127,6 +132,14 @@ class AutoloadGenerator $this->runScripts = $runScripts; } + /** + * Whether to run in drymode or not + */ + public function setDryRun(bool $dryRun = true): void + { + $this->dryRun = $dryRun; + } + /** * Whether platform requirements should be ignored. * @@ -398,6 +411,10 @@ EOF; } } + if ($this->dryRun) { + return $classMap; + } + $filesystem->filePutContentsIfModified($targetDir.'/autoload_namespaces.php', $namespacesFile); $filesystem->filePutContentsIfModified($targetDir.'/autoload_psr4.php', $psr4File); $filesystem->filePutContentsIfModified($targetDir.'/autoload_classmap.php', $classmapFile); diff --git a/src/Composer/Command/DumpAutoloadCommand.php b/src/Composer/Command/DumpAutoloadCommand.php index 2014940c3..41a23cd3a 100644 --- a/src/Composer/Command/DumpAutoloadCommand.php +++ b/src/Composer/Command/DumpAutoloadCommand.php @@ -37,6 +37,7 @@ class DumpAutoloadCommand extends BaseCommand new InputOption('classmap-authoritative', 'a', InputOption::VALUE_NONE, 'Autoload classes from the classmap only. Implicitly enables `--optimize`.'), new InputOption('apcu', null, InputOption::VALUE_NONE, 'Use APCu to cache found/not-found classes.'), new InputOption('apcu-prefix', null, InputOption::VALUE_REQUIRED, 'Use a custom prefix for the APCu autoloader cache. Implicitly enables --apcu'), + new InputOption('dry-run', null, InputOption::VALUE_NONE, 'Outputs the operations but will not execute anything.'), new InputOption('dev', null, InputOption::VALUE_NONE, 'Enables autoload-dev rules. Composer will by default infer this automatically according to the last install or update --no-dev state.'), new InputOption('no-dev', null, InputOption::VALUE_NONE, 'Disables autoload-dev rules. Composer will by default infer this automatically according to the last install or update --no-dev state.'), new InputOption('ignore-platform-req', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Ignore a specific platform requirement (php & ext- packages).'), @@ -83,6 +84,9 @@ EOT } $generator = $composer->getAutoloadGenerator(); + if ($input->getOption('dry-run')) { + $generator->setDryRun(true); + } if ($input->getOption('no-dev')) { $generator->setDevMode(false); }