Skip to content

Commit

Permalink
Make sure "roundcube/roundcubemail" install path is always available
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed May 3, 2024
1 parent 003a69c commit b43780e
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/ExtensionInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Roundcube\Composer;

use Composer\Installer\InstallationManager;
use Composer\Installer\LibraryInstaller;
use Composer\Package\PackageInterface;
use Composer\Package\Version\VersionParser;
Expand Down Expand Up @@ -43,15 +44,26 @@ protected function setRoundcubemailInstallPath(InstalledRepositoryInterface $ins

protected function getRoundcubemailInstallPath(): string
{
// install path is not set at composer download phase
// never assume any path, but for this known composer behaviour get it from backtrace instead
if ($this->roundcubemailInstallPath === null) {
$backtrace = debug_backtrace();
foreach ($backtrace as $frame) {
// relies on https://github.com/composer/composer/blob/2.7.4/src/Composer/Installer/InstallationManager.php#L243
if (($frame['object'] ?? null) instanceof InstallationManager
&& ($frame['function'] ?? null) === 'downloadAndExecuteBatch'

Check failure on line 54 in src/ExtensionInstaller.php

View workflow job for this annotation

GitHub Actions / Static Analysis

Offset 'function' on array{function: string, line?: int, file?: string, class?: class-string, type?: '->'|'::', args?: array, object: Composer\Installer\InstallationManager} on left side of ?? always exists and is not nullable.
) {
$this->setRoundcubemailInstallPath($frame['args'][0]);
}
}
}

return $this->roundcubemailInstallPath;
}

public function getInstallPath(PackageInterface $package)
{
if (
!$this->supports($package->getType())
|| $this->roundcubemailInstallPath === null // install path is not known at download phase
) {
if (!$this->supports($package->getType())) {
return parent::getInstallPath($package);
}

Expand Down

0 comments on commit b43780e

Please sign in to comment.