mirror of
https://github.com/flarum/core.git
synced 2025-07-18 07:11:17 +02:00
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
This commit is contained in:
@@ -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);
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user