Commit bab9a4c1 authored by Ad Schellevis's avatar Ad Schellevis

remove unused functions and switch to SimpleXML as default parser.

parent 6004b1de
...@@ -43,12 +43,6 @@ class Config extends Singleton ...@@ -43,12 +43,6 @@ class Config extends Singleton
*/ */
private $config_file = ""; private $config_file = "";
/**
* XMLDocument type reference to config
* @var \DOMDocument
*/
private $configxml = null ;
/** /**
* SimpleXML type reference to config * SimpleXML type reference to config
* @var SimpleXML * @var SimpleXML
...@@ -140,9 +134,7 @@ class Config extends Singleton ...@@ -140,9 +134,7 @@ class Config extends Singleton
// root node // root node
if ($node == null) { if ($node == null) {
$this->configxml = new \DOMDocument('1.0'); $this->simplexml = simplexml_load_string('<'.$this->simplexml[0]->getName().'/>');
$this->configxml->loadXML('<'.$this->simplexml[0]->getName().'/>');
$this->simplexml = simplexml_import_dom($this->configxml);
$node = $this->simplexml ; $node = $this->simplexml ;
} }
...@@ -179,7 +171,7 @@ class Config extends Singleton ...@@ -179,7 +171,7 @@ class Config extends Singleton
/** /**
* Execute a xpath expression on config.xml * Execute a xpath expression on config.xml (full DOM implementation)
* @param $query * @param $query
* @return \DOMNodeList * @return \DOMNodeList
* @throws ConfigException * @throws ConfigException
...@@ -187,7 +179,12 @@ class Config extends Singleton ...@@ -187,7 +179,12 @@ class Config extends Singleton
public function xpath($query) public function xpath($query)
{ {
$this->checkvalid(); $this->checkvalid();
$xpath = new \DOMXPath($this->configxml);
$configxml = dom_import_simplexml($this->simplexml);
$dom = new \DOMDocument('1.0');
$dom_sxe = $dom->importNode($configxml, true);
$dom->appendChild($dom_sxe);
$xpath = new \DOMXPath($dom);
return $xpath->query($query); return $xpath->query($query);
} }
...@@ -203,18 +200,6 @@ class Config extends Singleton ...@@ -203,18 +200,6 @@ class Config extends Singleton
return $this->simplexml; return $this->simplexml;
} }
/**
* get DOMDocument
* @return XMLDocument
* @throws ConfigException
*/
public function getDOM()
{
$this->checkvalid();
return $this->configxml;
}
/** /**
* init new config object, try to load current configuration * init new config object, try to load current configuration
...@@ -226,7 +211,7 @@ class Config extends Singleton ...@@ -226,7 +211,7 @@ class Config extends Singleton
try { try {
$this->load(); $this->load();
} catch (\Exception $e) { } catch (\Exception $e) {
$this->configxml = null ; $this->simplexml = null ;
} }
} }
...@@ -253,9 +238,7 @@ class Config extends Singleton ...@@ -253,9 +238,7 @@ class Config extends Singleton
} }
); );
$this->configxml = new \DOMDocument('1.0'); $this->simplexml = simplexml_load_string($xml);
$this->configxml->loadXML($xml);
$this->simplexml = simplexml_import_dom($this->configxml);
restore_error_handler(); restore_error_handler();
$this->statusIsValid = true; $this->statusIsValid = true;
...@@ -268,10 +251,13 @@ class Config extends Singleton ...@@ -268,10 +251,13 @@ class Config extends Singleton
public function __toString() public function __toString()
{ {
// reformat XML (pretty print) // reformat XML (pretty print)
$dom = new \DOMDocument; $configxml = dom_import_simplexml($this->simplexml);
$dom = new \DOMDocument('1.0');
$dom_sxe = $dom->importNode($configxml, true);
$dom->appendChild($dom_sxe);
$dom->formatOutput = true; $dom->formatOutput = true;
$dom->preserveWhiteSpace = false; $dom->preserveWhiteSpace = false;
$dom->loadXML($this->configxml->saveXML()); $dom->loadXML($dom->saveXML());
return $dom->saveXML(); return $dom->saveXML();
...@@ -369,7 +355,6 @@ class Config extends Singleton ...@@ -369,7 +355,6 @@ class Config extends Singleton
if ($this->statusIsValid) { if ($this->statusIsValid) {
// if current config is valid, // if current config is valid,
$configxml = $this->configxml;
$simplexml = $this->simplexml; $simplexml = $this->simplexml;
try { try {
// try to restore config // try to restore config
...@@ -378,7 +363,6 @@ class Config extends Singleton ...@@ -378,7 +363,6 @@ class Config extends Singleton
return true; return true;
} catch (ConfigException $e) { } catch (ConfigException $e) {
// copy / load failed, restore previous version // copy / load failed, restore previous version
$this->configxml = $configxml;
$this->simplexml = $simplexml; $this->simplexml = $simplexml;
$this->statusIsValid = true; $this->statusIsValid = true;
$this->save(null, true); $this->save(null, true);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment