Revert "FileUtil::loadConfig now returns a DOMDocument"

This reverts commit 58b07f266c.
This commit is contained in:
Steffen Schröder 2014-06-13 19:53:36 +02:00
parent 58b07f266c
commit 4c2a5e3260
2 changed files with 7 additions and 22 deletions

View File

@ -68,37 +68,22 @@ abstract class FileUtil {
} }
/** /**
* Load the Config XML-File with the given Name * Load config xml-file
* *
* @param string $fileName * @param string $fileName
* @return \DOMElement * @return \SimpleXMLElement
*/ */
public static function loadConfig($fileName) { public static function loadConfig($fileName) {
$fileLocation = ManiaControlDir . 'configs' . DIRECTORY_SEPARATOR . $fileName; $fileLocation = ManiaControlDir . 'configs' . DIRECTORY_SEPARATOR . $fileName;
if (!file_exists($fileLocation)) { if (!file_exists($fileLocation)) {
logMessage("Config file doesn't exist! ('{$fileName}')"); logMessage("Config File doesn't exist! ({$fileName})");
return null; return null;
} }
if (!is_readable($fileLocation)) { if (!is_readable($fileLocation)) {
logMessage("Config file isn't readable! Please check the file permissions. ('{$fileName}')"); logMessage("Config File isn't readable! Please check the File Permissions. ({$fileName})");
return null; return null;
} }
$configFileContent = @file_get_contents($fileLocation); return simplexml_load_file($fileLocation);
if (!$configFileContent) {
trigger_error("Couldn't load config file! ('{$fileName}')");
return null;
}
$domDocument = new \DOMDocument();
if (!@$domDocument->loadXML($configFileContent)) {
$message = "Config file isn't maintained properly! ('{$fileName}')";
$error = error_get_last();
if ($error && stripos($error['message'], 'DOMDocument::loadXML()') === 0) {
$message .= PHP_EOL . $error['message'];
}
trigger_error($message);
return null;
}
return $domDocument->firstChild;
} }
/** /**

View File

@ -65,7 +65,7 @@ class ManiaControl implements CommandListener, TimerListener {
public $authenticationManager = null; public $authenticationManager = null;
public $callbackManager = null; public $callbackManager = null;
public $chat = null; public $chat = null;
/** @var \DOMElement $config */ /** @var \SimpleXMLElement $config */
public $config = null; public $config = null;
public $configurator = null; public $configurator = null;
/** @var Connection $client */ /** @var Connection $client */
@ -160,7 +160,7 @@ class ManiaControl implements CommandListener, TimerListener {
if (!$this->config) { if (!$this->config) {
$this->quit("Error loading Configuration XML-File! ('{$configFileName}')", true); $this->quit("Error loading Configuration XML-File! ('{$configFileName}')", true);
} }
if ($this->config->childNodes->length < 3) { if ($this->config->count() < 3) {
$this->quit("Your Configuration File ('{$configFileName}') doesn't seem to be maintained properly. Please check it again!", true); $this->quit("Your Configuration File ('{$configFileName}') doesn't seem to be maintained properly. Please check it again!", true);
} }
} }