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
Raw Normal View History

2012-07-12 05:10:53 +00:00
<?php defined('SYSPATH') or die('No direct access allowed.');
2013-03-19 22:35:19 +00:00
2012-07-12 05:10:53 +00:00
/**
* This class extends the Kohana XML
*
* @package OSB
2013-03-19 22:35:19 +00:00
* @category Modifications
2012-07-12 05:10:53 +00:00
* @author Deon George
2013-03-19 22:35:19 +00:00
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
2012-07-12 05:10:53 +00:00
*/
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;
}
}
?>