MediaWiki master
PPNode_Hash_Attr.php
Go to the documentation of this file.
1<?php
8namespace MediaWiki\Parser;
9
10use InvalidArgumentException;
11use LogicException;
12use Stringable;
13
17// phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps
18class PPNode_Hash_Attr implements Stringable, PPNode {
19
21 public $name;
23 public $value;
25 private $store;
27 private $index;
28
36 public function __construct( array $store, $index ) {
37 $descriptor = $store[$index];
38 if ( $descriptor[PPNode_Hash_Tree::NAME][0] !== '@' ) {
39 throw new InvalidArgumentException( __METHOD__ . ': invalid name in attribute descriptor' );
40 }
41 $this->name = substr( $descriptor[PPNode_Hash_Tree::NAME], 1 );
42 $this->value = $descriptor[PPNode_Hash_Tree::CHILDREN][0];
43 $this->store = $store;
44 $this->index = $index;
45 }
46
47 public function __toString() {
48 return "<@{$this->name}>" . htmlspecialchars( $this->value, ENT_COMPAT ) . "</@{$this->name}>";
49 }
50
52 public function getName() {
53 return $this->name;
54 }
55
57 public function getNextSibling() {
58 return PPNode_Hash_Tree::factory( $this->store, $this->index + 1 );
59 }
60
62 public function getChildren() {
63 return false;
64 }
65
67 public function getFirstChild() {
68 return false;
69 }
70
72 public function getChildrenOfType( $name ) {
73 return false;
74 }
75
77 public function getLength() {
78 return false;
79 }
80
82 public function item( $i ) {
83 return false;
84 }
85
87 public function splitArg() {
88 // @phan-suppress-previous-line PhanPluginNeverReturnMethod
89 throw new LogicException( __METHOD__ . ': not supported' );
90 }
91
93 public function splitExt() {
94 // @phan-suppress-previous-line PhanPluginNeverReturnMethod
95 throw new LogicException( __METHOD__ . ': not supported' );
96 }
97
99 public function splitHeading() {
100 // @phan-suppress-previous-line PhanPluginNeverReturnMethod
101 throw new LogicException( __METHOD__ . ': not supported' );
102 }
103}
104
106class_alias( PPNode_Hash_Attr::class, 'PPNode_Hash_Attr' );
getChildrenOfType( $name)
Get all children of this tree node which have a given name.Returns an array-type node,...
splitArg()
Split a "<part>" node into an associative array containing: name PPNode name index String index value...
getName()
Get the name of this node.The following names are defined here:h A heading node. template A double-br...
item( $i)
Returns an item of an array-type node.PPNode|false
splitExt()
Split an "<ext>" node into an associative array containing name, attr, inner and close All values in ...
getNextSibling()
Get the next sibling of any node.False if there isn't one false|PPNode
getLength()
Returns the length of the array, or false if this is not an array-type node.
__construct(array $store, $index)
Construct an object using the data from $store[$index].
getChildren()
Get an array-type node containing the children of this node.Returns false if this is not a tree node....
splitHeading()
Split an "<h>" node.array
getFirstChild()
Get the first child of a tree node.False if there isn't one.false|PPNode
const CHILDREN
The offset of the child list within descriptors, used in some places for readability.
static factory(array $store, $index)
Construct an appropriate PPNode_Hash_* object with a class that depends on what is at the relevant st...
const NAME
The offset of the name within descriptors, used in some places for readability.
There are three types of nodes:
Definition PPNode.php:23