/** * This method returns an object matching the description specified by the element. * * @access public * @param Spring\Object\Parser $parser a reference to the parser * @param \SimpleXMLElement $element the element to be parsed * @return mixed an object matching the description * specified by the element * @throws Throwable\Parse\Exception indicates that a problem occurred * when parsing */ public function getObject(Spring\Object\Parser $parser, \SimpleXMLElement $element) { $object = new Common\Mutable\ArrayList(); $children = $parser->getElementChildren($element); foreach ($children as $child) { $object->addValue($parser->getObjectFromElement($child)); } return $object; }
/** * This method parses an "array" node. * * @access protected * @param \SimpleXMLElement $node a reference to the "array" node * @return \Unicity\Common\Mutable\IList the value as a list * @throws \Unicity\Throwable\Parse\Exception indicates that an unrecognized child * node was encountered */ protected function parseArrayElement(\SimpleXMLElement $node) { $element = new Common\Mutable\ArrayList(); $children = $node->children(); foreach ($children as $child) { $name = $child->getName(); switch ($name) { case 'array': $element->addValue($this->parseArrayElement($child)); break; case 'data': $element->addValue($this->parseDataElement($child)); break; case 'date': $element->addValue($this->parseDateElement($child)); break; case 'dict': $element->addValue($this->parseDictElement($child)); break; case 'false': $element->addValue($this->parseFalseElement($child)); break; case 'integer': $element->addValue($this->parseIntegerElement($child)); break; case 'real': $element->addValue($this->parseRealElement($child)); break; case 'string': $element->addValue($this->parseStringElement($child)); break; case 'true': $element->addValue($this->parseTrueElement($child)); break; default: throw new Throwable\Parse\Exception('Invalid child node named ":name" detected.', array(':name' => $name)); break; } } return $element; }
/** * This destructor ensures that any resources are properly disposed. * * @access public */ public function __destruct() { parent::__destruct(); unset($this->case_sensitive); }
/** * This method parses a "header" node. * * @access protected * @param \DOMElement $node a reference to the "header" node * @return Common\Mutable\IList a list of values * @throws \Unicity\Throwable\Parse\Exception indicates that problem occurred while * parsing */ protected function parseHeaderElement(\DOMElement $node) { $element = new Common\Mutable\ArrayList(); $attributes = $node->attributes; $attribute = $attributes->getNamedItem('comment'); if ($attribute !== null) { $element->addValue($attribute->nodeValue); } $children = $node->childNodes; foreach ($children as $child) { $name = $child->nodeName; switch ($name) { case 'comment': $element->addValue($this->parseCommentElement($child)); break; case '#text': break; default: throw new Throwable\Parse\Exception('Invalid child node named ":name" detected.', array(':name' => $name)); break; } } return $element; }
/** * This method processes an "array" node. * * @access protected * @param \SimpleXMLElement $node a reference to the "array" node * @return array an array of values * @throws Throwable\Instantiation\Exception indicates that problem occurred during * the instantiation */ protected function parseArrayElement(\SimpleXMLElement $node) { $iList = new Common\Mutable\ArrayList(); $children = $node->children(); foreach ($children as $child) { switch ($child->getName()) { case 'array': $iList->addValue($this->parseArrayElement($child)); break; case 'dictionary': $iList->addValue($this->parseDictionaryElement($child)); break; case 'expression': $iList->addValue($this->parseExpressionElement($child)); break; case 'null': $iList->addValue($this->parseNullElement($child)); break; case 'undefined': $iList->addValue($this->parseUndefinedElement($child)); break; case 'value': $iList->addValue($this->parseValueElement($child)); break; default: throw new Throwable\Instantiation\Exception('Unable to initial class.'); break; } } return $iList->toArray(); }
/** * This method converts a collection to use collections. * * @access public * @static * @param mixed $data the data to be converted * @return mixed the converted data */ public static function useCollections($data) { if (is_object($data)) { if ($data instanceof Common\IList) { $ilist = $data instanceof Common\Mutable\IList ? get_class($data) : '\\Unicity\\Common\\Mutable\\ArrayList'; $buffer = new $ilist(); foreach ($data as $value) { $buffer->addValue(static::useCollections($value)); } return $buffer; } else { if ($data instanceof Common\ISet) { $iset = $data instanceof Common\Mutable\ISet ? get_class($data) : '\\Unicity\\Common\\Mutable\\HashSet'; $buffer = new $iset(); foreach ($data as $value) { $buffer->putValue(static::useCollections($value)); } return $buffer; } else { if ($data instanceof Common\IMap) { $imap = $data instanceof Common\Mutable\IMap ? get_class($data) : '\\Unicity\\Common\\Mutable\\HashMap'; $buffer = new $imap(); foreach ($data as $key => $value) { $buffer->putEntry($key, static::useCollections($value)); } return $buffer; } else { if ($data instanceof \stdClass) { $data = get_object_vars($data); $buffer = new Common\Mutable\HashMap(); foreach ($data as $key => $value) { $buffer->putEntry($key, static::useCollections($value)); } return $buffer; } } } } } if (is_array($data)) { if (static::isDictionary($data)) { $buffer = new Common\Mutable\HashMap(); foreach ($data as $key => $value) { $buffer->putEntry($key, static::useCollections($value)); } return $buffer; } else { $buffer = new Common\Mutable\ArrayList(); foreach ($data as $value) { $buffer->addValue(static::useCollections($value)); } return $buffer; } } return $data; }
/** * 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 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 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); }