PortableInfobox/services/Parser/Nodes/NodeInfobox.php

51 lines
986 B
PHP
Raw Normal View History

<?php
namespace Wikia\PortableInfobox\Parser\Nodes;
class NodeInfobox extends Node {
protected $params;
public function getData() {
if ( !isset( $this->data ) ) {
2015-06-11 09:34:28 +00:00
$this->data = [ 'value' => $this->getDataForChildren() ];
}
return $this->data;
}
2015-06-11 09:34:28 +00:00
public function getRenderData() {
return array_map( function ( Node $item ) {
return $item->getRenderData();
}, array_filter( $this->getChildNodes(), function ( Node $item ) {
return !$item->isEmpty();
} ) );
}
public function isEmpty() {
2015-06-11 09:34:28 +00:00
/** @var Node $child */
foreach ( $this->getChildNodes() as $child ) {
if ( !$child->isEmpty() ) {
return false;
}
}
return true;
}
public function getParams() {
if ( !isset( $this->params ) ) {
$result = [ ];
foreach ( $this->xmlNode->attributes() as $k => $v ) {
$result[ $k ] = (string)$v;
}
$this->params = $result;
}
return $this->params;
}
public function getSource() {
return $this->getSourceForChildren();
}
}