From a10bc39bda9dd5c52285ab0a0eab129656404b3e Mon Sep 17 00:00:00 2001 From: clementzarch Date: Wed, 16 Aug 2023 12:04:01 +0200 Subject: [PATCH] add autoloads in PHP instead of using JQ, immediately require php:^8.2 after init, so that the "require" key in composer.json is not empty (otherwise json_encode() incorrectly converts it into an empty array) --- src/Adapter/Composer.php | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/Adapter/Composer.php b/src/Adapter/Composer.php index ad01e8d4..83390fd3 100644 --- a/src/Adapter/Composer.php +++ b/src/Adapter/Composer.php @@ -129,6 +129,7 @@ public function init(string $name): void 'init', '--no-interaction', sprintf('--name=%s', $name), + '--require=php:^8.2', ); $this->allowPlugins('php-http/discovery'); @@ -163,20 +164,14 @@ public function denyPlugins(string ...$plugins): void */ public function autoload(array $autoloads): void { + $composer = json_decode(file_get_contents($this->workdir.'/composer.json'), true, 512, \JSON_THROW_ON_ERROR); foreach ($autoloads as $type => $autoload) { match ($type) { - 'psr4' => $this->pipe( - $this->subcommand('cat', 'composer.json'), - $this->subcommand('jq', '--indent', '4', sprintf('.autoload."psr-4" |= . + %s', json_encode($autoload, \JSON_THROW_ON_ERROR))), - $this->subcommand('tee', 'composer.json'), - ), - 'file' => $this->pipe( - $this->subcommand('cat', 'composer.json'), - $this->subcommand('jq', '--indent', '4', sprintf('.autoload."file" |= . + %s', json_encode($autoload, \JSON_THROW_ON_ERROR))), - $this->subcommand('tee', 'composer.json'), - ) + 'psr4' => $composer['autoload']['psr-4'] = $autoload, + 'file' => $composer['autoload']['file'] = $autoload, }; } + file_put_contents($this->workdir.'/composer.json', json_encode($composer, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES)); } public function install(): void