/** * This method parses outer "object" nodes. * * @access protected * @param \SimpleXMLElement $root a reference to the root node * @param \SimpleXMLElement $node a reference to the "objects" node * @return Common\Mutable\ICollection a collection of objects */ protected function parseOuterObjectElements(\SimpleXMLElement $root, \SimpleXMLElement $node) { $list = new Common\Mutable\ArrayList(); $node->registerXPathNamespace('spring', Spring\Data\XML::NAMESPACE_URI); $children = $node->xpath('/spring:objects/spring:object'); foreach ($children as $child) { $list->addValue($this->parseOuterObjectElement($root, $child)); } switch ($list->count()) { case 0: return new Common\Mutable\HashMap(); case 1: return $list->getValue(0); default: return $list; } }
/** * This method parses a child node. * * @access protected * @param \SimpleXMLElement $node a reference to a child node * @return \Unicity\Common\Mutable\ICollection a collection representing the data * in the soap file * @throws \Unicity\Throwable\Parse\Exception indicates that an unrecognized child * node was encountered */ protected function parseChildElement(\SimpleXMLElement $node) { $children = $node->children(); if (count($children) > 0) { $list = new Common\Mutable\ArrayList(); $map = new Common\Mutable\HashMap(); foreach ($children as $child) { $name = $child->getName(); $value = $this->parseChildElement($child); $temp = new Common\Mutable\HashMap(); $temp->putEntry($name, $value); $list->addValue($temp); $map->putEntry($name, $value); } return $list->count() > $map->count() || $this->directives->hasKey('expandableProperties') && $this->directives->getValue('expandableProperties')->hasValue($node->getName()) ? $list : $map; } else { $value = dom_import_simplexml($node)->textContent; $value = trim($value); if ($value == '') { $value = Core\Data\Undefined::instance(); } else { if (preg_match('/^(true|false)$/i', $value)) { $value = Core\Convert::toBoolean($value); } else { if (preg_match('/^[+-]?(0|[1-9][0-9]*)((\\.[0-9]+)|([eE][+-]?(0|[1-9][0-9]*)))$/', $value)) { $value = Core\Convert::toDouble($value); } else { if (filter_var($value, FILTER_VALIDATE_INT) !== false) { $value = Core\Convert::toInteger($value); } else { $value = Core\Convert::toString($value); } } } } return $value; } }
/** * This method parses the "soap:Envelope" node. * * @access protected * @param \SimpleXMLElement $root a reference to the "soap:Envelope" node * @return \Unicity\Common\Mutable\ICollection a collection representing the data * in the soap file * @throws \Unicity\Throwable\Parse\Exception indicates that an unrecognized child * node was encountered */ protected function parseEnvelopeElement(\SimpleXMLElement $root) { $list = new Common\Mutable\ArrayList(); $prefix = $this->metadata['namespace']['prefix']; $uri = $this->metadata['namespace']['uri']; $root->registerXPathNamespace($prefix, $uri); $children = $root->xpath("./{$prefix}:Body"); foreach ($children as $child) { $list->addValue($this->parseBodyElement($child)); } return $list->count() != 1 ? $list : $list->getValue(0); }