diff --git a/composer.json b/composer.json index 9c85ceb1d5..6f0b526f7f 100644 --- a/composer.json +++ b/composer.json @@ -44,7 +44,8 @@ "*": "dist" }, "sort-packages": true, - "classmap-authoritative": true + "classmap-authoritative": true, + "platform-check": true }, "autoload": { "classmap": [ diff --git a/lib/composer/platform_check.php b/lib/composer/platform_check.php new file mode 100644 index 0000000000..861c725e0a --- /dev/null +++ b/lib/composer/platform_check.php @@ -0,0 +1,42 @@ += 70103)) { + $issues[] = 'Your Composer dependencies require a PHP version ">= 7.1.3". You are running ' . PHP_VERSION . '.'; +} + +$missingExtensions = array(); +extension_loaded('ctype') || $missingExtensions[] = 'ctype'; +extension_loaded('dom') || $missingExtensions[] = 'dom'; +extension_loaded('gd') || $missingExtensions[] = 'gd'; +extension_loaded('iconv') || $missingExtensions[] = 'iconv'; +extension_loaded('json') || $missingExtensions[] = 'json'; +extension_loaded('libxml') || $missingExtensions[] = 'libxml'; +extension_loaded('mysqli') || $missingExtensions[] = 'mysqli'; +extension_loaded('soap') || $missingExtensions[] = 'soap'; +extension_loaded('tokenizer') || $missingExtensions[] = 'tokenizer'; +extension_loaded('xml') || $missingExtensions[] = 'xml'; + +if ($missingExtensions) { + $issues[] = 'Your Composer dependencies require the following PHP extensions to be installed: ' . implode(', ', $missingExtensions) . '.'; +} + +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 + ); +}