application: move checkPHPVersion from Utils to ApplicationUtils
Relates to #372 Signed-off-by: VirtualTam <virtualtam@flibidi.net>
This commit is contained in:
parent
0def004963
commit
c9cf2715f0
5 changed files with 52 additions and 52 deletions
|
@ -5,6 +5,26 @@
|
||||||
class ApplicationUtils
|
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
|
* Checks Shaarli has the proper access permissions to its resources
|
||||||
*
|
*
|
||||||
|
|
|
@ -119,26 +119,6 @@ function generateLocation($referer, $host, $loopTerms = array())
|
||||||
return $finalReferer;
|
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.
|
* Validate session ID to prevent Full Path Disclosure.
|
||||||
*
|
*
|
||||||
|
|
|
@ -159,7 +159,7 @@
|
||||||
|
|
||||||
// Ensure the PHP version is supported
|
// Ensure the PHP version is supported
|
||||||
try {
|
try {
|
||||||
checkPHPVersion('5.3', PHP_VERSION);
|
ApplicationUtils::checkPHPVersion('5.3', PHP_VERSION);
|
||||||
} catch(Exception $exc) {
|
} catch(Exception $exc) {
|
||||||
header('Content-Type: text/plain; charset=utf-8');
|
header('Content-Type: text/plain; charset=utf-8');
|
||||||
echo $exc->getMessage();
|
echo $exc->getMessage();
|
||||||
|
|
|
@ -11,6 +11,37 @@
|
||||||
*/
|
*/
|
||||||
class ApplicationUtilsTest extends PHPUnit_Framework_TestCase
|
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
|
* Checks resource permissions for the current Shaarli installation
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -138,37 +138,6 @@ public function testGenerateLocationOut() {
|
||||||
$this->assertEquals('?', generateLocation($ref, 'localhost'));
|
$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!
|
* Test is_session_id_valid with a valid ID - TEST ALL THE HASHES!
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue