Skip to content

Commit 12f2bae

Browse files
committed
Add support for Composer v2 promises
1 parent d20c10c commit 12f2bae

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

src/ComposerInstaller/SiteProfileInstaller.php

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Composer\Repository\InstalledRepositoryInterface;
66
use Composer\Package\PackageInterface;
77
use Composer\Util\Filesystem;
8+
use React\Promise\PromiseInterface;
89

910
/**
1011
* SiteProfileInstaller class
@@ -35,21 +36,32 @@ public function supports($packageType)
3536
*/
3637
public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
3738
{
38-
parent::install($repo, $package);
39-
4039
// check if there's a nested site- prefixed directory, in which case we
4140
// must assume that it's the real site profile directory and move it up
4241
// one level
43-
$path = $this->getInstallPath($package);
44-
$site = $this->getNestedSiteDirectoryName($path);
45-
if ($site) {
46-
$basePath = $this->getBasePath(static::BASE_PATH);
47-
$tempPath = $basePath . 'temp-' . \basename($path);
48-
$filesystem = new Filesystem();
49-
$filesystem->rename($path, $tempPath);
50-
$filesystem->rename($tempPath . '/' . $site, $basePath . $site);
51-
$filesystem->remove($tempPath);
42+
$adjustProfilePath = function() use ($package) {
43+
$path = $this->getInstallPath($package);
44+
$site = $this->getNestedSiteDirectoryName($path);
45+
if ($site) {
46+
$basePath = $this->getBasePath(static::BASE_PATH);
47+
$tempPath = $basePath . 'temp-' . \basename($path);
48+
$filesystem = new Filesystem();
49+
$filesystem->rename($path, $tempPath);
50+
$filesystem->rename($tempPath . '/' . $site, $basePath . $site);
51+
$filesystem->remove($tempPath);
52+
}
53+
};
54+
55+
$promise = parent::install($repo, $package);
56+
57+
// Composer v2 might return a promise here
58+
if ($promise instanceof PromiseInterface) {
59+
return $promise->then($adjustProfilePath);
5260
}
61+
62+
// if not, execute the code right away as parent::install executed synchronously
63+
// (composer v1, or v2 without async)
64+
$adjustProfilePath();
5365
}
5466

5567
/**

0 commit comments

Comments
 (0)