MediaWiki master
PPDStackElement_Hash.php
Go to the documentation of this file.
1<?php
8namespace MediaWiki\Parser;
9
16// phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps
21 public $open;
22
26 public $close;
27
32 public $savedPrefix = '';
33
37 public $startPos;
38
42 public $count;
43
47 public $parts;
48
53 public $lineStart;
54
56 public $partClass = PPDPart_Hash::class;
57
58 public function __construct( array $data = [] ) {
59 $class = $this->partClass;
60 $this->parts = [ new $class ];
61
62 foreach ( $data as $name => $value ) {
63 $this->$name = $value;
64 }
65 }
66
68 public function &getAccum() {
69 return $this->parts[count( $this->parts ) - 1]->out;
70 }
71
75 public function addPart( $s = '' ) {
76 $class = $this->partClass;
77 $this->parts[] = new $class( $s );
78 }
79
83 public function getCurrentPart() {
84 return $this->parts[count( $this->parts ) - 1];
85 }
86
90 public function getFlags() {
91 $partCount = count( $this->parts );
92 $findPipe = $this->open != "\n" && $this->open != '[';
93 return [
94 'findPipe' => $findPipe,
95 'findEquals' => $findPipe && $partCount > 1 && !isset( $this->parts[$partCount - 1]->eqpos ),
96 'inHeading' => $this->open == "\n",
97 ];
98 }
99
106 public function breakSyntax( $openingCount = false ) {
107 if ( $this->open == "\n" ) {
108 $accum = array_merge( [ $this->savedPrefix ], $this->parts[0]->out );
109 } else {
110 if ( $openingCount === false ) {
111 $openingCount = $this->count;
112 }
113 $s = substr( $this->open, 0, -1 );
114 $s .= str_repeat(
115 substr( $this->open, -1 ),
116 $openingCount - strlen( $s )
117 );
118 $accum = [ $this->savedPrefix . $s ];
119 $lastIndex = 0;
120 $first = true;
121 foreach ( $this->parts as $part ) {
122 if ( $first ) {
123 $first = false;
124 } elseif ( is_string( $accum[$lastIndex] ) ) {
125 $accum[$lastIndex] .= '|';
126 } else {
127 $accum[++$lastIndex] = '|';
128 }
129
130 foreach ( $part->out as $node ) {
131 if ( is_string( $node ) && is_string( $accum[$lastIndex] ) ) {
132 $accum[$lastIndex] .= $node;
133 } else {
134 $accum[++$lastIndex] = $node;
135 }
136 }
137 }
138 }
139 return $accum;
140 }
141}
142
144class_alias( PPDStackElement_Hash::class, 'PPDStackElement_Hash' );
string $close
Matching closing character.
string $savedPrefix
Saved prefix that may affect later processing, e.g.
int $startPos
Start offset of this element in the source wikitext.
breakSyntax( $openingCount=false)
Get the accumulator that would result if the close is not found.
class string< PPDPart_Hash > $partClass
bool $lineStart
True if the open char appeared at the start of the input line.
string $open
Opening character (\n for heading)
PPDPart_Hash[] $parts
Array of PPDPart objects describing pipe-separated parts.
int $count
Number of opening characters found (number of "=" for heading)