Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. DumpAutoloadCommand.php

function DumpAutoloadCommand::execute

Overrides Command::execute

File

vendor/composer/composer/src/Composer/Command/DumpAutoloadCommand.php, line 59

Class

DumpAutoloadCommand
@author Jordi Boggiano <j.boggiano@seld.be>

Namespace

Composer\Command

Code

protected function execute(InputInterface $input, OutputInterface $output) : int {
    $composer = $this->requireComposer();
    $commandEvent = new CommandEvent(PluginEvents::COMMAND, 'dump-autoload', $input, $output);
    $composer->getEventDispatcher()
        ->dispatch($commandEvent->getName(), $commandEvent);
    $installationManager = $composer->getInstallationManager();
    $localRepo = $composer->getRepositoryManager()
        ->getLocalRepository();
    $package = $composer->getPackage();
    $config = $composer->getConfig();
    $missingDependencies = false;
    foreach ($localRepo->getCanonicalPackages() as $localPkg) {
        $installPath = $installationManager->getInstallPath($localPkg);
        if ($installPath !== null && file_exists($installPath) === false) {
            $missingDependencies = true;
            $this->getIO()
                ->write('<warning>Not all dependencies are installed. Make sure to run a "composer install" to install missing dependencies</warning>');
            break;
        }
    }
    $optimize = $input->getOption('optimize') || $config->get('optimize-autoloader');
    $authoritative = $input->getOption('classmap-authoritative') || $config->get('classmap-authoritative');
    $apcuPrefix = $input->getOption('apcu-prefix');
    $apcu = $apcuPrefix !== null || $input->getOption('apcu') || $config->get('apcu-autoloader');
    if ($input->getOption('strict-psr') && !$optimize && !$authoritative) {
        throw new \InvalidArgumentException('--strict-psr mode only works with optimized autoloader, use --optimize or --classmap-authoritative if you want a strict return value.');
    }
    if ($input->getOption('strict-ambiguous') && !$optimize && !$authoritative) {
        throw new \InvalidArgumentException('--strict-ambiguous mode only works with optimized autoloader, use --optimize or --classmap-authoritative if you want a strict return value.');
    }
    if ($authoritative) {
        $this->getIO()
            ->write('<info>Generating optimized autoload files (authoritative)</info>');
    }
    elseif ($optimize) {
        $this->getIO()
            ->write('<info>Generating optimized autoload files</info>');
    }
    else {
        $this->getIO()
            ->write('<info>Generating autoload files</info>');
    }
    $generator = $composer->getAutoloadGenerator();
    if ($input->getOption('dry-run')) {
        $generator->setDryRun(true);
    }
    if ($input->getOption('no-dev')) {
        $generator->setDevMode(false);
    }
    if ($input->getOption('dev')) {
        if ($input->getOption('no-dev')) {
            throw new \InvalidArgumentException('You can not use both --no-dev and --dev as they conflict with each other.');
        }
        $generator->setDevMode(true);
    }
    $generator->setClassMapAuthoritative($authoritative);
    $generator->setRunScripts(true);
    $generator->setApcu($apcu, $apcuPrefix);
    $generator->setPlatformRequirementFilter($this->getPlatformRequirementFilter($input));
    $classMap = $generator->dump($config, $localRepo, $package, $installationManager, 'composer', $optimize, null, $composer->getLocker(), $input->getOption('strict-ambiguous'));
    $numberOfClasses = count($classMap);
    if ($authoritative) {
        $this->getIO()
            ->write('<info>Generated optimized autoload files (authoritative) containing ' . $numberOfClasses . ' classes</info>');
    }
    elseif ($optimize) {
        $this->getIO()
            ->write('<info>Generated optimized autoload files containing ' . $numberOfClasses . ' classes</info>');
    }
    else {
        $this->getIO()
            ->write('<info>Generated autoload files</info>');
    }
    if ($missingDependencies || $input->getOption('strict-psr') && count($classMap->getPsrViolations()) > 0) {
        return 1;
    }
    if ($input->getOption('strict-ambiguous') && count($classMap->getAmbiguousClasses(false)) > 0) {
        return 2;
    }
    return 0;
}
RSS feed
Powered by Drupal