1
0
Fork 0

Optimize extension checks

pull/8812/head
Nicolas Grekas 2020-04-21 09:35:34 +02:00
parent e23710f92d
commit 6463ab9e49
7 changed files with 32 additions and 56 deletions

View File

@ -591,13 +591,13 @@ EOF;
} }
if (preg_match('{^ext-(.+)$}iD', $link->getTarget(), $match)) { if (preg_match('{^ext-(.+)$}iD', $link->getTarget(), $match)) {
$requiredExtensions[] = $match[1]; $extension = var_export($match[1], true);
$requiredExtensions[$extension] = "extension_loaded($extension) || \$missingExtensions[] = $extension;\n";
} }
} }
} }
$requiredExtensions = array_values(array_unique($requiredExtensions)); ksort($requiredExtensions);
sort($requiredExtensions);
$formatToPhpVersionId = function (Bound $bound) { $formatToPhpVersionId = function (Bound $bound) {
if ($bound->isZero()) { if ($bound->isZero()) {
@ -634,7 +634,19 @@ EOF;
$highestPhpVersionId = $formatToPhpVersionId($highestPhpVersion); $highestPhpVersionId = $formatToPhpVersionId($highestPhpVersion);
$lowestPhpVersion = $formatToHumanReadable($lowestPhpVersion); $lowestPhpVersion = $formatToHumanReadable($lowestPhpVersion);
$highestPhpVersion = $formatToHumanReadable($highestPhpVersion); $highestPhpVersion = $formatToHumanReadable($highestPhpVersion);
$requiredExtensions = var_export($requiredExtensions, true); $requiredExtensions = implode('', $requiredExtensions);
if ('' !== $requiredExtensions) {
$requiredExtensions = <<<EXT_CHECKS
\$missingExtensions = array();
$requiredExtensions
if (\$missingExtensions) {
\$issues[] = 'Your Composer dependencies require the following PHP extensions to be installed: ' . implode(', ', \$missingExtensions);
}
EXT_CHECKS;
}
return <<<PLATFORM_CHECK return <<<PLATFORM_CHECK
<?php <?php
@ -646,14 +658,8 @@ EOF;
if (!(PHP_VERSION_ID $lowestOperator $lowestPhpVersionId && PHP_VERSION_ID $highestOperator $highestPhpVersionId)) { if (!(PHP_VERSION_ID $lowestOperator $lowestPhpVersionId && PHP_VERSION_ID $highestOperator $highestPhpVersionId)) {
\$issues[] = 'Your Composer dependencies require a PHP version "$lowestOperator $lowestPhpVersion" and "$highestOperator $highestPhpVersion". You are running ' . PHP_VERSION . '.'; \$issues[] = 'Your Composer dependencies require a PHP version "$lowestOperator $lowestPhpVersion" and "$highestOperator $highestPhpVersion". You are running ' . PHP_VERSION . '.';
} }
$requiredExtensions
\$missingExtensions = array_diff($requiredExtensions, array_map('strtolower', get_loaded_extensions())); if (\$issues) {
if (0 !== count(\$missingExtensions)) {
\$issues[] = 'Your Composer dependencies require the following PHP extensions to be installed: ' . implode(', ', \$missingExtensions);
}
if (0 !== count(\$issues)) {
die('Composer detected issues in your platform:' . "\\n\\n" . implode("\\n", \$issues)); die('Composer detected issues in your platform:' . "\\n\\n" . implode("\\n", \$issues));
} }

View File

@ -8,13 +8,6 @@ if (!(PHP_VERSION_ID >= 70200 && PHP_VERSION_ID < 80000)) {
$issues[] = 'Your Composer dependencies require a PHP version ">= 7.2.0" and "< 8.0.0". You are running ' . PHP_VERSION . '.'; $issues[] = 'Your Composer dependencies require a PHP version ">= 7.2.0" and "< 8.0.0". You are running ' . PHP_VERSION . '.';
} }
$missingExtensions = array_diff(array ( if ($issues) {
), array_map('strtolower', get_loaded_extensions()));
if (0 !== count($missingExtensions)) {
$issues[] = 'Your Composer dependencies require the following PHP extensions to be installed: ' . implode(', ', $missingExtensions);
}
if (0 !== count($issues)) {
die('Composer detected issues in your platform:' . "\n\n" . implode("\n", $issues)); die('Composer detected issues in your platform:' . "\n\n" . implode("\n", $issues));
} }

View File

@ -8,13 +8,6 @@ if (!(PHP_VERSION_ID >= 0 && PHP_VERSION_ID < 80000)) {
$issues[] = 'Your Composer dependencies require a PHP version ">= 0" and "< 8.0.0". You are running ' . PHP_VERSION . '.'; $issues[] = 'Your Composer dependencies require a PHP version ">= 0" and "< 8.0.0". You are running ' . PHP_VERSION . '.';
} }
$missingExtensions = array_diff(array ( if ($issues) {
), array_map('strtolower', get_loaded_extensions()));
if (0 !== count($missingExtensions)) {
$issues[] = 'Your Composer dependencies require the following PHP extensions to be installed: ' . implode(', ', $missingExtensions);
}
if (0 !== count($issues)) {
die('Composer detected issues in your platform:' . "\n\n" . implode("\n", $issues)); die('Composer detected issues in your platform:' . "\n\n" . implode("\n", $issues));
} }

View File

@ -8,15 +8,14 @@ if (!(PHP_VERSION_ID >= 0 && PHP_VERSION_ID < 99999)) {
$issues[] = 'Your Composer dependencies require a PHP version ">= 0" and "< 99999". You are running ' . PHP_VERSION . '.'; $issues[] = 'Your Composer dependencies require a PHP version ">= 0" and "< 99999". You are running ' . PHP_VERSION . '.';
} }
$missingExtensions = array_diff(array ( $missingExtensions = array();
0 => 'json', extension_loaded('json') || $missingExtensions[] = 'json';
1 => 'xml', extension_loaded('xml') || $missingExtensions[] = 'xml';
), array_map('strtolower', get_loaded_extensions()));
if (0 !== count($missingExtensions)) { if ($missingExtensions) {
$issues[] = 'Your Composer dependencies require the following PHP extensions to be installed: ' . implode(', ', $missingExtensions); $issues[] = 'Your Composer dependencies require the following PHP extensions to be installed: ' . implode(', ', $missingExtensions);
} }
if (0 !== count($issues)) { if ($issues) {
die('Composer detected issues in your platform:' . "\n\n" . implode("\n", $issues)); die('Composer detected issues in your platform:' . "\n\n" . implode("\n", $issues));
} }

View File

@ -8,13 +8,6 @@ if (!(PHP_VERSION_ID >= 70200 && PHP_VERSION_ID < 99999)) {
$issues[] = 'Your Composer dependencies require a PHP version ">= 7.2.0" and "< 99999". You are running ' . PHP_VERSION . '.'; $issues[] = 'Your Composer dependencies require a PHP version ">= 7.2.0" and "< 99999". You are running ' . PHP_VERSION . '.';
} }
$missingExtensions = array_diff(array ( if ($issues) {
), array_map('strtolower', get_loaded_extensions()));
if (0 !== count($missingExtensions)) {
$issues[] = 'Your Composer dependencies require the following PHP extensions to be installed: ' . implode(', ', $missingExtensions);
}
if (0 !== count($issues)) {
die('Composer detected issues in your platform:' . "\n\n" . implode("\n", $issues)); die('Composer detected issues in your platform:' . "\n\n" . implode("\n", $issues));
} }

View File

@ -8,13 +8,6 @@ if (!(PHP_VERSION_ID >= 70208 && PHP_VERSION_ID < 80000)) {
$issues[] = 'Your Composer dependencies require a PHP version ">= 7.2.8" and "< 8.0.0". You are running ' . PHP_VERSION . '.'; $issues[] = 'Your Composer dependencies require a PHP version ">= 7.2.8" and "< 8.0.0". You are running ' . PHP_VERSION . '.';
} }
$missingExtensions = array_diff(array ( if ($issues) {
), array_map('strtolower', get_loaded_extensions()));
if (0 !== count($missingExtensions)) {
$issues[] = 'Your Composer dependencies require the following PHP extensions to be installed: ' . implode(', ', $missingExtensions);
}
if (0 !== count($issues)) {
die('Composer detected issues in your platform:' . "\n\n" . implode("\n", $issues)); die('Composer detected issues in your platform:' . "\n\n" . implode("\n", $issues));
} }

View File

@ -8,15 +8,14 @@ if (!(PHP_VERSION_ID >= 70200 && PHP_VERSION_ID < 80000)) {
$issues[] = 'Your Composer dependencies require a PHP version ">= 7.2.0" and "< 8.0.0". You are running ' . PHP_VERSION . '.'; $issues[] = 'Your Composer dependencies require a PHP version ">= 7.2.0" and "< 8.0.0". You are running ' . PHP_VERSION . '.';
} }
$missingExtensions = array_diff(array ( $missingExtensions = array();
0 => 'json', extension_loaded('json') || $missingExtensions[] = 'json';
1 => 'xml', extension_loaded('xml') || $missingExtensions[] = 'xml';
), array_map('strtolower', get_loaded_extensions()));
if (0 !== count($missingExtensions)) { if ($missingExtensions) {
$issues[] = 'Your Composer dependencies require the following PHP extensions to be installed: ' . implode(', ', $missingExtensions); $issues[] = 'Your Composer dependencies require the following PHP extensions to be installed: ' . implode(', ', $missingExtensions);
} }
if (0 !== count($issues)) { if ($issues) {
die('Composer detected issues in your platform:' . "\n\n" . implode("\n", $issues)); die('Composer detected issues in your platform:' . "\n\n" . implode("\n", $issues));
} }