PortableInfobox/includes/services/Parser/Nodes/NodeFactory.php

42 lines
1.1 KiB
PHP
Raw Normal View History

<?php
namespace PortableInfobox\Parser\Nodes;
use PortableInfobox\Parser\XmlParser;
class NodeFactory {
2018-08-16 09:25:53 +00:00
public static function newFromXML( $text, array $data = [] ) {
return self::getInstance( XmlParser::parseXmlString( $text ), $data );
}
2018-08-16 09:25:53 +00:00
public static function newFromSimpleXml( \SimpleXMLElement $xmlNode, array $data = [] ) {
return self::getInstance( $xmlNode, $data );
}
/**
* @param \SimpleXMLElement $xmlNode
* @param array $data
*
* @return Node|NodeUnimplemented
*/
protected static function getInstance( \SimpleXMLElement $xmlNode, array $data ) {
2018-07-24 12:13:12 +00:00
//wfProfileIn( __METHOD__ );
$tagType = $xmlNode->getName();
$className = 'PortableInfobox\\Parser\\Nodes\\' . 'Node' .
mb_convert_case( mb_strtolower( $tagType ), MB_CASE_TITLE );
if ( class_exists( $className ) ) {
/* @var $instance \Wikia\PortableInfobox\Parser\Nodes\Node */
$instance = new $className( $xmlNode, $data );
2018-07-24 12:13:12 +00:00
//wfProfileOut( __METHOD__ );
2018-08-22 08:04:07 +00:00
if ( $instance instanceof Node ) {
return $instance;
}
}
2018-07-24 12:13:12 +00:00
//wfProfileOut( __METHOD__ );
return new NodeUnimplemented( $xmlNode, $data );
}
2018-08-16 09:25:53 +00:00
}