1
0
mirror of https://github.com/mbirth/tcl_update_db.git synced 2024-12-26 12:34:07 +00:00

Optimisations.

This commit is contained in:
Markus Birth 2017-12-10 16:55:02 +01:00
parent d90eed75f0
commit c25908cd7d
Signed by: mbirth
GPG Key ID: A9928D7A098C3A9A
2 changed files with 43 additions and 14 deletions

View File

@ -11,10 +11,28 @@ class GotuObject
} }
public function __isset($attr)
{
return array_key_exists($attr, $this->attrs);
}
public function __get($attr)
{
if (!$this->__isset($attr)) {
return null;
}
return $this->attrs[$attr];
}
public function getAttrs()
{
return $this->attrs;
}
public static function fromXmlParser(XmlParser $xp) public static function fromXmlParser(XmlParser $xp)
{ {
if (!$xp->validateGOTU()) { if (!$xp->validateGOTU()) {
return false; return null;
} }
$g = new self(); $g = new self();
$g->attrs = $xp->getAttrs(); $g->attrs = $xp->getAttrs();

View File

@ -32,6 +32,27 @@ class XmlParser
$this->dom = new \DOMDocument(); $this->dom = new \DOMDocument();
} }
public function __isset($attr)
{
if ($attr == 'time') {
return true;
}
return array_key_exists($attr, $this->attr_map);
}
public function __get($attr)
{
if ($attr === 'time') {
return $this->getReleaseTime();
}
if (!array_key_exists($attr, $this->attr_map)) {
return null;
}
$xpath = $this->attr_map[$attr];
$node = $this->getXPathValue($xpath);
return $node;
}
public function loadXMLFromString($xml) public function loadXMLFromString($xml)
{ {
$xml_ok = $this->dom->loadXML($xml, LIBXML_NOENT); $xml_ok = $this->dom->loadXML($xml, LIBXML_NOENT);
@ -50,23 +71,13 @@ class XmlParser
return true; return true;
} }
public function getAttr($attr)
{
if (!isset($this->attr_map[$attr])) {
return false;
}
$xpath = $this->attr_map[$attr];
$node = $this->getXPathValue($xpath);
return $node;
}
public function getAttrs() public function getAttrs()
{ {
$attrs = array(); $attrs = array();
foreach ($this->attr_map as $key => $xpath) { foreach (array_keys($this->attr_map) as $key) {
$attrs[$key] = $this->getXPathValue($xpath); $attrs[$key] = $this->__get($key);
} }
$attrs['time'] = $this->getReleaseTime(); $attrs['time'] = $this->__get('time');
return $attrs; return $attrs;
} }