2015-06-10 09:28:33 +00:00
|
|
|
<?php
|
|
|
|
namespace Wikia\PortableInfobox\Parser\Nodes;
|
|
|
|
|
|
|
|
|
2015-06-10 15:19:40 +00:00
|
|
|
use Wikia\PortableInfobox\Parser\XmlParser;
|
|
|
|
|
2015-06-10 09:28:33 +00:00
|
|
|
class NodeFactory {
|
|
|
|
|
2015-06-10 15:19:40 +00:00
|
|
|
public static function newFromXML( $text, array $data = [ ] ) {
|
|
|
|
return self::getInstance( XmlParser::parseXmlString( $text ), $data );
|
|
|
|
}
|
|
|
|
|
|
|
|
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__ );
|
2015-06-10 09:28:33 +00:00
|
|
|
$tagType = $xmlNode->getName();
|
2015-06-12 13:43:37 +00:00
|
|
|
$className = 'Wikia\\PortableInfobox\\Parser\\Nodes\\' . 'Node' .
|
|
|
|
mb_convert_case( mb_strtolower( $tagType ), MB_CASE_TITLE );
|
2015-06-10 09:28:33 +00:00
|
|
|
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__ );
|
2015-06-10 15:19:40 +00:00
|
|
|
|
2015-06-10 09:28:33 +00:00
|
|
|
return $instance;
|
|
|
|
}
|
2018-07-24 12:13:12 +00:00
|
|
|
//wfProfileOut( __METHOD__ );
|
2015-06-10 15:19:40 +00:00
|
|
|
|
2015-06-10 09:28:33 +00:00
|
|
|
return new NodeUnimplemented( $xmlNode, $data );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|