Skip to content

Commit 2c36dce

Browse files
authored
Merge pull request #245 from asgrim/show-pie-packages-not-enabled
Show command display PIE packages installed but not loaded in target PHP
2 parents 374722c + 3121b19 commit 2c36dce

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/Command/ShowCommand.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@
2020
use Symfony\Component\Console\Output\NullOutput;
2121
use Symfony\Component\Console\Output\OutputInterface;
2222

23+
use function array_diff;
2324
use function array_key_exists;
25+
use function array_keys;
2426
use function array_walk;
27+
use function count;
2528
use function file_exists;
2629
use function sprintf;
2730
use function substr;
@@ -88,14 +91,15 @@ public function execute(InputInterface $input, OutputInterface $output): int
8891
$phpEnabledExtensions = $targetPlatform->phpBinaryPath->extensions();
8992
$extensionPath = $targetPlatform->phpBinaryPath->extensionPath();
9093
$extensionEnding = $targetPlatform->operatingSystem === OperatingSystem::Windows ? '.dll' : '.so';
94+
$piePackagesMatched = [];
9195

9296
$output->writeln(sprintf(
9397
"\n" . '<options=bold,underscore>%s:</>',
9498
$showAll ? 'All loaded extensions' : 'Loaded PIE extensions',
9599
));
96100
array_walk(
97101
$phpEnabledExtensions,
98-
static function (string $version, string $phpExtensionName) use ($showAll, $output, $piePackages, $extensionPath, $extensionEnding): void {
102+
static function (string $version, string $phpExtensionName) use ($showAll, $output, $piePackages, $extensionPath, $extensionEnding, &$piePackagesMatched): void {
99103
if (! array_key_exists($phpExtensionName, $piePackages)) {
100104
if ($showAll) {
101105
$output->writeln(sprintf(' <comment>%s:%s</comment>', $phpExtensionName, $version));
@@ -104,7 +108,8 @@ static function (string $version, string $phpExtensionName) use ($showAll, $outp
104108
return;
105109
}
106110

107-
$piePackage = $piePackages[$phpExtensionName];
111+
$piePackage = $piePackages[$phpExtensionName];
112+
$piePackagesMatched[] = $phpExtensionName;
108113

109114
$output->writeln(sprintf(
110115
' <info>%s:%s</info> (from 🥧 <info>%s</info>%s)',
@@ -121,6 +126,21 @@ static function (string $version, string $phpExtensionName) use ($showAll, $outp
121126
},
122127
);
123128

129+
if (! $showAll && ! count($piePackagesMatched)) {
130+
$output->writeln('(none)');
131+
}
132+
133+
$unmatchedPiePackages = array_diff(array_keys($piePackages), $piePackagesMatched);
134+
135+
if (count($unmatchedPiePackages)) {
136+
$output->writeln("\n" . ' ⚠️ <options=bold,underscore>PIE packages not loaded:</>');
137+
$output->writeln('These extensions were installed with PIE but are not currently enabled.' . "\n");
138+
139+
foreach ($unmatchedPiePackages as $unmatchedPiePackage) {
140+
$output->writeln(sprintf(' - %s', $piePackages[$unmatchedPiePackage]->prettyNameAndVersion()));
141+
}
142+
}
143+
124144
return Command::SUCCESS;
125145
}
126146

0 commit comments

Comments
 (0)