From 3121b1923d0b2852bffee0bbb2c13a1598b864cd Mon Sep 17 00:00:00 2001 From: James Titcumb Date: Wed, 14 May 2025 11:45:36 +0200 Subject: [PATCH] Update show command to display if a PIE package is installed but not loaded into the target PHP --- src/Command/ShowCommand.php | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/Command/ShowCommand.php b/src/Command/ShowCommand.php index 37d93602..2bb5abdb 100644 --- a/src/Command/ShowCommand.php +++ b/src/Command/ShowCommand.php @@ -20,8 +20,11 @@ use Symfony\Component\Console\Output\NullOutput; use Symfony\Component\Console\Output\OutputInterface; +use function array_diff; use function array_key_exists; +use function array_keys; use function array_walk; +use function count; use function file_exists; use function sprintf; use function substr; @@ -88,6 +91,7 @@ public function execute(InputInterface $input, OutputInterface $output): int $phpEnabledExtensions = $targetPlatform->phpBinaryPath->extensions(); $extensionPath = $targetPlatform->phpBinaryPath->extensionPath(); $extensionEnding = $targetPlatform->operatingSystem === OperatingSystem::Windows ? '.dll' : '.so'; + $piePackagesMatched = []; $output->writeln(sprintf( "\n" . '%s:', @@ -95,7 +99,7 @@ public function execute(InputInterface $input, OutputInterface $output): int )); array_walk( $phpEnabledExtensions, - static function (string $version, string $phpExtensionName) use ($showAll, $output, $piePackages, $extensionPath, $extensionEnding): void { + static function (string $version, string $phpExtensionName) use ($showAll, $output, $piePackages, $extensionPath, $extensionEnding, &$piePackagesMatched): void { if (! array_key_exists($phpExtensionName, $piePackages)) { if ($showAll) { $output->writeln(sprintf(' %s:%s', $phpExtensionName, $version)); @@ -104,7 +108,8 @@ static function (string $version, string $phpExtensionName) use ($showAll, $outp return; } - $piePackage = $piePackages[$phpExtensionName]; + $piePackage = $piePackages[$phpExtensionName]; + $piePackagesMatched[] = $phpExtensionName; $output->writeln(sprintf( ' %s:%s (from 🥧 %s%s)', @@ -121,6 +126,21 @@ static function (string $version, string $phpExtensionName) use ($showAll, $outp }, ); + if (! $showAll && ! count($piePackagesMatched)) { + $output->writeln('(none)'); + } + + $unmatchedPiePackages = array_diff(array_keys($piePackages), $piePackagesMatched); + + if (count($unmatchedPiePackages)) { + $output->writeln("\n" . ' ⚠️ PIE packages not loaded:'); + $output->writeln('These extensions were installed with PIE but are not currently enabled.' . "\n"); + + foreach ($unmatchedPiePackages as $unmatchedPiePackage) { + $output->writeln(sprintf(' - %s', $piePackages[$unmatchedPiePackage]->prettyNameAndVersion())); + } + } + return Command::SUCCESS; }