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

Breadcrumb

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

class SyncHelper

Hierarchy

  • class \Composer\Util\SyncHelper

Expanded class hierarchy of SyncHelper

1 file declares its use of SyncHelper
ArchiveManager.php in vendor/composer/composer/src/Composer/Package/Archiver/ArchiveManager.php

File

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

Namespace

Composer\Util
View source
class SyncHelper {
    
    /**
     * Helps you download + install a single package in a synchronous way
     *
     * This executes all the required steps and waits for promises to complete
     *
     * @param Loop                                $loop        Loop instance which you can get from $composer->getLoop()
     * @param DownloaderInterface|DownloadManager $downloader  DownloadManager instance or Downloader instance you can get from $composer->getDownloadManager()->getDownloader('zip') for example
     * @param string                              $path        The installation path for the package
     * @param PackageInterface                    $package     The package to install
     * @param PackageInterface|null               $prevPackage The previous package if this is an update and not an initial installation
     */
    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));
    }
    
    /**
     * Waits for a promise to resolve
     *
     * @param Loop                  $loop    Loop instance which you can get from $composer->getLoop()
     * @phpstan-param PromiseInterface<mixed>|null $promise
     */
    public static function await(Loop $loop, ?PromiseInterface $promise = null) : void {
        if ($promise !== null) {
            $loop->wait([
                $promise,
            ]);
        }
    }

}

Members

Title Sort descending Modifiers Object type Summary
SyncHelper::await public static function Waits for a promise to resolve
SyncHelper::downloadAndInstallPackageSync public static function Helps you download + install a single package in a synchronous way

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal