From 926cdc31a871fd6ee27af2aaabf97e22c023f485 Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 6 Jul 2020 17:46:20 +0100 Subject: [PATCH] nicer error for unsupported version --- core/sanitize_php.php | 63 +++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 33 deletions(-) diff --git a/core/sanitize_php.php b/core/sanitize_php.php index 259eb71d..f83d694d 100644 --- a/core/sanitize_php.php +++ b/core/sanitize_php.php @@ -4,39 +4,6 @@ * be included right at the very start of index.php and tests/bootstrap.php */ -$min_php = "7.3"; -if (version_compare(phpversion(), $min_php, ">=") === false) { - print " -Shimmie does not support versions of PHP lower than $min_php -(PHP reports that it is version ".phpversion()."). -If your web host is running an older version, they are dangerously out of -date and you should plan on moving elsewhere. -"; - exit; -} - -# ini_set('zend.assertions', '1'); // generate assertions -ini_set('assert.exception', '1'); // throw exceptions when failed -set_error_handler(function ($errNo, $errStr) { - // Should we turn ALL notices into errors? PHP allows a lot of - // terrible things to happen by default... - if (strpos($errStr, 'Use of undefined constant ') === 0) { - throw new Exception("PHP Error#$errNo: $errStr"); - } else { - return false; - } -}); - -ob_start(); - -if (PHP_SAPI === 'cli' || PHP_SAPI == 'phpdbg') { - if (isset($_SERVER['REMOTE_ADDR'])) { - die("CLI with remote addr? Confused, not taking the risk."); - } - $_SERVER['REMOTE_ADDR'] = "0.0.0.0"; - $_SERVER['HTTP_HOST'] = ""; -} - function die_nicely($title, $body, $code=0) { print(" @@ -61,3 +28,33 @@ function die_nicely($title, $body, $code=0) } exit($code); } + +$min_php = "7.3"; +if (version_compare(phpversion(), $min_php, ">=") === false) { + die_nicely("Not Supported", " + Shimmie does not support versions of PHP lower than $min_php + (PHP reports that it is version ".phpversion()."). + ", 1); +} + +# ini_set('zend.assertions', '1'); // generate assertions +ini_set('assert.exception', '1'); // throw exceptions when failed +set_error_handler(function ($errNo, $errStr) { + // Should we turn ALL notices into errors? PHP allows a lot of + // terrible things to happen by default... + if (strpos($errStr, 'Use of undefined constant ') === 0) { + throw new Exception("PHP Error#$errNo: $errStr"); + } else { + return false; + } +}); + +ob_start(); + +if (PHP_SAPI === 'cli' || PHP_SAPI == 'phpdbg') { + if (isset($_SERVER['REMOTE_ADDR'])) { + die("CLI with remote addr? Confused, not taking the risk."); + } + $_SERVER['REMOTE_ADDR'] = "0.0.0.0"; + $_SERVER['HTTP_HOST'] = ""; +}