diff --git a/src/Command/InfoCommand.php b/src/Command/InfoCommand.php index d31c9a36..95d382ce 100644 --- a/src/Command/InfoCommand.php +++ b/src/Command/InfoCommand.php @@ -4,6 +4,8 @@ namespace Php\Pie\Command; +use Composer\Semver\Constraint\Constraint; +use Php\Pie\ComposerIntegration\PhpBinaryPathBasedPlatformRepository; use Php\Pie\ComposerIntegration\PieComposerFactory; use Php\Pie\ComposerIntegration\PieComposerRequest; use Php\Pie\ComposerIntegration\PieOperation; @@ -12,13 +14,18 @@ use Php\Pie\DependencyResolver\InvalidPackageName; use Php\Pie\DependencyResolver\UnableToResolveRequirement; use Php\Pie\Installing\InstallForPhpProject\FindMatchingPackages; +use Php\Pie\Platform\InstalledPiePackages; +use Php\Pie\Platform\ThreadSafetyMode; +use Php\Pie\Util\Emoji; 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\Output\OutputInterface; +use function array_key_exists; use function count; +use function in_array; use function sprintf; #[AsCommand( @@ -78,7 +85,7 @@ public function execute(InputInterface $input, OutputInterface $output): int $composer, $targetPlatform, $requestedNameAndVersion, - CommandHelper::determineForceInstallingPackageVersion($input), + true, ); } catch (UnableToResolveRequirement $unableToResolveRequirement) { return CommandHelper::handlePackageNotFound( @@ -102,14 +109,57 @@ public function execute(InputInterface $input, OutputInterface $output): int $output->writeln(sprintf('Composer package name: %s', $package->name())); $output->writeln(sprintf('Version: %s', $package->version())); $output->writeln(sprintf('Download URL: %s', $package->downloadUrl() ?? '(not specified)')); + $output->writeln(sprintf( + 'TS/NTS: %s', + ($targetPlatform->threadSafety === ThreadSafetyMode::NonThreadSafe && ! $package->supportNts()) + || ($targetPlatform->threadSafety === ThreadSafetyMode::ThreadSafe && ! $package->supportZts()) ? sprintf('%s (not supported on %s)', Emoji::PROHIBITED, $targetPlatform->threadSafety->asShort()) : Emoji::GREEN_CHECKMARK, + )); + + $output->writeln(sprintf( + 'OS: %s', + ($package->compatibleOsFamilies() === null || in_array($targetPlatform->operatingSystemFamily, $package->compatibleOsFamilies(), true)) + && ($package->incompatibleOsFamilies() === null || ! in_array($targetPlatform->operatingSystemFamily, $package->incompatibleOsFamilies(), true)) + ? Emoji::GREEN_CHECKMARK + : sprintf('%s (not supported on %s)', Emoji::PROHIBITED, $targetPlatform->operatingSystemFamily->value), + )); + + $output->writeln("\nDependencies:"); + $requires = $package->composerPackage()->getRequires(); + + if (count($requires) > 0) { + /** @var array> $platformConstraints */ + $platformConstraints = []; + $composerPlatform = new PhpBinaryPathBasedPlatformRepository($targetPlatform->phpBinaryPath, $composer, new InstalledPiePackages(), null); + foreach ($composerPlatform->getPackages() as $platformPackage) { + $platformConstraints[$platformPackage->getName()][] = new Constraint('==', $platformPackage->getPrettyVersion()); + } + + foreach ($requires as $requireName => $requireLink) { + $packageStatus = sprintf(' %s: %s %%s', $requireName, $requireLink->getConstraint()->getPrettyString()); + if (! array_key_exists($requireName, $platformConstraints)) { + $output->writeln(sprintf($packageStatus, Emoji::PROHIBITED . ' (not installed)')); + continue; + } + + foreach ($platformConstraints[$requireName] as $constraint) { + if ($requireLink->getConstraint()->matches($constraint)) { + $output->writeln(sprintf($packageStatus, Emoji::GREEN_CHECKMARK)); + } else { + $output->writeln(sprintf($packageStatus, Emoji::PROHIBITED . ' (your version is ' . $constraint->getVersion() . ')')); + } + } + } + } else { + $output->writeln(' No dependencies.'); + } + $output->writeln("\nConfigure options:"); if (count($package->configureOptions())) { - $output->writeln('Configure options:'); foreach ($package->configureOptions() as $configureOption) { $output->writeln(sprintf(' --%s%s (%s)', $configureOption->name, $configureOption->needsValue ? '=?' : '', $configureOption->description)); } } else { - $output->writeln('No configure options are specified.'); + $output->writeln(' No configure options are specified.'); } return Command::SUCCESS; diff --git a/src/DependencyResolver/ResolveDependencyWithComposer.php b/src/DependencyResolver/ResolveDependencyWithComposer.php index 2eb46309..7546d32d 100644 --- a/src/DependencyResolver/ResolveDependencyWithComposer.php +++ b/src/DependencyResolver/ResolveDependencyWithComposer.php @@ -66,8 +66,11 @@ public function __invoke( $piePackage = Package::fromComposerCompletePackage($package); $this->assertBuildProviderProvidersBundledExtensions($targetPlatform, $piePackage, $forceInstallPackageVersion); - $this->assertCompatibleOsFamily($targetPlatform, $piePackage); - $this->assertCompatibleThreadSafetyMode($targetPlatform->threadSafety, $piePackage); + + if (! $forceInstallPackageVersion) { + $this->assertCompatibleOsFamily($targetPlatform, $piePackage); + $this->assertCompatibleThreadSafetyMode($targetPlatform->threadSafety, $piePackage); + } return $piePackage; }