From 609d451895d1889f2980abf76a370c6aef3869d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Schro=CC=88der?= Date: Sun, 15 Jun 2014 00:51:43 +0200 Subject: [PATCH] system utility class --- application/core/ManiaControl.php | 17 ++-------- application/core/Utils/SystemUtil.php | 48 +++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 15 deletions(-) create mode 100644 application/core/Utils/SystemUtil.php diff --git a/application/core/ManiaControl.php b/application/core/ManiaControl.php index 78a43ffc..1af0a121 100644 --- a/application/core/ManiaControl.php +++ b/application/core/ManiaControl.php @@ -26,6 +26,7 @@ use ManiaControl\Statistics\StatisticManager; use ManiaControl\Update\UpdateManager; use ManiaControl\Utils\CommandLineHelper; use ManiaControl\Utils\Formatter; +use ManiaControl\Utils\SystemUtil; use Maniaplanet\DedicatedServer\Connection; use Maniaplanet\DedicatedServer\Xmlrpc\AuthenticationException; use Maniaplanet\DedicatedServer\Xmlrpc\Exception; @@ -51,8 +52,6 @@ class ManiaControl implements CommandListener, TimerListener { const VERSION = '0.151'; const API_VERSION = '2013-04-16'; const MIN_DEDIVERSION = '2014-04-02_18_00'; - const OS_UNIX = 'Unix'; - const OS_WIN = 'Windows'; const SCRIPT_TIMEOUT = 10; const URL_WEBSERVICE = 'http://ws.maniacontrol.com/'; const SETTING_PERMISSION_SHUTDOWN = 'Shutdown ManiaControl'; @@ -248,7 +247,7 @@ class ManiaControl implements CommandListener, TimerListener { // Execute start script in background // TODO: restart the .php script itself ($_SERVER['scriptname'] or something + $argv) - if ($this->getOS() === self::OS_UNIX) { + if (SystemUtil::isUnix()) { $command = 'sh ' . escapeshellarg(ManiaControlDir . 'ManiaControl.sh') . ' > /dev/null &'; exec($command); } else { @@ -260,18 +259,6 @@ class ManiaControl implements CommandListener, TimerListener { $this->quit('Quitting ManiaControl to restart.'); } - /** - * Get the Operating System on which ManiaControl is running - * - * @return string - */ - public function getOS() { - if (defined('PHP_WINDOWS_VERSION_MAJOR')) { - return self::OS_WIN; - } - return self::OS_UNIX; - } - /** * Handle Shutdown Command * diff --git a/application/core/Utils/SystemUtil.php b/application/core/Utils/SystemUtil.php new file mode 100644 index 00000000..0312782f --- /dev/null +++ b/application/core/Utils/SystemUtil.php @@ -0,0 +1,48 @@ + + * @copyright 2014 ManiaControl Team + * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 + */ +class SystemUtil { + /* + * Constants + */ + const OS_UNIX = 'Unix'; + const OS_WIN = 'Windows'; + + /** + * Get whether ManiaControl is running on Windows + * + * @return bool + */ + public static function isWindows() { + return (self::getOS() === self::OS_WIN); + } + + /** + * Get the Operating System on which ManiaControl is running + * + * @return string + */ + public static function getOS() { + if (defined('PHP_WINDOWS_VERSION_MAJOR')) { + return self::OS_WIN; + } + return self::OS_UNIX; + } + + /** + * Get whether ManiaControl is running on Unix + * + * @return bool + */ + public static function isUnix() { + return (self::getOS() === self::OS_UNIX); + } +}