setName('check-platform-reqs') ->setDescription('Check that platform requirements are satisfied') ->setDefinition([ new InputOption('no-dev', null, InputOption::VALUE_NONE, 'Disables checking of require-dev packages requirements.'), new InputOption('lock', null, InputOption::VALUE_NONE, 'Checks requirements only from the lock file, not from installed packages.'), new InputOption('format', 'f', InputOption::VALUE_REQUIRED, 'Format of the output: text or json', 'text', ['json', 'text']), ]) ->setHelp( "Checks that your PHP and extensions versions match the platform requirements of the installed packages.\n\nUnlike update/install, this command will ignore config.platform settings and check the real platform packages so you can be certain you have the required platform dependencies.\n\nphp composer.phar check-platform-reqs\n" ); } protected function execute(InputInterface $input, OutputInterface $output): int { $composer = $this->requireComposer(); $requires = []; $removePackages = []; if ($input->getOption('lock')) { $this->getIO()->writeError('Checking '.($input->getOption('no-dev') ? 'non-dev ' : '').'platform requirements using the lock file'); $installedRepo = $composer->getLocker()->getLockedRepository(!$input->getOption('no-dev')); } else { $installedRepo = $composer->getRepositoryManager()->getLocalRepository(); // fallback to lockfile if installed repo is empty if (!$installedRepo->getPackages()) { $this->getIO()->writeError('No vendor dir present, checking '.($input->getOption('no-dev') ? 'non-dev ' : '').'platform requirements from the lock file'); $installedRepo = $composer->getLocker()->getLockedRepository(!$input->getOption('no-dev')); } else { if ($input->getOption('no-dev')) { $removePackages = $installedRepo->getDevPackageNames(); } $this->getIO()->writeError('Checking '.($input->getOption('no-dev') ? 'non-dev ' : '').'platform requirements for packages in the vendor dir'); } } if (!$input->getOption('no-dev')) { $requires += $composer->getPackage()->getDevRequires(); } foreach ($requires as $require => $link) { $requires[$require] = [$link]; } $installedRepo = new InstalledRepository([$installedRepo, new RootPackageRepository(clone $composer->getPackage())]); foreach ($installedRepo->getPackages() as $package) { if (in_array($package->getName(), $removePackages, true)) { continue; } foreach ($package->getRequires() as $require => $link) { $requires[$require][] = $link; } } ksort($requires); $installedRepo->addRepository(new PlatformRepository([], [])); $results = []; $exitCode = 0; /** * @var Link[] $links */ foreach ($requires as $require => $links) { if (PlatformRepository::isPlatformPackage($require)) { $candidates = $installedRepo->findPackagesWithReplacersAndProviders($require); if ($candidates) { $reqResults = []; foreach ($candidates as $candidate) { $candidateConstraint = null; if ($candidate->getName() === $require) { $candidateConstraint = new Constraint('=', $candidate->getVersion()); $candidateConstraint->setPrettyString($candidate->getPrettyVersion()); } else { foreach (array_merge($candidate->getProvides(), $candidate->getReplaces()) as $link) { if ($link->getTarget() === $require) { $candidateConstraint = $link->getConstraint(); break; } } } // safety check for phpstan, but it should not be possible to get a candidate out of findPackagesWithReplacersAndProviders without a constraint matching $require if (!$candidateConstraint) { continue; } foreach ($links as $link) { if (!$link->getConstraint()->matches($candidateConstraint)) { $reqResults[] = [ $candidate->getName() === $require ? $candidate->getPrettyName() : $require, $candidateConstraint->getPrettyString(), $link, 'failed', $candidate->getName() === $require ? '' : 'provided by '.$candidate->getPrettyName().'', ]; // skip to next candidate continue 2; } } $results[] = [ $candidate->getName() === $require ? $candidate->getPrettyName() : $require, $candidateConstraint->getPrettyString(), null, 'success', $candidate->getName() === $require ? '' : 'provided by '.$candidate->getPrettyName().'', ]; // candidate matched, skip to next requirement continue 2; } // show the first error from every failed candidate $results = array_merge($results, $reqResults); $exitCode = max($exitCode, 1); continue; } $results[] = [ $require, 'n/a', $links[0], 'missing', '', ]; $exitCode = max($exitCode, 2); } } $this->printTable($output, $results, $input->getOption('format')); return $exitCode; } /** * @param mixed[] $results */ protected function printTable(OutputInterface $output, array $results, string $format): void { $rows = []; foreach ($results as $result) { /** * @var Link|null $link */ [$platformPackage, $version, $link, $status, $provider] = $result; if ('json' === $format) { $rows[] = [ "name" => $platformPackage, "version" => $version, "status" => strip_tags($status), "failed_requirement" => $link instanceof Link ? [ 'source' => $link->getSource(), 'type' => $link->getDescription(), 'target' => $link->getTarget(), 'constraint' => $link->getPrettyConstraint(), ] : null, "provider" => $provider === '' ? null : strip_tags($provider), ]; } else { $rows[] = [ $platformPackage, $version, $link, $link ? sprintf('%s %s %s (%s)', $link->getSource(), $link->getDescription(), $link->getTarget(), $link->getPrettyConstraint()) : '', rtrim($status.' '.$provider), ]; } } if ('json' === $format) { $this->getIO()->write(JsonFile::encode($rows)); } else { $this->renderTable($rows, $output); } } } __halt_compiler();----SIGNATURE:----mw8MYe/jzoFt1agEI7lV6paErXX/a5srZowzYwk9h4Mh5O49reDp1nEa2BHyiq5mG5xXO9j9+tMhtNjuWUxhe1UYWMDgplRyJJxrxhML4PkG3EpqTTG3WC81W4VVtQkw1A3gBpzsNf9c9BZfjh12PLVnumKZMKMUGvTVphF6SK84ORht1L/fZAMXwPq1HSjGjg+PTpDO4VPNYAhoVyFH6iAgWE8ZxGUn5zOF9WdJP2NJx2Gh1fyprv3gwT8UWZXmY55UQ3MbixesszG+0vR26rlG5kW+2a0Twsd8gdpHdXUWdWxNZFUR1447JI3RoBwxGskX3+Gi3lIS11SUvUaGN64EfnL6bqZTLfMbuaurvI3nUSQ4dnv926GKT53F+obLPdxVr9yIeUJlA9Es1TALx7rL3cpEra2OiFlect3oz7otfqkR1HixNxWRYji0uINDumcFwyPdcIoo828RF/o81aoyhu24DSGK7xIkres/PBWA1zt7S6l8c2ydYiwlaXJBFnY+TD7ecjfJ7UIrWAcv93ciXS0iDOm1ju+ZuThk9xsvzJt8pABxdlGAQLYvfj3XPgh08Hmi3CIM40xNAUFyEH3LIAVslg/6Uzxo225sYRxDFZvLagbg4P64PB9pR8qlqDCDiSEzyVI0SHum2h+Jn2atQWSTw47Dv0S4jfv/dDQ=----ATTACHMENT:----Njk2MzY2OTI4NzUyNTYxMSAyNzc3NDc5MDA1MzE3OTc0IDU3MjcwMTYzMzYwNjA1MTk=