Skip to content

Commit

Permalink
add autoloads in PHP instead of using JQ,
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
clemzarch committed Aug 17, 2023
1 parent 3c5e39f commit a10bc39
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/Adapter/Composer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a10bc39

Please sign in to comment.