function ComposerInspector::getVersion

Returns the current Composer version.

Return value

string The Composer version.

Throws

\UnexpectedValueException Thrown if the Composer version cannot be determined.

1 call to ComposerInspector::getVersion()
ComposerInspector::validateExecutable in core/modules/package_manager/src/ComposerInspector.php
Validates that the Composer executable exists in a supported version.

File

core/modules/package_manager/src/ComposerInspector.php, line 264

Class

ComposerInspector
Defines a class to get information from Composer.

Namespace

Drupal\package_manager

Code

public function getVersion() : string {
  $this->runner
    ->run([
    '--format=json',
  ], callback: $this->processCallback
    ->reset());
  $data = $this->processCallback
    ->parseJsonOutput();
  if (isset($data['application']['name']) && isset($data['application']['version']) && $data['application']['name'] === 'Composer' && is_string($data['application']['version'])) {
    return $data['application']['version'];
  }
  throw new \UnexpectedValueException('Unable to determine Composer version');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.