function ExecutableFinder::getLocalComposerPath

Tries to find the Composer binary installed in the project.

Return value

string|null The path of the `composer` binary installed in the project's vendor dependencies, or NULL if it is not installed or cannot be found.

1 call to ExecutableFinder::getLocalComposerPath()
ExecutableFinder::find in core/modules/package_manager/src/ExecutableFinder.php

File

core/modules/package_manager/src/ExecutableFinder.php, line 84

Class

ExecutableFinder
An executable finder which looks for executable paths in configuration.

Namespace

Drupal\package_manager

Code

private function getLocalComposerPath() : ?string {
  // Composer is not installed in the project, so there's nothing to do.
  if ($this->composerPackagePath === FALSE) {
    return NULL;
  }
  // This is a bit expensive to compute, so statically cache it.
  if ($this->composerBinaryPath) {
    return $this->composerBinaryPath;
  }
  $composer_json = file_get_contents($this->composerPackagePath . '/composer.json');
  $composer_json = Json::decode($composer_json);
  foreach ($composer_json['bin'] ?? [] as $bin) {
    if (str_ends_with($bin, '/composer')) {
      $this->composerBinaryPath = $this->composerPackagePath . '/' . $bin;
      break;

    }
  }
  return $this->composerBinaryPath;
}

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