Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/Composer/Autoload/AutoloadGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand All @@ -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]])) {
Expand Down Expand Up @@ -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_CHECK

if (PHP_INT_SIZE !== 8) {
\$issues[] = 'Your Composer dependencies require a 64-bit build of PHP.';
}

PHP_CHECK;
}

Expand Down
12 changes: 12 additions & 0 deletions tests/Composer/Test/Autoload/AutoloadGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1861,6 +1861,18 @@ public static function platformCheckProvider(): array
],
'specific_php_release',
],
'Specific 64-bit PHP version' => [
[
'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('*')),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

// platform_check.php @generated by Composer

$issues = array();

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
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

// platform_check.php @generated by Composer

$issues = array();

if (!(PHP_VERSION_ID >= 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
);
}