44
55namespace Php \Pie \Command ;
66
7+ use Composer \Semver \Constraint \Constraint ;
8+ use Php \Pie \ComposerIntegration \PhpBinaryPathBasedPlatformRepository ;
79use Php \Pie \ComposerIntegration \PieComposerFactory ;
810use Php \Pie \ComposerIntegration \PieComposerRequest ;
911use Php \Pie \ComposerIntegration \PieOperation ;
1214use Php \Pie \DependencyResolver \InvalidPackageName ;
1315use Php \Pie \DependencyResolver \UnableToResolveRequirement ;
1416use Php \Pie \Installing \InstallForPhpProject \FindMatchingPackages ;
17+ use Php \Pie \Platform \InstalledPiePackages ;
18+ use Php \Pie \Platform \ThreadSafetyMode ;
19+ use Php \Pie \Util \Emoji ;
1520use Psr \Container \ContainerInterface ;
1621use Symfony \Component \Console \Attribute \AsCommand ;
1722use Symfony \Component \Console \Command \Command ;
1823use Symfony \Component \Console \Input \InputInterface ;
1924use Symfony \Component \Console \Output \OutputInterface ;
2025
26+ use function array_key_exists ;
2127use function count ;
28+ use function in_array ;
2229use function sprintf ;
2330
2431#[AsCommand(
@@ -78,7 +85,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
7885 $ composer ,
7986 $ targetPlatform ,
8087 $ requestedNameAndVersion ,
81- CommandHelper:: determineForceInstallingPackageVersion ( $ input ) ,
88+ true ,
8289 );
8390 } catch (UnableToResolveRequirement $ unableToResolveRequirement ) {
8491 return CommandHelper::handlePackageNotFound (
@@ -102,14 +109,57 @@ public function execute(InputInterface $input, OutputInterface $output): int
102109 $ output ->writeln (sprintf ('Composer package name: %s ' , $ package ->name ()));
103110 $ output ->writeln (sprintf ('Version: %s ' , $ package ->version ()));
104111 $ output ->writeln (sprintf ('Download URL: %s ' , $ package ->downloadUrl () ?? '(not specified) ' ));
112+ $ output ->writeln (sprintf (
113+ 'TS/NTS: %s ' ,
114+ ($ targetPlatform ->threadSafety === ThreadSafetyMode::NonThreadSafe && ! $ package ->supportNts ())
115+ || ($ targetPlatform ->threadSafety === ThreadSafetyMode::ThreadSafe && ! $ package ->supportZts ()) ? sprintf ('%s (not supported on %s) ' , Emoji::PROHIBITED , $ targetPlatform ->threadSafety ->asShort ()) : Emoji::GREEN_CHECKMARK ,
116+ ));
117+
118+ $ output ->writeln (sprintf (
119+ 'OS: %s ' ,
120+ ($ package ->compatibleOsFamilies () === null || in_array ($ targetPlatform ->operatingSystemFamily , $ package ->compatibleOsFamilies (), true ))
121+ && ($ package ->incompatibleOsFamilies () === null || ! in_array ($ targetPlatform ->operatingSystemFamily , $ package ->incompatibleOsFamilies (), true ))
122+ ? Emoji::GREEN_CHECKMARK
123+ : sprintf ('%s (not supported on %s) ' , Emoji::PROHIBITED , $ targetPlatform ->operatingSystemFamily ->value ),
124+ ));
125+
126+ $ output ->writeln ("\n<options=bold,underscore>Dependencies:</> " );
127+ $ requires = $ package ->composerPackage ()->getRequires ();
128+
129+ if (count ($ requires ) > 0 ) {
130+ /** @var array<string, list<Constraint>> $platformConstraints */
131+ $ platformConstraints = [];
132+ $ composerPlatform = new PhpBinaryPathBasedPlatformRepository ($ targetPlatform ->phpBinaryPath , $ composer , new InstalledPiePackages (), null );
133+ foreach ($ composerPlatform ->getPackages () as $ platformPackage ) {
134+ $ platformConstraints [$ platformPackage ->getName ()][] = new Constraint ('== ' , $ platformPackage ->getPrettyVersion ());
135+ }
136+
137+ foreach ($ requires as $ requireName => $ requireLink ) {
138+ $ packageStatus = sprintf (' %s: %s %%s ' , $ requireName , $ requireLink ->getConstraint ()->getPrettyString ());
139+ if (! array_key_exists ($ requireName , $ platformConstraints )) {
140+ $ output ->writeln (sprintf ($ packageStatus , Emoji::PROHIBITED . ' (not installed) ' ));
141+ continue ;
142+ }
143+
144+ foreach ($ platformConstraints [$ requireName ] as $ constraint ) {
145+ if ($ requireLink ->getConstraint ()->matches ($ constraint )) {
146+ $ output ->writeln (sprintf ($ packageStatus , Emoji::GREEN_CHECKMARK ));
147+ } else {
148+ $ output ->writeln (sprintf ($ packageStatus , Emoji::PROHIBITED . ' (your version is ' . $ constraint ->getVersion () . ') ' ));
149+ }
150+ }
151+ }
152+ } else {
153+ $ output ->writeln (' No dependencies. ' );
154+ }
105155
156+ $ output ->writeln ("\n<options=bold,underscore>Configure options:</> " );
106157 if (count ($ package ->configureOptions ())) {
107- $ output ->writeln ('Configure options: ' );
108158 foreach ($ package ->configureOptions () as $ configureOption ) {
109159 $ output ->writeln (sprintf (' --%s%s (%s) ' , $ configureOption ->name , $ configureOption ->needsValue ? '=? ' : '' , $ configureOption ->description ));
110160 }
111161 } else {
112- $ output ->writeln ('No configure options are specified. ' );
162+ $ output ->writeln (' No configure options are specified. ' );
113163 }
114164
115165 return Command::SUCCESS ;
0 commit comments