system utility class

This commit is contained in:
Steffen Schröder 2014-06-15 00:51:43 +02:00
parent ddc42c854f
commit 609d451895
2 changed files with 50 additions and 15 deletions

View File

@ -26,6 +26,7 @@ use ManiaControl\Statistics\StatisticManager;
use ManiaControl\Update\UpdateManager; use ManiaControl\Update\UpdateManager;
use ManiaControl\Utils\CommandLineHelper; use ManiaControl\Utils\CommandLineHelper;
use ManiaControl\Utils\Formatter; use ManiaControl\Utils\Formatter;
use ManiaControl\Utils\SystemUtil;
use Maniaplanet\DedicatedServer\Connection; use Maniaplanet\DedicatedServer\Connection;
use Maniaplanet\DedicatedServer\Xmlrpc\AuthenticationException; use Maniaplanet\DedicatedServer\Xmlrpc\AuthenticationException;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception; use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
@ -51,8 +52,6 @@ class ManiaControl implements CommandListener, TimerListener {
const VERSION = '0.151'; const VERSION = '0.151';
const API_VERSION = '2013-04-16'; const API_VERSION = '2013-04-16';
const MIN_DEDIVERSION = '2014-04-02_18_00'; const MIN_DEDIVERSION = '2014-04-02_18_00';
const OS_UNIX = 'Unix';
const OS_WIN = 'Windows';
const SCRIPT_TIMEOUT = 10; const SCRIPT_TIMEOUT = 10;
const URL_WEBSERVICE = 'http://ws.maniacontrol.com/'; const URL_WEBSERVICE = 'http://ws.maniacontrol.com/';
const SETTING_PERMISSION_SHUTDOWN = 'Shutdown ManiaControl'; const SETTING_PERMISSION_SHUTDOWN = 'Shutdown ManiaControl';
@ -248,7 +247,7 @@ class ManiaControl implements CommandListener, TimerListener {
// Execute start script in background // Execute start script in background
// TODO: restart the .php script itself ($_SERVER['scriptname'] or something + $argv) // 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 &'; $command = 'sh ' . escapeshellarg(ManiaControlDir . 'ManiaControl.sh') . ' > /dev/null &';
exec($command); exec($command);
} else { } else {
@ -260,18 +259,6 @@ class ManiaControl implements CommandListener, TimerListener {
$this->quit('Quitting ManiaControl to restart.'); $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 * Handle Shutdown Command
* *

View File

@ -0,0 +1,48 @@
<?php
namespace ManiaControl\Utils;
/**
* System Utility Class
*
* @author ManiaControl Team <mail@maniacontrol.com>
* @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);
}
}