From 9a34cb92b7c85e67c8f7fe6eaef07f40e78c0768 Mon Sep 17 00:00:00 2001 From: Antonio De Marco Date: Thu, 5 Oct 2017 10:01:48 +0200 Subject: [PATCH] Issue #36: Improve Target:parseXml(). --- src/Messages/Components/Target.php | 67 ++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 23 deletions(-) diff --git a/src/Messages/Components/Target.php b/src/Messages/Components/Target.php index b55cc28..e098b28 100644 --- a/src/Messages/Components/Target.php +++ b/src/Messages/Components/Target.php @@ -310,38 +310,59 @@ protected function parseXml($xml) { $parser = $this->getParser(); $parser->addXmlContent($xml); + $this->parseAttributionContact($parser); + $this->parseAttributionsSend($parser); + $this->parseAttributions($parser); + return $this; + } + + /** + * @param \EC\Poetry\Services\Parser $parser + */ + private function parseAttributionContact(Parser $parser) + { $parser->eachComponent("attributions/attributionContact", function (Parser $component) { $this->withContact() - ->setParser($this->getParser()) - ->setNickname($component->getContent('attributionContact/contactNickname')) - ->setEmail($component->getContent('attributionContact/contactEmail')) - ->setType($component->attr('type')) - ->setAction($component->attr('action')); + ->setParser($this->getParser()) + ->setNickname($component->getContent('attributionContact/contactNickname')) + ->setEmail($component->getContent('attributionContact/contactEmail')) + ->setType($component->attr('type')) + ->setAction($component->attr('action')); }, $this); + } + /** + * @param \EC\Poetry\Services\Parser $parser + */ + private function parseAttributionsSend(Parser $parser) + { $parser->eachComponent("attributions/attributionsSend", function (Parser $component) { $this->withReturnAddress() - ->setParser($this->getParser()) - ->setType($component->attr('type')) - ->setAction($component->attr('action')) - ->setUser($component->getContent('attributionsSend/retourUser')) - ->setPassword($component->getContent('attributionsSend/retourPassword')) - ->setAddress($component->getContent('attributionsSend/retourAddress')) - ->setPath($component->getContent('attributionsSend/retourPath')) - ->setRemark($component->getContent('attributionsSend/retourRemark')); + ->setParser($this->getParser()) + ->setType($component->attr('type')) + ->setAction($component->attr('action')) + ->setUser($component->getContent('attributionsSend/retourUser')) + ->setPassword($component->getContent('attributionsSend/retourPassword')) + ->setAddress($component->getContent('attributionsSend/retourAddress')) + ->setPath($component->getContent('attributionsSend/retourPath')) + ->setRemark($component->getContent('attributionsSend/retourRemark')); }, $this); + } + /** + * @param \EC\Poetry\Services\Parser $parser + */ + private function parseAttributions(Parser $parser) + { $this->setFormat($parser->getAttribute('attributions', 'format')) - ->setLanguage($parser->getAttribute('attributions', 'lgCode')) - ->setTrackChanges($parser->getAttribute('attributions', 'trackChanges')) - ->setRemark($parser->getContent('attributions/attributionsRemark')) - ->setDelay($parser->getContent('attributions/attributionsDelai')) - ->setDelayFormat($parser->getAttribute('attributions/attributionsDelai', 'format')) - ->setAcceptedDelay($parser->getContent('attributions/attributionsDelaiAccepted')) - ->setAcceptedDelayFormat($parser->getAttribute('attributions/attributionsDelaiAccepted', 'format')) - ->setTranslatedFile($parser->getContent('attributions/attributionsFile')); - - return $this; + ->setLanguage($parser->getAttribute('attributions', 'lgCode')) + ->setTrackChanges($parser->getAttribute('attributions', 'trackChanges')) + ->setRemark($parser->getContent('attributions/attributionsRemark')) + ->setDelay($parser->getContent('attributions/attributionsDelai')) + ->setDelayFormat($parser->getAttribute('attributions/attributionsDelai', 'format')) + ->setAcceptedDelay($parser->getContent('attributions/attributionsDelaiAccepted')) + ->setAcceptedDelayFormat($parser->getAttribute('attributions/attributionsDelaiAccepted', 'format')) + ->setTranslatedFile($parser->getContent('attributions/attributionsFile')); } }