34 lines
1.1 KiB
PHP
34 lines
1.1 KiB
PHP
<?php
|
|
|
|
/*
|
|
* Laravel 5.6's PackageManifest predates Composer 2. Composer 2 stores the
|
|
* installed package list under a "packages" key, which makes Laravel's
|
|
* package:discover command fail with "Undefined index: name".
|
|
*
|
|
* This script adds support for both formats to the vendored framework file.
|
|
* Composer runs it before package:discover, so it is safe to run repeatedly.
|
|
*/
|
|
|
|
$file = __DIR__.'/../vendor/laravel/framework/src/Illuminate/Foundation/PackageManifest.php';
|
|
|
|
if (! file_exists($file)) {
|
|
fwrite(STDERR, "PackageManifest.php not found; skipping Composer 2 patch.\n");
|
|
exit(0);
|
|
}
|
|
|
|
$contents = file_get_contents($file);
|
|
|
|
if (strpos($contents, "\$packages = \$packages['packages'] ?? \$packages;") !== false) {
|
|
exit(0);
|
|
}
|
|
|
|
$needle = '$packages = json_decode($this->files->get($path), true);';
|
|
$replacement = $needle."\n\n \$packages = \$packages['packages'] ?? \$packages;";
|
|
|
|
if (strpos($contents, $needle) === false) {
|
|
fwrite(STDERR, "Could not find PackageManifest build() snippet; skipping patch.\n");
|
|
exit(0);
|
|
}
|
|
|
|
file_put_contents($file, str_replace($needle, $replacement, $contents));
|