From afc0fae9664cf3897d0d8421dab6cc8c7f9f452c Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Tue, 21 Apr 2020 15:47:58 +0200 Subject: [PATCH] Add compatiblity with Composer 2.0 - The structure of vendor/composer/installed.json will change. - The same file will now contain the relative path to package locations. References: - https://github.com/composer/composer/blob/master/UPGRADE-2.0.md - https://php.watch/articles/composer-2 --- framework/core/src/Extension/ExtensionManager.php | 10 +++++++++- .../src/Install/Steps/EnableBundledExtensions.php | 12 ++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/framework/core/src/Extension/ExtensionManager.php b/framework/core/src/Extension/ExtensionManager.php index 7ac0f9a90..e9aaed950 100644 --- a/framework/core/src/Extension/ExtensionManager.php +++ b/framework/core/src/Extension/ExtensionManager.php @@ -73,12 +73,20 @@ class ExtensionManager // Load all packages installed by composer. $installed = json_decode($this->filesystem->get($this->app->vendorPath().'/composer/installed.json'), true); + // Composer 2.0 changes the structure of the installed.json manifest + $installed = $installed['packages'] ?? $installed; + foreach ($installed as $package) { if (Arr::get($package, 'type') != 'flarum-extension' || empty(Arr::get($package, 'name'))) { continue; } + + $path = isset($package['install-path']) + ? $this->getExtensionsDir().'/composer/'.$package['install-path'] + : $this->getExtensionsDir().'/'.Arr::get($package, 'name'); + // Instantiates an Extension object using the package path and composer.json file. - $extension = new Extension($this->getExtensionsDir().'/'.Arr::get($package, 'name'), $package); + $extension = new Extension($path, $package); // Per default all extensions are installed if they are registered in composer. $extension->setInstalled(true); diff --git a/framework/core/src/Install/Steps/EnableBundledExtensions.php b/framework/core/src/Install/Steps/EnableBundledExtensions.php index 33d448906..14167e527 100644 --- a/framework/core/src/Install/Steps/EnableBundledExtensions.php +++ b/framework/core/src/Install/Steps/EnableBundledExtensions.php @@ -89,14 +89,22 @@ class EnableBundledExtensions implements Step private function loadExtensions() { $json = file_get_contents("$this->vendorPath/composer/installed.json"); + $installed = json_decode($json, true); - return (new Collection(json_decode($json, true))) + // Composer 2.0 changes the structure of the installed.json manifest + $installed = $installed['packages'] ?? $installed; + + return (new Collection($installed)) ->filter(function ($package) { return Arr::get($package, 'type') == 'flarum-extension'; })->filter(function ($package) { return ! empty(Arr::get($package, 'name')); })->map(function ($package) { - $extension = new Extension($this->vendorPath.'/'.Arr::get($package, 'name'), $package); + $path = isset($package['install-path']) + ? "$this->vendorPath/composer/".$package['install-path'] + : $this->vendorPath.'/'.Arr::get($package, 'name'); + + $extension = new Extension($path, $package); $extension->setVersion(Arr::get($package, 'version')); return $extension;