Skip to content

Commit

Permalink
PHP: ensure 5.3 compatibility
Browse files Browse the repository at this point in the history
Relates to shaarli#250

Modifications
 - add PHP 5.3 to Travis environments
 - rewrite array declarations: explicitely use array() instead of []
 - move checkPHPVersion to application/Utils.php
 - bump required version from 5.1.0 to 5.3.x

Signed-off-by: VirtualTam <virtualtam@flibidi.net>
  • Loading branch information
virtualtam committed Jul 11, 2015
1 parent 49ca756 commit 78cf5bf
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 29 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ php:
- 5.6
- 5.5
- 5.4
- 5.3
install:
- composer self-update
- composer install
Expand Down
6 changes: 3 additions & 3 deletions application/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
function writeConfig($config, $isLoggedIn)
{
// These fields are required in configuration.
$MANDATORY_FIELDS = [
$MANDATORY_FIELDS = array(
'login', 'hash', 'salt', 'timezone', 'title', 'titleLink',
'redirector', 'disablesessionprotection', 'privateLinkByDefault'
];
);

if (!isset($config['config']['CONFIG_FILE'])) {
throw new MissingFieldConfigException('CONFIG_FILE');
Expand Down Expand Up @@ -126,4 +126,4 @@ public function __construct()
{
$this->message = 'You are not authorized to alter config.';
}
}
}
17 changes: 17 additions & 0 deletions application/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,21 @@ function checkDateFormat($format, $string)
$date = DateTime::createFromFormat($format, $string);
return $date && $date->format($string) == $string;
}

/**
* Checks the PHP version to ensure Shaarli can run
*
* @return void
*/
function checkPHPVersion($minVersion)
{
if (version_compare(PHP_VERSION, $minVersion) < 0) {
header('Content-Type: text/plain; charset=utf-8');
echo 'Your PHP version is obsolete!';
echo ' Shaarli requires at least PHP '.$minVersion.', and thus cannot run.';
echo ' Your PHP version has known security vulnerabilities and should be updated';
echo ' as soon as possible.';
exit;
}
}
?>
18 changes: 3 additions & 15 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
ini_set('memory_limit', '128M'); // Try to set max upload file size and read (May not work on some hosts).
ini_set('post_max_size', '16M');
ini_set('upload_max_filesize', '16M');
checkphpversion();
error_reporting(E_ALL^E_WARNING); // See all error except warnings.
//error_reporting(-1); // See all errors (for debugging only)

Expand All @@ -68,6 +67,9 @@
require_once 'application/Utils.php';
require_once 'application/Config.php';

// Ensure the PHP version is supported
checkPHPVersion('5.3');

include "inc/rain.tpl.class.php"; //include Rain TPL
raintpl::$tpl_dir = $GLOBALS['config']['RAINTPL_TPL']; // template directory
raintpl::$cache_dir = $GLOBALS['config']['RAINTPL_TMP']; // cache directory
Expand Down Expand Up @@ -158,21 +160,7 @@ function setup_login_state() {

return $userIsLoggedIn;
}
//==================================================================================================
$userIsLoggedIn = setup_login_state();
//==================================================================================================
//==================================================================================================

// Check PHP version
function checkphpversion()
{
if (version_compare(PHP_VERSION, '5.1.0') < 0)
{
header('Content-Type: text/plain; charset=utf-8');
echo 'Your PHP version is obsolete! Shaarli requires at least php 5.1.0, and thus cannot run. Sorry. Your PHP version has known security vulnerabilities and should be updated as soon as possible.';
exit;
}
}

// Checks if an update is available for Shaarli.
// (at most once a day, and only for registered user.)
Expand Down
10 changes: 5 additions & 5 deletions tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ConfigTest extends PHPUnit_Framework_TestCase
*/
public function setUp()
{
self::$_configFields = [
self::$_configFields = array(
'login' => 'login',
'hash' => 'hash',
'salt' => 'salt',
Expand All @@ -28,13 +28,13 @@ public function setUp()
'redirector' => '',
'disablesessionprotection' => false,
'privateLinkByDefault' => false,
'config' => [
'config' => array(
'CONFIG_FILE' => 'tests/config.php',
'DATADIR' => 'tests',
'config1' => 'config1data',
'config2' => 'config2data',
]
];
)
);
}

/**
Expand Down Expand Up @@ -174,4 +174,4 @@ public function testMergeDeprecatedConfigNoFile()
include self::$_configFields['config']['CONFIG_FILE'];
$this->assertEquals(self::$_configFields['login'], $GLOBALS['login']);
}
}
}
12 changes: 6 additions & 6 deletions tests/LinkDBTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,12 @@ public function testCountHiddenPublic()
public function testDays()
{
$this->assertEquals(
['20121206', '20130614', '20150310'],
array('20121206', '20130614', '20150310'),
self::$publicLinkDB->days()
);

$this->assertEquals(
['20121206', '20130614', '20141125', '20150310'],
array('20121206', '20130614', '20141125', '20150310'),
self::$privateLinkDB->days()
);
}
Expand Down Expand Up @@ -269,7 +269,7 @@ public function testGetUnknownLinkFromURL()
public function testAllTags()
{
$this->assertEquals(
[
array(
'web' => 3,
'cartoon' => 2,
'gnu' => 2,
Expand All @@ -279,12 +279,12 @@ public function testAllTags()
'software' => 1,
'stallman' => 1,
'free' => 1
],
),
self::$publicLinkDB->allTags()
);

$this->assertEquals(
[
array(
'web' => 4,
'cartoon' => 3,
'gnu' => 2,
Expand All @@ -298,7 +298,7 @@ public function testAllTags()
'w3c' => 1,
'css' => 1,
'Mercurial' => 1
],
),
self::$privateLinkDB->allTags()
);
}
Expand Down

0 comments on commit 78cf5bf

Please sign in to comment.