71 $this->store = $store;
72 $this->index = $index;
73 [
$this->name, $this->rawChildren ] = $this->store[$index];
84 public static function factory( array $store, $index ) {
85 if ( !isset( $store[$index] ) ) {
89 $descriptor = $store[$index];
90 if ( is_string( $descriptor ) ) {
91 $class = PPNode_Hash_Text::class;
92 } elseif ( is_array( $descriptor ) ) {
93 if ( $descriptor[self::NAME][0] ===
'@' ) {
94 $class = PPNode_Hash_Attr::class;
99 throw new InvalidArgumentException( __METHOD__ .
': invalid node descriptor' );
101 return new $class( $store, $index );
111 for ( $node = $this->
getFirstChild(); $node; $node = $node->getNextSibling() ) {
113 $attribs .=
' ' . $node->name .
114 '="' . htmlspecialchars( $node->value, ENT_COMPAT ) .
'"';
116 $inner .= $node->__toString();
119 if ( $inner ===
'' ) {
120 return "<{$this->name}$attribs/>";
122 return "<{$this->name}$attribs>$inner</{$this->name}>";
131 foreach ( $this->rawChildren as $i => $child ) {
145 if ( !isset( $this->rawChildren[0] ) ) {
171 foreach ( $this->rawChildren as $i => $child ) {
172 if ( is_array( $child ) && $child[self::NAME] ===
$name ) {
184 return $this->rawChildren;
228 foreach ( $children as $i => $child ) {
229 if ( !is_array( $child ) ) {
232 if ( $child[self::NAME] ===
'name' ) {
233 $bits[
'name'] =
new self( $children, $i );
234 if ( isset( $child[self::CHILDREN][0][self::NAME] )
239 } elseif ( $child[self::NAME] ===
'value' ) {
240 $bits[
'value'] =
new self( $children, $i );
244 if ( !isset( $bits[
'name'] ) ) {
245 throw new InvalidArgumentException(
'Invalid brace node passed to ' . __METHOD__ );
247 if ( !isset( $bits[
'index'] ) ) {
270 foreach ( $children as $i => $child ) {
271 if ( !is_array( $child ) ) {
274 switch ( $child[self::NAME] ) {
276 $bits[
'name'] =
new self( $children, $i );
279 $bits[
'attr'] =
new self( $children, $i );
282 $bits[
'inner'] =
new self( $children, $i );
285 $bits[
'close'] =
new self( $children, $i );
289 if ( !isset( $bits[
'name'] ) ) {
290 throw new InvalidArgumentException(
'Invalid ext node passed to ' . __METHOD__ );
301 if ( $this->name !==
'h' ) {
302 throw new BadMethodCallException(
'Invalid h node passed to ' . __METHOD__ );
314 foreach ( $children as $child ) {
315 if ( !is_array( $child ) ) {
318 if ( $child[self::NAME] ===
'@i' ) {
320 } elseif ( $child[self::NAME] ===
'@level' ) {
324 if ( !isset( $bits[
'i'] ) ) {
325 throw new InvalidArgumentException(
'Invalid h node passed to ' . __METHOD__ );
347 $bits = [
'lineStart' =>
'' ];
348 foreach ( $children as $i => $child ) {
349 if ( !is_array( $child ) ) {
352 switch ( $child[self::NAME] ) {
354 $bits[
'title'] =
new self( $children, $i );
357 $parts[] =
new self( $children, $i );
360 $bits[
'lineStart'] =
'1';
364 if ( !isset( $bits[
'title'] ) ) {
365 throw new InvalidArgumentException(
'Invalid node passed to ' . __METHOD__ );
static factory(array $store, $index)
Construct an appropriate PPNode_Hash_* object with a class that depends on what is at the relevant st...
splitExt()
Split an "<ext>" node into an associative array containing name, attr, inner and close All values in ...
static splitRawArg(array $children)
Like splitArg() but for a raw child array.
splitArg()
Split a "<part>" node into an associative array containing:
getNextSibling()
Get the next sibling, or false if there is none.
static splitRawTemplate(array $children)
Like splitTemplate() but for a raw child array.
splitHeading()
Split an "<h>" node.
splitTemplate()
Split a "<template>" or "<tplarg>" node.
static splitRawHeading(array $children)
Like splitHeading() but for a raw child array.
static splitRawExt(array $children)
Like splitExt() but for a raw child array.
__construct(array $store, $index)
Construct an object using the data from $store[$index].
getChildrenOfType( $name)
Get an array of the children with a given node name.
__toString()
Convert a node to XML, for debugging.
const CHILDREN
The offset of the child list within descriptors, used in some places for readability.
getFirstChild()
Get the first child, or false if there is none.
getRawChildren()
Get the raw child array.
const NAME
The offset of the name within descriptors, used in some places for readability.
There are three types of nodes: