This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
khosb/application/classes/XML.php

45 lines
1.0 KiB
PHP

<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class extends the Kohana XML
*
* @package OSB
* @category Modifications
* @author Deon George
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class XML extends XML_Core {
/**
* Collapse an XML object into a simple array
*/
public function collapse(XML $xml=NULL) {
if (is_null($xml))
$xml = $this;
$result = array();
foreach ($xml->as_array() as $j=>$k) {
$v = $xml->$j->value();
if (count($k) > 1) {
foreach ($xml->get($j,1) as $k)
if (isset($k['name'][0]))
$result[$j][$k['name'][0]] = (isset($k['value'][0]) ? $k['value'][0] : '');
else
$result[$j][] = $k;
} elseif (! is_null($v))
$result[$j] = $v;
else {
$result[$j] = $this->collapse($xml->$j);
}
}
if (array_key_exists('name',$result) AND array_key_exists('value',$result))
$result = array($result['name']=>$result['value']);
return $result;
}
}
?>