2015-05-13 11:51:07 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Wikia\PortableInfobox\Helpers;
|
|
|
|
|
|
|
|
class SimpleXmlUtil {
|
|
|
|
private static $instance = null;
|
|
|
|
|
|
|
|
private function __construct() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return null|SimpleXmlUtil
|
|
|
|
*/
|
|
|
|
public static function getInstance() {
|
|
|
|
if ( is_null( self::$instance ) ) {
|
|
|
|
self::$instance = new self;
|
|
|
|
}
|
|
|
|
return self::$instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets contents of SimpleXML node as XML string
|
|
|
|
* Will return empty string for a non-node argument
|
|
|
|
*
|
|
|
|
* @param $node
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getInnerXML( $node ) {
|
|
|
|
$innerXML = '';
|
|
|
|
if ( $node instanceof \SimpleXMLElement ) {
|
2015-05-19 13:31:56 +00:00
|
|
|
$domElement = dom_import_simplexml( $node );
|
2015-05-19 12:35:50 +00:00
|
|
|
|
2015-05-19 14:15:06 +00:00
|
|
|
if ( ( $domElement instanceof \DOMElement ) && ( $domElement->hasChildNodes() ) ) {
|
2015-05-19 13:31:56 +00:00
|
|
|
foreach ( $domElement->childNodes as $child ) {
|
2015-05-19 12:35:50 +00:00
|
|
|
$innerXML .= $child->ownerDocument->saveXML( $child );
|
|
|
|
}
|
2015-05-13 11:51:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $innerXML;
|
|
|
|
}
|
|
|
|
}
|