Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions src/PHP/ComposerAutoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,39 @@ private static function pipe(string ...$commands): string
return implode(' | ', $commands);
}

private static function indirection(string $command, string $destination): string
{
return $command . ' > ' . self::escapeArgument($destination);
}

private static function and(string ...$commands): string
{
return implode(' \\'.\PHP_EOL.' && ', $commands);
}

public function __toString(): string
{
if (\count($this->autoloads) <= 0) {
return '';
}

$commands = implode(' \\'.\PHP_EOL.' && ', array_map(fn ($type, $autoload) => match ($type) {
'psr4' => self::pipe(
self::command('cat', 'composer.json'),
self::command('jq', '--indent', '4', sprintf('.autoload."psr-4" |= . + %s', json_encode($autoload, \JSON_THROW_ON_ERROR))),
self::command('tee', 'composer.json')
$commands = self::and(
...array_map(
fn ($type, $autoload) => match ($type) {
'psr4' => self::and(
self::pipe(
self::command('cat', 'composer.json'),
self::command('jq', '--indent', '4', sprintf('.autoload."psr-4" |= . + %s', json_encode($autoload, \JSON_THROW_ON_ERROR))),
self::command('tee', 'composer.temp')
),
self::indirection(self::command('cat', 'composer.temp'), 'composer.json'),
self::command('rm', 'composer.temp'),
)
},
array_keys($this->autoloads),
array_values($this->autoloads)
)
}, array_keys($this->autoloads), array_values($this->autoloads)));
);

return (string) new Dockerfile\Run(
<<<RUN
Expand Down