diff --git a/application/ApplicationUtils.php b/application/ApplicationUtils.php index 6fb07f3..b0e94e2 100644 --- a/application/ApplicationUtils.php +++ b/application/ApplicationUtils.php @@ -5,6 +5,26 @@ class ApplicationUtils { + /** + * Checks the PHP version to ensure Shaarli can run + * + * @param string $minVersion minimum PHP required version + * @param string $curVersion current PHP version (use PHP_VERSION) + * + * @throws Exception the PHP version is not supported + */ + public static function checkPHPVersion($minVersion, $curVersion) + { + if (version_compare($curVersion, $minVersion) < 0) { + throw new Exception( + 'Your PHP version is obsolete!' + .' Shaarli requires at least PHP '.$minVersion.', and thus cannot run.' + .' Your PHP version has known security vulnerabilities and should be' + .' updated as soon as possible.' + ); + } + } + /** * Checks Shaarli has the proper access permissions to its resources * diff --git a/application/Utils.php b/application/Utils.php index 120333c..b8579b4 100644 --- a/application/Utils.php +++ b/application/Utils.php @@ -119,26 +119,6 @@ function generateLocation($referer, $host, $loopTerms = array()) return $finalReferer; } -/** - * Checks the PHP version to ensure Shaarli can run - * - * @param string $minVersion minimum PHP required version - * @param string $curVersion current PHP version (use PHP_VERSION) - * - * @throws Exception the PHP version is not supported - */ -function checkPHPVersion($minVersion, $curVersion) -{ - if (version_compare($curVersion, $minVersion) < 0) { - throw new Exception( - 'Your PHP version is obsolete!' - .' Shaarli requires at least PHP '.$minVersion.', and thus cannot run.' - .' Your PHP version has known security vulnerabilities and should be' - .' updated as soon as possible.' - ); - } -} - /** * Validate session ID to prevent Full Path Disclosure. * diff --git a/index.php b/index.php index 654f7f8..aae477b 100644 --- a/index.php +++ b/index.php @@ -159,7 +159,7 @@ require_once 'application/Router.php'; // Ensure the PHP version is supported try { - checkPHPVersion('5.3', PHP_VERSION); + ApplicationUtils::checkPHPVersion('5.3', PHP_VERSION); } catch(Exception $exc) { header('Content-Type: text/plain; charset=utf-8'); echo $exc->getMessage(); diff --git a/tests/ApplicationUtilsTest.php b/tests/ApplicationUtilsTest.php index 9a99c6c..01301e6 100644 --- a/tests/ApplicationUtilsTest.php +++ b/tests/ApplicationUtilsTest.php @@ -11,6 +11,37 @@ require_once 'application/ApplicationUtils.php'; */ class ApplicationUtilsTest extends PHPUnit_Framework_TestCase { + /** + * Check supported PHP versions + */ + public function testCheckSupportedPHPVersion() + { + $minVersion = '5.3'; + ApplicationUtils::checkPHPVersion($minVersion, '5.4.32'); + ApplicationUtils::checkPHPVersion($minVersion, '5.5'); + ApplicationUtils::checkPHPVersion($minVersion, '5.6.10'); + } + + /** + * Check a unsupported PHP version + * @expectedException Exception + * @expectedExceptionMessageRegExp /Your PHP version is obsolete/ + */ + public function testCheckSupportedPHPVersion51() + { + ApplicationUtils::checkPHPVersion('5.3', '5.1.0'); + } + + /** + * Check another unsupported PHP version + * @expectedException Exception + * @expectedExceptionMessageRegExp /Your PHP version is obsolete/ + */ + public function testCheckSupportedPHPVersion52() + { + ApplicationUtils::checkPHPVersion('5.3', '5.2'); + } + /** * Checks resource permissions for the current Shaarli installation */ diff --git a/tests/UtilsTest.php b/tests/UtilsTest.php index 311d4bf..4847ea9 100644 --- a/tests/UtilsTest.php +++ b/tests/UtilsTest.php @@ -138,37 +138,6 @@ class UtilsTest extends PHPUnit_Framework_TestCase $this->assertEquals('?', generateLocation($ref, 'localhost')); } - /** - * Check supported PHP versions - */ - public function testCheckSupportedPHPVersion() - { - $minVersion = '5.3'; - checkPHPVersion($minVersion, '5.4.32'); - checkPHPVersion($minVersion, '5.5'); - checkPHPVersion($minVersion, '5.6.10'); - } - - /** - * Check a unsupported PHP version - * @expectedException Exception - * @expectedExceptionMessageRegExp /Your PHP version is obsolete/ - */ - public function testCheckSupportedPHPVersion51() - { - checkPHPVersion('5.3', '5.1.0'); - } - - /** - * Check another unsupported PHP version - * @expectedException Exception - * @expectedExceptionMessageRegExp /Your PHP version is obsolete/ - */ - public function testCheckSupportedPHPVersion52() - { - checkPHPVersion('5.3', '5.2'); - } - /** * Test is_session_id_valid with a valid ID - TEST ALL THE HASHES! *