Skip to content

Commit de87a3c

Browse files
committed
Make sure "roundcube/roundcubemail" install path is always available
1 parent 003a69c commit de87a3c

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
],
2020
"require": {
2121
"php": ">=7.3 <8.4",
22-
"composer-plugin-api": "^1.0 || ^2.0",
22+
"composer-plugin-api": "^2.1",
2323
"roundcube/roundcubemail": "*"
2424
},
2525
"require-dev": {
26-
"composer/composer": "^2.0",
26+
"composer/composer": "^2.1",
2727
"ergebnis/composer-normalize": "^2.13",
2828
"friendsofphp/php-cs-fixer": "^3.0",
2929
"phpstan/extension-installer": "^1.1",

src/ExtensionInstaller.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Roundcube\Composer;
44

5+
use Composer\Installer\InstallationManager;
56
use Composer\Installer\LibraryInstaller;
67
use Composer\Package\PackageInterface;
78
use Composer\Package\Version\VersionParser;
@@ -43,15 +44,26 @@ protected function setRoundcubemailInstallPath(InstalledRepositoryInterface $ins
4344

4445
protected function getRoundcubemailInstallPath(): string
4546
{
47+
// install path is not set at composer download phase
48+
// never assume any path, but for this known composer behaviour get it from backtrace instead
49+
if ($this->roundcubemailInstallPath === null) {
50+
$backtrace = debug_backtrace();
51+
foreach ($backtrace as $frame) {
52+
// relies on https://github.com/composer/composer/blob/2.7.4/src/Composer/Installer/InstallationManager.php#L243
53+
if (($frame['object'] ?? null) instanceof InstallationManager
54+
&& $frame['function'] === 'downloadAndExecuteBatch'
55+
) {
56+
$this->setRoundcubemailInstallPath($frame['args'][0]);
57+
}
58+
}
59+
}
60+
4661
return $this->roundcubemailInstallPath;
4762
}
4863

4964
public function getInstallPath(PackageInterface $package)
5065
{
51-
if (
52-
!$this->supports($package->getType())
53-
|| $this->roundcubemailInstallPath === null // install path is not known at download phase
54-
) {
66+
if (!$this->supports($package->getType())) {
5567
return parent::getInstallPath($package);
5668
}
5769

0 commit comments

Comments
 (0)