MediaWiki master
PPNode_Hash_Attr.php
Go to the documentation of this file.
1<?php
22namespace MediaWiki\Parser;
23
24use InvalidArgumentException;
25use LogicException;
26use Stringable;
27
31// phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps
32class PPNode_Hash_Attr implements Stringable, PPNode {
33
35 public $name;
37 public $value;
39 private $store;
41 private $index;
42
50 public function __construct( array $store, $index ) {
51 $descriptor = $store[$index];
52 if ( $descriptor[PPNode_Hash_Tree::NAME][0] !== '@' ) {
53 throw new InvalidArgumentException( __METHOD__ . ': invalid name in attribute descriptor' );
54 }
55 $this->name = substr( $descriptor[PPNode_Hash_Tree::NAME], 1 );
56 $this->value = $descriptor[PPNode_Hash_Tree::CHILDREN][0];
57 $this->store = $store;
58 $this->index = $index;
59 }
60
61 public function __toString() {
62 return "<@{$this->name}>" . htmlspecialchars( $this->value, ENT_COMPAT ) . "</@{$this->name}>";
63 }
64
65 public function getName() {
66 return $this->name;
67 }
68
69 public function getNextSibling() {
70 return PPNode_Hash_Tree::factory( $this->store, $this->index + 1 );
71 }
72
73 public function getChildren() {
74 return false;
75 }
76
77 public function getFirstChild() {
78 return false;
79 }
80
81 public function getChildrenOfType( $name ) {
82 return false;
83 }
84
85 public function getLength() {
86 return false;
87 }
88
89 public function item( $i ) {
90 return false;
91 }
92
93 public function splitArg() {
94 // @phan-suppress-previous-line PhanPluginNeverReturnMethod
95 throw new LogicException( __METHOD__ . ': not supported' );
96 }
97
98 public function splitExt() {
99 // @phan-suppress-previous-line PhanPluginNeverReturnMethod
100 throw new LogicException( __METHOD__ . ': not supported' );
101 }
102
103 public function splitHeading() {
104 // @phan-suppress-previous-line PhanPluginNeverReturnMethod
105 throw new LogicException( __METHOD__ . ': not supported' );
106 }
107}
108
110class_alias( PPNode_Hash_Attr::class, 'PPNode_Hash_Attr' );
getChildrenOfType( $name)
Get all children of this tree node which have a given name.
splitArg()
Split a "<part>" node into an associative array containing: name PPNode name index String index value...
getName()
Get the name of this node.
item( $i)
Returns an item of an array-type node.
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.
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.
getFirstChild()
Get the first child of a tree node.
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:37