TrackManiaControl/application/core/Server/Config.php

90 lines
1.8 KiB
PHP
Raw Normal View History

2014-03-20 16:18:35 +01:00
<?php
namespace ManiaControl\Server;
/**
* Model Class holding the Server Config
*
2014-05-02 17:50:30 +02:00
* @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
2014-03-20 16:18:35 +01:00
*/
2014-06-20 19:05:59 +02:00
class Config {
2014-03-20 16:18:35 +01:00
/*
* Public Properties
2014-03-20 16:18:35 +01:00
*/
public $id = null;
public $host = null;
public $port = null;
public $user = null;
2014-03-20 16:18:35 +01:00
public $pass = null;
/**
* Create a new Server Config Instance
*
2014-06-20 19:05:59 +02:00
* @param mixed $id
* @param mixed $host
* @param mixed $port
* @param mixed $user
* @param mixed $pass
2014-03-20 16:18:35 +01:00
*/
public function __construct($id = null, $host = null, $port = null, $user = null, $pass = null) {
$this->id = $this->extractConfigData($id);
$this->host = $this->extractConfigData($host);
$this->port = $this->extractConfigData($port);
$this->user = $this->extractConfigData($user);
$this->pass = $this->extractConfigData($pass);
}
/**
* Extract the actual Data from the given Config Param
*
* @param mixed $configParam
* @return string
*/
private function extractConfigData($configParam) {
if (is_array($configParam)) {
return (string)reset($configParam);
}
return (string)$configParam;
2014-05-27 08:57:26 +02:00
}
/**
* Validate the Config Data
*
* @param string $message
2014-05-27 08:57:26 +02:00
* @return bool
*/
public function validate(&$message = null) {
// Host
if (!$this->host) {
$message = 'Missing Host!';
return false;
}
// Port
if (!$this->port || $this->port === 'port') {
$message = 'Missing Port!';
return false;
}
// User
if (!$this->user) {
$message = 'Missing User!';
return false;
2014-05-27 08:57:26 +02:00
}
if (!in_array($this->user, array('SuperAdmin', 'Admin', 'User'))) {
$message = 'Invalid User!';
2014-05-27 08:57:26 +02:00
return false;
}
// Pass
if (!$this->pass) {
$message = 'Missing Pass!';
return false;
}
2014-05-27 08:57:26 +02:00
return true;
2014-03-20 16:18:35 +01:00
}
}