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

Breadcrumb

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

function RunScriptCommand::execute

Overrides Command::execute

File

vendor/composer/composer/src/Composer/Command/RunScriptCommand.php, line 102

Class

RunScriptCommand
@author Fabien Potencier <fabien.potencier@gmail.com>

Namespace

Composer\Command

Code

protected function execute(InputInterface $input, OutputInterface $output) : int {
    if ($input->getOption('list')) {
        return $this->listScripts($output);
    }
    $script = $input->getArgument('script');
    if ($script === null) {
        throw new \RuntimeException('Missing required argument "script"');
    }
    if (!in_array($script, $this->scriptEvents)) {
        if (defined('Composer\\Script\\ScriptEvents::' . str_replace('-', '_', strtoupper($script)))) {
            throw new \InvalidArgumentException(sprintf('Script "%s" cannot be run with this command', $script));
        }
    }
    $composer = $this->requireComposer();
    $devMode = $input->getOption('dev') || !$input->getOption('no-dev');
    $event = new ScriptEvent($script, $composer, $this->getIO(), $devMode);
    $hasListeners = $composer->getEventDispatcher()
        ->hasEventListeners($event);
    if (!$hasListeners) {
        throw new \InvalidArgumentException(sprintf('Script "%s" is not defined in this package', $script));
    }
    $args = $input->getArgument('args');
    if (null !== ($timeout = $input->getOption('timeout'))) {
        if (!ctype_digit($timeout)) {
            throw new \RuntimeException('Timeout value must be numeric and positive if defined, or 0 for forever');
        }
        // Override global timeout set before in Composer by environment or config
        ProcessExecutor::setTimeout((int) $timeout);
    }
    Platform::putEnv('COMPOSER_DEV_MODE', $devMode ? '1' : '0');
    return $composer->getEventDispatcher()
        ->dispatchScript($script, $devMode, $args);
}

API Navigation

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