Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
36 changes: 33 additions & 3 deletions src/Command/ShowCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
use Php\Pie\ComposerIntegration\PieInstalledJsonMetadataKeys;
use Php\Pie\File\BinaryFile;
use Php\Pie\File\BinaryFileFailedVerification;
use Php\Pie\Platform as PiePlatform;
use Php\Pie\Platform\InstalledPiePackages;
use Php\Pie\Platform\OperatingSystem;
use Psr\Container\ContainerInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Output\OutputInterface;

Expand All @@ -33,6 +35,8 @@
)]
final class ShowCommand extends Command
{
private const OPTION_ALL = 'all';

public function __construct(
private readonly InstalledPiePackages $installedPiePackages,
private readonly ContainerInterface $container,
Expand All @@ -45,12 +49,33 @@ public function configure(): void
parent::configure();

CommandHelper::configurePhpConfigOptions($this);

$this->addOption(
self::OPTION_ALL,
null,
InputOption::VALUE_NONE,
'Show all extensions for the target PHP installation, even those PIE does not manage.',
);
}

public function execute(InputInterface $input, OutputInterface $output): int
{
$showAll = $input->hasOption(self::OPTION_ALL) && $input->getOption(self::OPTION_ALL);
$targetPlatform = CommandHelper::determineTargetPlatformFromInputs($input, $output);

if ($output->getVerbosity() < OutputInterface::VERBOSITY_VERBOSE) {
$output->writeln(
sprintf(
'<info>Using pie.json:</info> %s',
PiePlatform::getPieJsonFilename($targetPlatform),
),
);
}

if (! $showAll) {
$output->writeln('Tip: to include extensions in this list that PIE does not manage, use the --all flag.');
}

$composer = PieComposerFactory::createPieComposer(
$this->container,
PieComposerRequest::noOperation(
Expand All @@ -64,12 +89,17 @@ public function execute(InputInterface $input, OutputInterface $output): int
$extensionPath = $targetPlatform->phpBinaryPath->extensionPath();
$extensionEnding = $targetPlatform->operatingSystem === OperatingSystem::Windows ? '.dll' : '.so';

$output->writeln("\n" . '<info>Loaded extensions:</info>');
$output->writeln(sprintf(
"\n" . '<options=bold,underscore>%s:</>',
$showAll ? 'All loaded extensions' : 'Loaded PIE extensions',
));
array_walk(
$phpEnabledExtensions,
static function (string $version, string $phpExtensionName) use ($output, $piePackages, $extensionPath, $extensionEnding): void {
static function (string $version, string $phpExtensionName) use ($showAll, $output, $piePackages, $extensionPath, $extensionEnding): void {
if (! array_key_exists($phpExtensionName, $piePackages)) {
$output->writeln(sprintf(' <comment>%s:%s</comment>', $phpExtensionName, $version));
if ($showAll) {
$output->writeln(sprintf(' <comment>%s:%s</comment>', $phpExtensionName, $version));
}

return;
}
Expand Down
2 changes: 1 addition & 1 deletion test/integration/Command/ShowCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function setUp(): void

public function testExecute(): void
{
$this->commandTester->execute([]);
$this->commandTester->execute(['--all' => true]);

$this->commandTester->assertCommandIsSuccessful();

Expand Down