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

Breadcrumb

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

function BaseCommand::getPreferredInstallOptions

Returns preferSource and preferDist values based on the configuration.

Return value

bool[] An array composed of the preferSource and preferDist values

6 calls to BaseCommand::getPreferredInstallOptions()
CreateProjectCommand::execute in vendor/composer/composer/src/Composer/Command/CreateProjectCommand.php
Executes the current command.
CreateProjectCommand::installProject in vendor/composer/composer/src/Composer/Command/CreateProjectCommand.php
InstallCommand::execute in vendor/composer/composer/src/Composer/Command/InstallCommand.php
Executes the current command.
ReinstallCommand::execute in vendor/composer/composer/src/Composer/Command/ReinstallCommand.php
Executes the current command.
RequireCommand::doUpdate in vendor/composer/composer/src/Composer/Command/RequireCommand.php

... See full list

File

vendor/composer/composer/src/Composer/Command/BaseCommand.php, line 320

Class

BaseCommand
Base class for Composer commands

Namespace

Composer\Command

Code

protected function getPreferredInstallOptions(Config $config, InputInterface $input, bool $keepVcsRequiresPreferSource = false) {
    $preferSource = false;
    $preferDist = false;
    switch ($config->get('preferred-install')) {
        case 'source':
            $preferSource = true;
            break;
        case 'dist':
            $preferDist = true;
            break;
        case 'auto':
        default:
            // noop
            break;
    }
    if (!$input->hasOption('prefer-dist') || !$input->hasOption('prefer-source')) {
        return [
            $preferSource,
            $preferDist,
        ];
    }
    if ($input->hasOption('prefer-install') && is_string($input->getOption('prefer-install'))) {
        if ($input->getOption('prefer-source')) {
            throw new \InvalidArgumentException('--prefer-source can not be used together with --prefer-install');
        }
        if ($input->getOption('prefer-dist')) {
            throw new \InvalidArgumentException('--prefer-dist can not be used together with --prefer-install');
        }
        switch ($input->getOption('prefer-install')) {
            case 'dist':
                $input->setOption('prefer-dist', true);
                break;
            case 'source':
                $input->setOption('prefer-source', true);
                break;
            case 'auto':
                $preferDist = false;
                $preferSource = false;
                break;
            default:
                throw new \UnexpectedValueException('--prefer-install accepts one of "dist", "source" or "auto", got ' . $input->getOption('prefer-install'));
        }
    }
    if ($input->getOption('prefer-source') || $input->getOption('prefer-dist') || $keepVcsRequiresPreferSource && $input->hasOption('keep-vcs') && $input->getOption('keep-vcs')) {
        $preferSource = $input->getOption('prefer-source') || $keepVcsRequiresPreferSource && $input->hasOption('keep-vcs') && $input->getOption('keep-vcs');
        $preferDist = $input->getOption('prefer-dist');
    }
    return [
        $preferSource,
        $preferDist,
    ];
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal