Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. SyncHelper.php

function SyncHelper::downloadAndInstallPackageSync

Helps you download + install a single package in a synchronous way

This executes all the required steps and waits for promises to complete

Parameters

Loop $loop Loop instance which you can get from $composer->getLoop():

DownloaderInterface|DownloadManager $downloader DownloadManager instance or Downloader instance you can get from $composer->getDownloadManager()->getDownloader('zip') for example:

string $path The installation path for the package:

PackageInterface $package The package to install:

PackageInterface|null $prevPackage The previous package if this is an update and not an initial installation:

File

vendor/composer/composer/src/Composer/Util/SyncHelper.php, line 33

Class

SyncHelper

Namespace

Composer\Util

Code

public static function downloadAndInstallPackageSync(Loop $loop, $downloader, string $path, PackageInterface $package, ?PackageInterface $prevPackage = null) : void {
    assert($downloader instanceof DownloaderInterface || $downloader instanceof DownloadManager);
    $type = $prevPackage !== null ? 'update' : 'install';
    try {
        self::await($loop, $downloader->download($package, $path, $prevPackage));
        self::await($loop, $downloader->prepare($type, $package, $path, $prevPackage));
        if ($type === 'update' && $prevPackage !== null) {
            self::await($loop, $downloader->update($package, $prevPackage, $path));
        }
        else {
            self::await($loop, $downloader->install($package, $path));
        }
    } catch (\Exception $e) {
        self::await($loop, $downloader->cleanup($type, $package, $path, $prevPackage));
        throw $e;
    }
    self::await($loop, $downloader->cleanup($type, $package, $path, $prevPackage));
}
RSS feed
Powered by Drupal