function ComposerPatchesValidator::computePatcherStatus

Computes the status of the patcher plugin in a particular directory.

Parameters

string $working_dir: The directory in which to run Composer.

Return value

bool[] An indexed array containing three booleans, in order:

  • Whether the patcher plugin is installed.
  • Whether the patcher plugin is a root requirement in composer.json (in either the runtime or dev dependencies).
  • Whether the `composer-exit-on-patch-failure` flag is set in the `extra` section of composer.json.
1 call to ComposerPatchesValidator::computePatcherStatus()
ComposerPatchesValidator::validate in core/modules/package_manager/src/Validator/ComposerPatchesValidator.php
Validates the status of the patcher plugin.

File

core/modules/package_manager/src/Validator/ComposerPatchesValidator.php, line 147

Class

ComposerPatchesValidator
Validates the configuration of the cweagans/composer-patches plugin.

Namespace

Drupal\package_manager\Validator

Code

private function computePatcherStatus(string $working_dir) : array {
  $list = $this->composerInspector
    ->getInstalledPackagesList($working_dir);
  $installed_version = $list[static::PLUGIN_NAME]?->version;
  $info = $this->composerInspector
    ->getRootPackageInfo($working_dir);
  $is_root_requirement = array_key_exists(static::PLUGIN_NAME, $info['requires'] ?? []) || array_key_exists(static::PLUGIN_NAME, $info['devRequires'] ?? []);
  // The 2.x version of the plugin always exits with an error if a patch can't
  // be applied.
  if ($installed_version && Semver::satisfies($installed_version, '^2')) {
    $exit_on_failure = TRUE;
  }
  else {
    $extra = Json::decode($this->composerInspector
      ->getConfig('extra', $working_dir));
    $exit_on_failure = $extra['composer-exit-on-patch-failure'] ?? FALSE;
  }
  return [
    is_string($installed_version),
    $is_root_requirement,
    $exit_on_failure,
  ];
}

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