Skip to content

Commit

Permalink
Adding PHP Doc to XML class.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrbasso committed Jul 27, 2010
1 parent 921dfb2 commit 5de7fa5
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions cake/libs/xml.php
Expand Up @@ -23,10 +23,12 @@
class Xml { class Xml {


/** /**
* Initialize XML object from a given XML string. Returns false on error. * Initialize SimpleXMLElement from a given XML string, file path, URL or array.
* *
* @param string $input XML string, a path to a file, or an HTTP resource to load * @param mixed $input XML string, a path to a file, an URL or an array
* @return object SimpleXMLElement * @return object SimpleXMLElement
* @static
* @access public
*/ */
public static function build($input) { public static function build($input) {
if (is_array($input) || is_object($input)) { if (is_array($input) || is_object($input)) {
Expand All @@ -41,6 +43,15 @@ public static function build($input) {
throw new Exception(__('XML cannot be read.')); throw new Exception(__('XML cannot be read.'));
} }


/**
* Transform an array in a SimpleXMLElement
*
* @param array $input Array with data
* @param string $format If create childs ('tags') or attributes ('attribute')
* @return object SimpleXMLElement
* @static
* @access public
*/
public static function fromArray($input, $format = 'attribute') { public static function fromArray($input, $format = 'attribute') {
if (!is_array($input) || count($input) !== 1) { if (!is_array($input) || count($input) !== 1) {
throw new Exception(__('Invalid input.')); throw new Exception(__('Invalid input.'));
Expand All @@ -58,6 +69,16 @@ public static function fromArray($input, $format = 'attribute') {
return $simpleXml; return $simpleXml;
} }


/**
* Recursive method to create SimpleXMLElement from array
*
* @param object $node Handler to SimpleXMLElement
* @param array $array
* @param string $format
* @return void
* @static
* @access protected
*/
protected static function _fromArrayRecursive(&$node, &$array, $format = 'attribute') { protected static function _fromArrayRecursive(&$node, &$array, $format = 'attribute') {
if (empty($array) || !is_array($array)) { if (empty($array) || !is_array($array)) {
return; return;
Expand Down Expand Up @@ -95,7 +116,10 @@ protected static function _fromArrayRecursive(&$node, &$array, $format = 'attrib
/** /**
* Returns this XML structure as a array. * Returns this XML structure as a array.
* *
* @param object $simpleXML SimpleXMLElement instance
* @return array Array representation of the XML structure. * @return array Array representation of the XML structure.
* @static
* @access public
*/ */
public static function toArray($simpleXML) { public static function toArray($simpleXML) {
if (!($simpleXML instanceof SimpleXMLElement)) { if (!($simpleXML instanceof SimpleXMLElement)) {
Expand All @@ -106,6 +130,15 @@ public static function toArray($simpleXML) {
return $result; return $result;
} }


/**
* Recursive method to toArray
*
* @param object $xml SimpleXMLElement object
* @param array $parentData Parent array with data
* @return void
* @static
* @access public
*/
protected static function _toArray($xml, &$parentData) { protected static function _toArray($xml, &$parentData) {
$data = array(); $data = array();


Expand Down

0 comments on commit 5de7fa5

Please sign in to comment.