You are here

class ComposerDeployHandler in Composer Deploy 8

Same name and namespace in other branches
  1. 7 includes/ComposerDeployHandler.php \Drupal\composer_deploy\ComposerDeployHandler

Hierarchy

Expanded class hierarchy of ComposerDeployHandler

1 file declares its use of ComposerDeployHandler
composer_deploy.module in ./composer_deploy.module

File

src/ComposerDeployHandler.php, line 10
Contains \Drupal\composer_deploy\ComposerDeployHanlder.

Namespace

Drupal\composer_deploy
View source
class ComposerDeployHandler {
  protected $packages = [];

  /**
   * List of package prefixes.
   *
   * @var string[]
   */
  protected $prefixes = [
    'drupal',
  ];
  public function __construct($path) {
    $packages = json_decode(file_get_contents($path), TRUE);

    // Composer 2.0 compatibility.
    // @see https://getcomposer.org/upgrade/UPGRADE-2.0.md
    $packages = $packages['packages'] ?? $packages;
    $this->packages = is_array($packages) ? $packages : [];
  }
  public function getPackage($projectName) {
    foreach ($this->packages as $package) {
      foreach ($this->prefixes as $prefix) {
        if ($package['name'] == $prefix . '/' . $projectName) {
          return $package;
        }
      }
    }
    return FALSE;
  }
  public static function fromVendorDir($vendor_dir) {
    return new static($vendor_dir . '/composer/installed.json');
  }

  /**
   * Set the package prefixes to check against.
   *
   * @param string[] $prefixes
   */
  public function setPrefixes(array $prefixes) {
    $this->prefixes = $prefixes;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ComposerDeployHandler::$packages protected property
ComposerDeployHandler::$prefixes protected property List of package prefixes.
ComposerDeployHandler::fromVendorDir public static function
ComposerDeployHandler::getPackage public function
ComposerDeployHandler::setPrefixes public function Set the package prefixes to check against.
ComposerDeployHandler::__construct public function