From 9778a1551ce708b9f421a181806412a05410f1fb Mon Sep 17 00:00:00 2001 From: VirtualTam Date: Mon, 3 Dec 2018 23:58:59 +0100 Subject: [PATCH] namespacing: \Shaarli\ApplicationUtils Signed-off-by: VirtualTam --- application/ApplicationUtils.php | 75 +++++++++++++++------------- application/render/PageBuilder.php | 2 +- application/updater/Updater.php | 2 +- index.php | 4 +- tests/ApplicationUtilsTest.php | 27 ++-------- tests/utils/FakeApplicationUtils.php | 19 +++++++ 6 files changed, 67 insertions(+), 62 deletions(-) create mode 100644 tests/utils/FakeApplicationUtils.php diff --git a/application/ApplicationUtils.php b/application/ApplicationUtils.php index a3b2dcb..7fe3cb3 100644 --- a/application/ApplicationUtils.php +++ b/application/ApplicationUtils.php @@ -1,4 +1,9 @@ get('resource.theme'), - ) as $path) { - if (! is_readable(realpath($path))) { - $errors[] = '"'.$path.'" '. t('directory is not readable'); + 'application', + 'inc', + 'plugins', + $rainTplDir, + $rainTplDir . '/' . $conf->get('resource.theme'), + ) as $path) { + if (!is_readable(realpath($path))) { + $errors[] = '"' . $path . '" ' . t('directory is not readable'); } } // Check cache and data directories are readable and writable foreach (array( - $conf->get('resource.thumbnails_cache'), - $conf->get('resource.data_dir'), - $conf->get('resource.page_cache'), - $conf->get('resource.raintpl_tmp'), - ) as $path) { - if (! is_readable(realpath($path))) { - $errors[] = '"'.$path.'" '. t('directory is not readable'); + $conf->get('resource.thumbnails_cache'), + $conf->get('resource.data_dir'), + $conf->get('resource.page_cache'), + $conf->get('resource.raintpl_tmp'), + ) as $path) { + if (!is_readable(realpath($path))) { + $errors[] = '"' . $path . '" ' . t('directory is not readable'); } - if (! is_writable(realpath($path))) { - $errors[] = '"'.$path.'" '. t('directory is not writable'); + if (!is_writable(realpath($path))) { + $errors[] = '"' . $path . '" ' . t('directory is not writable'); } } // Check configuration files are readable and writable foreach (array( - $conf->getConfigFileExt(), - $conf->get('resource.datastore'), - $conf->get('resource.ban_file'), - $conf->get('resource.log'), - $conf->get('resource.update_check'), - ) as $path) { - if (! is_file(realpath($path))) { + $conf->getConfigFileExt(), + $conf->get('resource.datastore'), + $conf->get('resource.ban_file'), + $conf->get('resource.log'), + $conf->get('resource.update_check'), + ) as $path) { + if (!is_file(realpath($path))) { # the file may not exist yet continue; } - if (! is_readable(realpath($path))) { - $errors[] = '"'.$path.'" '. t('file is not readable'); + if (!is_readable(realpath($path))) { + $errors[] = '"' . $path . '" ' . t('file is not readable'); } - if (! is_writable(realpath($path))) { - $errors[] = '"'.$path.'" '. t('file is not writable'); + if (!is_writable(realpath($path))) { + $errors[] = '"' . $path . '" ' . t('file is not writable'); } } diff --git a/application/render/PageBuilder.php b/application/render/PageBuilder.php index 9a0fe61..1c5b925 100644 --- a/application/render/PageBuilder.php +++ b/application/render/PageBuilder.php @@ -2,7 +2,7 @@ namespace Shaarli\Render; -use ApplicationUtils; +use Shaarli\ApplicationUtils; use Exception; use Shaarli\Bookmark\LinkDB; use RainTPL; diff --git a/application/updater/Updater.php b/application/updater/Updater.php index 55251a3..89f0ff7 100644 --- a/application/updater/Updater.php +++ b/application/updater/Updater.php @@ -2,7 +2,7 @@ namespace Shaarli\Updater; -use ApplicationUtils; +use Shaarli\ApplicationUtils; use Exception; use RainTPL; use ReflectionClass; diff --git a/index.php b/index.php index ce0373e..3a7dab2 100644 --- a/index.php +++ b/index.php @@ -56,7 +56,6 @@ require_once 'inc/rain.tpl.class.php'; require_once __DIR__ . '/vendor/autoload.php'; // Shaarli library -require_once 'application/ApplicationUtils.php'; require_once 'application/bookmark/LinkUtils.php'; require_once 'application/config/ConfigPlugin.php'; require_once 'application/feed/Cache.php'; @@ -71,6 +70,7 @@ require_once 'application/Utils.php'; require_once 'application/PluginManager.php'; require_once 'application/Router.php'; +use \Shaarli\ApplicationUtils; use \Shaarli\Bookmark\Exception\LinkNotFoundException; use \Shaarli\Bookmark\LinkDB; use \Shaarli\Config\ConfigManager; @@ -83,7 +83,7 @@ use \Shaarli\Render\ThemeUtils; use \Shaarli\Security\LoginManager; use \Shaarli\Security\SessionManager; use \Shaarli\Thumbnailer; -use Shaarli\Updater\Updater; +use \Shaarli\Updater\Updater; // Ensure the PHP version is supported try { diff --git a/tests/ApplicationUtilsTest.php b/tests/ApplicationUtilsTest.php index fe5f84c..82f8804 100644 --- a/tests/ApplicationUtilsTest.php +++ b/tests/ApplicationUtilsTest.php @@ -1,33 +1,14 @@