renamed server config class

improved loading code
This commit is contained in:
Steffen Schröder 2014-05-27 10:46:18 +02:00
parent f54ee6df64
commit eead92e0dd
2 changed files with 11 additions and 14 deletions

View File

@ -26,7 +26,7 @@ class Server implements CallbackListener {
/* /*
* Public Properties * Public Properties
*/ */
/** @var Config $config */ /** @var ServerConfig $config */
public $config = null; public $config = null;
public $index = -1; public $index = -1;
public $ip = null; public $ip = null;
@ -117,35 +117,35 @@ class Server implements CallbackListener {
// Host // Host
$hostElements = $serverElement->xpath('host'); $hostElements = $serverElement->xpath('host');
if (!$hostElements) { if (!$hostElements) {
trigger_error("Invalid server configuration (host).", E_USER_ERROR); trigger_error("Invalid server configuration (Host).", E_USER_ERROR);
} }
$host = (string)$hostElements[0]; $host = (string)$hostElements[0];
// Port // Port
$portElements = $serverElement->xpath('port'); $portElements = $serverElement->xpath('port');
if (!$portElements) { if (!$portElements) {
trigger_error("Invalid server configuration (port).", E_USER_ERROR); trigger_error("Invalid server configuration (Port).", E_USER_ERROR);
} }
$port = (string)$portElements[0]; $port = (string)$portElements[0];
// Login // Login
$loginElements = $serverElement->xpath('login'); $loginElements = $serverElement->xpath('login');
if (!$loginElements) { if (!$loginElements) {
trigger_error("Invalid server configuration (login).", E_USER_ERROR); trigger_error("Invalid server configuration (Login).", E_USER_ERROR);
} }
$login = (string)$loginElements[0]; $login = (string)$loginElements[0];
// Password // Password
$passElements = $serverElement->xpath('pass'); $passElements = $serverElement->xpath('pass');
if (!$passElements) { if (!$passElements) {
trigger_error("Invalid server configuration (password).", E_USER_ERROR); trigger_error("Invalid server configuration (Pass).", E_USER_ERROR);
} }
$pass = (string)$passElements[0]; $pass = (string)$passElements[0];
// Create config object // Create config object
$config = new Config($serverId, $host, $port, $login, $pass); $config = new ServerConfig($serverId, $host, $port, $login, $pass);
if (!$config->validate()) { if (!$config->validate()) {
$this->maniaControl->quit("Your Configuration File doesn't seem to be maintained properly. Please check it again!", true); $this->maniaControl->quit("Your config file doesn't seem to be maintained properly. Please check the server configuration again!", true);
} }
$this->config = $config; $this->config = $config;
} }

View File

@ -9,7 +9,7 @@ namespace ManiaControl\Server;
* @copyright 2014 ManiaControl Team * @copyright 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/ */
class Config { class ServerConfig {
/* /*
* Public Properties * Public Properties
*/ */
@ -42,13 +42,10 @@ class Config {
* @return bool * @return bool
*/ */
public function validate() { public function validate() {
$invalid = false; if (!$this->host || !$this->port || !$this->login || !$this->pass) {
if (!$this->host) { return false;
$invalid = true;
} else if (!$this->port || $this->port === 'port') {
$invalid = true;
} }
if ($invalid) { if ($this->port === 'port') {
return false; return false;
} }
return true; return true;