From c25908cd7dd3afbfba4ebcf216aa2b8cc39ae77b Mon Sep 17 00:00:00 2001 From: Markus Birth Date: Sun, 10 Dec 2017 16:55:02 +0100 Subject: [PATCH] Optimisations. --- lib/TclUpdates/GotuObject.php | 20 ++++++++++++++++++- lib/TclUpdates/XmlParser.php | 37 +++++++++++++++++++++++------------ 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/lib/TclUpdates/GotuObject.php b/lib/TclUpdates/GotuObject.php index ed5e4aa..381a6fb 100755 --- a/lib/TclUpdates/GotuObject.php +++ b/lib/TclUpdates/GotuObject.php @@ -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) { if (!$xp->validateGOTU()) { - return false; + return null; } $g = new self(); $g->attrs = $xp->getAttrs(); diff --git a/lib/TclUpdates/XmlParser.php b/lib/TclUpdates/XmlParser.php index 8b2a811..4c8fe81 100644 --- a/lib/TclUpdates/XmlParser.php +++ b/lib/TclUpdates/XmlParser.php @@ -32,6 +32,27 @@ class XmlParser $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) { $xml_ok = $this->dom->loadXML($xml, LIBXML_NOENT); @@ -50,23 +71,13 @@ class XmlParser 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() { $attrs = array(); - foreach ($this->attr_map as $key => $xpath) { - $attrs[$key] = $this->getXPathValue($xpath); + foreach (array_keys($this->attr_map) as $key) { + $attrs[$key] = $this->__get($key); } - $attrs['time'] = $this->getReleaseTime(); + $attrs['time'] = $this->__get('time'); return $attrs; }