aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorVirtualTam <virtualtam@flibidi.net>2018-12-03 23:58:59 +0100
committerVirtualTam <virtualtam@flibidi.net>2019-01-12 23:11:19 +0100
commit9778a1551ce708b9f421a181806412a05410f1fb (patch)
tree325e12edc2b80b99b10e07be63351d786113aee9
parentbcf056c9d92e5240e645c76a4cdc8ae159693f9a (diff)
downloadShaarli-9778a1551ce708b9f421a181806412a05410f1fb.tar.gz
Shaarli-9778a1551ce708b9f421a181806412a05410f1fb.tar.zst
Shaarli-9778a1551ce708b9f421a181806412a05410f1fb.zip
namespacing: \Shaarli\ApplicationUtils
Signed-off-by: VirtualTam <virtualtam@flibidi.net>
-rw-r--r--application/ApplicationUtils.php75
-rw-r--r--application/render/PageBuilder.php2
-rw-r--r--application/updater/Updater.php2
-rw-r--r--index.php4
-rw-r--r--tests/ApplicationUtilsTest.php27
-rw-r--r--tests/utils/FakeApplicationUtils.php19
6 files changed, 67 insertions, 62 deletions
diff --git a/application/ApplicationUtils.php b/application/ApplicationUtils.php
index a3b2dcb1..7fe3cb32 100644
--- a/application/ApplicationUtils.php
+++ b/application/ApplicationUtils.php
@@ -1,4 +1,9 @@
1<?php 1<?php
2namespace Shaarli;
3
4use Exception;
5use Shaarli\Config\ConfigManager;
6
2/** 7/**
3 * Shaarli (application) utilities 8 * Shaarli (application) utilities
4 */ 9 */
@@ -51,7 +56,7 @@ class ApplicationUtils
51 return false; 56 return false;
52 } 57 }
53 } else { 58 } else {
54 if (! is_file($remote)) { 59 if (!is_file($remote)) {
55 return false; 60 return false;
56 } 61 }
57 $data = file_get_contents($remote); 62 $data = file_get_contents($remote);
@@ -97,7 +102,7 @@ class ApplicationUtils
97 // Do not check versions for visitors 102 // Do not check versions for visitors
98 // Do not check if the user doesn't want to 103 // Do not check if the user doesn't want to
99 // Do not check with dev version 104 // Do not check with dev version
100 if (! $isLoggedIn || empty($enableCheck) || $currentVersion === 'dev') { 105 if (!$isLoggedIn || empty($enableCheck) || $currentVersion === 'dev') {
101 return false; 106 return false;
102 } 107 }
103 108
@@ -111,7 +116,7 @@ class ApplicationUtils
111 return false; 116 return false;
112 } 117 }
113 118
114 if (! in_array($branch, self::$GIT_BRANCHES)) { 119 if (!in_array($branch, self::$GIT_BRANCHES)) {
115 throw new Exception( 120 throw new Exception(
116 'Invalid branch selected for updates: "' . $branch . '"' 121 'Invalid branch selected for updates: "' . $branch . '"'
117 ); 122 );
@@ -123,7 +128,7 @@ class ApplicationUtils
123 self::$GIT_URL . '/' . $branch . '/' . self::$VERSION_FILE 128 self::$GIT_URL . '/' . $branch . '/' . self::$VERSION_FILE
124 ); 129 );
125 130
126 if (! $latestVersion) { 131 if (!$latestVersion) {
127 // Only update the file's modification date 132 // Only update the file's modification date
128 file_put_contents($updateFile, $currentVersion); 133 file_put_contents($updateFile, $currentVersion);
129 return false; 134 return false;
@@ -152,9 +157,9 @@ class ApplicationUtils
152 if (version_compare($curVersion, $minVersion) < 0) { 157 if (version_compare($curVersion, $minVersion) < 0) {
153 $msg = t( 158 $msg = t(
154 'Your PHP version is obsolete!' 159 'Your PHP version is obsolete!'
155 . ' Shaarli requires at least PHP %s, and thus cannot run.' 160 . ' Shaarli requires at least PHP %s, and thus cannot run.'
156 . ' Your PHP version has known security vulnerabilities and should be' 161 . ' Your PHP version has known security vulnerabilities and should be'
157 . ' updated as soon as possible.' 162 . ' updated as soon as possible.'
158 ); 163 );
159 throw new Exception(sprintf($msg, $minVersion)); 164 throw new Exception(sprintf($msg, $minVersion));
160 } 165 }
@@ -174,50 +179,50 @@ class ApplicationUtils
174 179
175 // Check script and template directories are readable 180 // Check script and template directories are readable
176 foreach (array( 181 foreach (array(
177 'application', 182 'application',
178 'inc', 183 'inc',
179 'plugins', 184 'plugins',
180 $rainTplDir, 185 $rainTplDir,
181 $rainTplDir.'/'.$conf->get('resource.theme'), 186 $rainTplDir . '/' . $conf->get('resource.theme'),
182 ) as $path) { 187 ) as $path) {
183 if (! is_readable(realpath($path))) { 188 if (!is_readable(realpath($path))) {
184 $errors[] = '"'.$path.'" '. t('directory is not readable'); 189 $errors[] = '"' . $path . '" ' . t('directory is not readable');
185 } 190 }
186 } 191 }
187 192
188 // Check cache and data directories are readable and writable 193 // Check cache and data directories are readable and writable
189 foreach (array( 194 foreach (array(
190 $conf->get('resource.thumbnails_cache'), 195 $conf->get('resource.thumbnails_cache'),
191 $conf->get('resource.data_dir'), 196 $conf->get('resource.data_dir'),
192 $conf->get('resource.page_cache'), 197 $conf->get('resource.page_cache'),
193 $conf->get('resource.raintpl_tmp'), 198 $conf->get('resource.raintpl_tmp'),
194 ) as $path) { 199 ) as $path) {
195 if (! is_readable(realpath($path))) { 200 if (!is_readable(realpath($path))) {
196 $errors[] = '"'.$path.'" '. t('directory is not readable'); 201 $errors[] = '"' . $path . '" ' . t('directory is not readable');
197 } 202 }
198 if (! is_writable(realpath($path))) { 203 if (!is_writable(realpath($path))) {
199 $errors[] = '"'.$path.'" '. t('directory is not writable'); 204 $errors[] = '"' . $path . '" ' . t('directory is not writable');
200 } 205 }
201 } 206 }
202 207
203 // Check configuration files are readable and writable 208 // Check configuration files are readable and writable
204 foreach (array( 209 foreach (array(
205 $conf->getConfigFileExt(), 210 $conf->getConfigFileExt(),
206 $conf->get('resource.datastore'), 211 $conf->get('resource.datastore'),
207 $conf->get('resource.ban_file'), 212 $conf->get('resource.ban_file'),
208 $conf->get('resource.log'), 213 $conf->get('resource.log'),
209 $conf->get('resource.update_check'), 214 $conf->get('resource.update_check'),
210 ) as $path) { 215 ) as $path) {
211 if (! is_file(realpath($path))) { 216 if (!is_file(realpath($path))) {
212 # the file may not exist yet 217 # the file may not exist yet
213 continue; 218 continue;
214 } 219 }
215 220
216 if (! is_readable(realpath($path))) { 221 if (!is_readable(realpath($path))) {
217 $errors[] = '"'.$path.'" '. t('file is not readable'); 222 $errors[] = '"' . $path . '" ' . t('file is not readable');
218 } 223 }
219 if (! is_writable(realpath($path))) { 224 if (!is_writable(realpath($path))) {
220 $errors[] = '"'.$path.'" '. t('file is not writable'); 225 $errors[] = '"' . $path . '" ' . t('file is not writable');
221 } 226 }
222 } 227 }
223 228
diff --git a/application/render/PageBuilder.php b/application/render/PageBuilder.php
index 9a0fe61a..1c5b9251 100644
--- a/application/render/PageBuilder.php
+++ b/application/render/PageBuilder.php
@@ -2,7 +2,7 @@
2 2
3namespace Shaarli\Render; 3namespace Shaarli\Render;
4 4
5use ApplicationUtils; 5use Shaarli\ApplicationUtils;
6use Exception; 6use Exception;
7use Shaarli\Bookmark\LinkDB; 7use Shaarli\Bookmark\LinkDB;
8use RainTPL; 8use RainTPL;
diff --git a/application/updater/Updater.php b/application/updater/Updater.php
index 55251a30..89f0ff7f 100644
--- a/application/updater/Updater.php
+++ b/application/updater/Updater.php
@@ -2,7 +2,7 @@
2 2
3namespace Shaarli\Updater; 3namespace Shaarli\Updater;
4 4
5use ApplicationUtils; 5use Shaarli\ApplicationUtils;
6use Exception; 6use Exception;
7use RainTPL; 7use RainTPL;
8use ReflectionClass; 8use ReflectionClass;
diff --git a/index.php b/index.php
index ce0373e1..3a7dab25 100644
--- a/index.php
+++ b/index.php
@@ -56,7 +56,6 @@ require_once 'inc/rain.tpl.class.php';
56require_once __DIR__ . '/vendor/autoload.php'; 56require_once __DIR__ . '/vendor/autoload.php';
57 57
58// Shaarli library 58// Shaarli library
59require_once 'application/ApplicationUtils.php';
60require_once 'application/bookmark/LinkUtils.php'; 59require_once 'application/bookmark/LinkUtils.php';
61require_once 'application/config/ConfigPlugin.php'; 60require_once 'application/config/ConfigPlugin.php';
62require_once 'application/feed/Cache.php'; 61require_once 'application/feed/Cache.php';
@@ -71,6 +70,7 @@ require_once 'application/Utils.php';
71require_once 'application/PluginManager.php'; 70require_once 'application/PluginManager.php';
72require_once 'application/Router.php'; 71require_once 'application/Router.php';
73 72
73use \Shaarli\ApplicationUtils;
74use \Shaarli\Bookmark\Exception\LinkNotFoundException; 74use \Shaarli\Bookmark\Exception\LinkNotFoundException;
75use \Shaarli\Bookmark\LinkDB; 75use \Shaarli\Bookmark\LinkDB;
76use \Shaarli\Config\ConfigManager; 76use \Shaarli\Config\ConfigManager;
@@ -83,7 +83,7 @@ use \Shaarli\Render\ThemeUtils;
83use \Shaarli\Security\LoginManager; 83use \Shaarli\Security\LoginManager;
84use \Shaarli\Security\SessionManager; 84use \Shaarli\Security\SessionManager;
85use \Shaarli\Thumbnailer; 85use \Shaarli\Thumbnailer;
86use Shaarli\Updater\Updater; 86use \Shaarli\Updater\Updater;
87 87
88// Ensure the PHP version is supported 88// Ensure the PHP version is supported
89try { 89try {
diff --git a/tests/ApplicationUtilsTest.php b/tests/ApplicationUtilsTest.php
index fe5f84ce..82f8804d 100644
--- a/tests/ApplicationUtilsTest.php
+++ b/tests/ApplicationUtilsTest.php
@@ -1,33 +1,14 @@
1<?php 1<?php
2use Shaarli\Config\ConfigManager; 2namespace Shaarli;
3
4/**
5 * ApplicationUtils' tests
6 */
7 3
8require_once 'application/ApplicationUtils.php'; 4use Shaarli\Config\ConfigManager;
9
10/**
11 * Fake ApplicationUtils class to avoid HTTP requests
12 */
13class FakeApplicationUtils extends ApplicationUtils
14{
15 public static $VERSION_CODE = '';
16
17 /**
18 * Toggle HTTP requests, allow overriding the version code
19 */
20 public static function getVersion($url, $timeout = 0)
21 {
22 return self::$VERSION_CODE;
23 }
24}
25 5
6require_once 'tests/utils/FakeApplicationUtils.php';
26 7
27/** 8/**
28 * Unitary tests for Shaarli utilities 9 * Unitary tests for Shaarli utilities
29 */ 10 */
30class ApplicationUtilsTest extends PHPUnit_Framework_TestCase 11class ApplicationUtilsTest extends \PHPUnit\Framework\TestCase
31{ 12{
32 protected static $testUpdateFile = 'sandbox/update.txt'; 13 protected static $testUpdateFile = 'sandbox/update.txt';
33 protected static $testVersion = '0.5.0'; 14 protected static $testVersion = '0.5.0';
diff --git a/tests/utils/FakeApplicationUtils.php b/tests/utils/FakeApplicationUtils.php
new file mode 100644
index 00000000..de83d598
--- /dev/null
+++ b/tests/utils/FakeApplicationUtils.php
@@ -0,0 +1,19 @@
1<?php
2
3namespace Shaarli;
4
5/**
6 * Fake ApplicationUtils class to avoid HTTP requests
7 */
8class FakeApplicationUtils extends ApplicationUtils
9{
10 public static $VERSION_CODE = '';
11
12 /**
13 * Toggle HTTP requests, allow overriding the version code
14 */
15 public static function getVersion($url, $timeout = 0)
16 {
17 return self::$VERSION_CODE;
18 }
19}