diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index a16e6b67b65c..734641d6d38d 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -720,6 +720,7 @@ protected function getPathCode(Filesystem $filesystem, string $basePath, string protected function getPlatformCheck(array $packageMap, $checkPlatform, array $devPackageNames) { $lowestPhpVersion = Bound::zero(); + $requiredPhp64bit = false; $requiredExtensions = []; $extensionProviders = []; @@ -744,13 +745,17 @@ protected function getPlatformCheck(array $packageMap, $checkPlatform, array $de continue; } - if ('php' === $link->getTarget()) { + if (in_array($link->getTarget(), ['php', 'php-64bit'], true)) { $constraint = $link->getConstraint(); if ($constraint->getLowerBound()->compareTo($lowestPhpVersion, '>')) { $lowestPhpVersion = $constraint->getLowerBound(); } } + if ('php-64bit' === $link->getTarget()) { + $requiredPhp64bit = true; + } + if ($checkPlatform === true && Preg::isMatch('{^ext-(.+)$}iD', $link->getTarget(), $match)) { // skip extension checks if they have a valid provider/replacer if (isset($extensionProviders[$match[1]])) { @@ -823,6 +828,16 @@ protected function getPlatformCheck(array $packageMap, $checkPlatform, array $de \$issues[] = 'Your Composer dependencies require a PHP version $requiredPhpError. You are running ' . PHP_VERSION . '.'; } +PHP_CHECK; + } + + if ($requiredPhp64bit) { + $requiredPhp .= << [ + [ + 'php-64bit' => new Link('a', 'php-64bit', $versionParser->parseConstraints('^7.2.8')), + ], + 'specific_php_64bit_required', + ], + '64-bit PHP required' => [ + [ + 'php-64bit' => new Link('a', 'php-64bit', $versionParser->parseConstraints('*')), + ], + 'php_64bit_required', + ], 'No PHP required' => [ [ 'ext-xml' => new Link('a', 'ext-xml', $versionParser->parseConstraints('*')), diff --git a/tests/Composer/Test/Autoload/Fixtures/platform/php_64bit_required.php b/tests/Composer/Test/Autoload/Fixtures/platform/php_64bit_required.php new file mode 100644 index 000000000000..fa023908ff1f --- /dev/null +++ b/tests/Composer/Test/Autoload/Fixtures/platform/php_64bit_required.php @@ -0,0 +1,26 @@ += 70208)) { + $issues[] = 'Your Composer dependencies require a PHP version ">= 7.2.8". You are running ' . PHP_VERSION . '.'; +} + +if (PHP_INT_SIZE !== 8) { + $issues[] = 'Your Composer dependencies require a 64-bit build of PHP.'; +} + +if ($issues) { + if (!headers_sent()) { + header('HTTP/1.1 500 Internal Server Error'); + } + if (!ini_get('display_errors')) { + if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') { + fwrite(STDERR, 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . implode(PHP_EOL, $issues) . PHP_EOL.PHP_EOL); + } elseif (!headers_sent()) { + echo 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . str_replace('You are running '.PHP_VERSION.'.', '', implode(PHP_EOL, $issues)) . PHP_EOL.PHP_EOL; + } + } + trigger_error( + 'Composer detected issues in your platform: ' . implode(' ', $issues), + E_USER_ERROR + ); +}