You are here

public function ComposerExecutableValidator::checkForComposerExecutable in Automatic Updates 8.2

Validates that the Composer executable can be found.

Parameters

\Drupal\automatic_updates\Event\UpdateEvent $event: The event object.

File

src/Validator/ComposerExecutableValidator.php, line 56

Class

ComposerExecutableValidator
Validates that the Composer executable can be found in the correct version.

Namespace

Drupal\automatic_updates\Validator

Code

public function checkForComposerExecutable(UpdateEvent $event) : void {
  try {
    $this->composer
      ->run([
      '--version',
    ], $this);
  } catch (ExceptionInterface $e) {
    $error = ValidationResult::createError([
      $e
        ->getMessage(),
    ]);
    $event
      ->addValidationResult($error);
    return;
  }
  if ($this->version) {
    $major_version = ExtensionVersion::createFromVersionString($this->version)
      ->getMajorVersion();
    if ($major_version < 2) {
      $error = ValidationResult::createError([
        $this
          ->t('Composer 2 or later is required, but version @version was detected.', [
          '@version' => $this->version,
        ]),
      ]);
      $event
        ->addValidationResult($error);
    }
  }
  else {
    $error = ValidationResult::createError([
      $this
        ->t('The Composer version could not be detected.'),
    ]);
    $event
      ->addValidationResult($error);
  }
}