Skip to content

Commit

Permalink
Merge pull request #121 from php-etl/fix/autoloads
Browse files Browse the repository at this point in the history
add autoloads with PHP instead of using JQ
  • Loading branch information
clemzarch authored Aug 21, 2023
2 parents 3c5e39f + a10bc39 commit e65c423
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 e65c423

Please sign in to comment.