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
73 public function addPart( $s = '' ) {
74 $class = $this->partClass;
75 $this->parts[] = new $class( $s );
76 }
77
81 public function getCurrentPart() {
82 return $this->parts[count( $this->parts ) - 1];
83 }
84
88 public function getFlags() {
89 $partCount = count( $this->parts );
90 $findPipe = $this->open != "\n" && $this->open != '[';
91 return [
92 'findPipe' => $findPipe,
93 'findEquals' => $findPipe && $partCount > 1 && !isset( $this->parts[$partCount - 1]->eqpos ),
94 'inHeading' => $this->open == "\n",
95 ];
96 }
97
104 public function breakSyntax( $openingCount = false ) {
105 if ( $this->open == "\n" ) {
106 $accum = array_merge( [ $this->savedPrefix ], $this->parts[0]->out );
107 } else {
108 if ( $openingCount === false ) {
109 $openingCount = $this->count;
110 }
111 $s = substr( $this->open, 0, -1 );
112 $s .= str_repeat(
113 substr( $this->open, -1 ),
114 $openingCount - strlen( $s )
115 );
116 $accum = [ $this->savedPrefix . $s ];
117 $lastIndex = 0;
118 $first = true;
119 foreach ( $this->parts as $part ) {
120 if ( $first ) {
121 $first = false;
122 } elseif ( is_string( $accum[$lastIndex] ) ) {
123 $accum[$lastIndex] .= '|';
124 } else {
125 $accum[++$lastIndex] = '|';
126 }
127
128 foreach ( $part->out as $node ) {
129 if ( is_string( $node ) && is_string( $accum[$lastIndex] ) ) {
130 $accum[$lastIndex] .= $node;
131 } else {
132 $accum[++$lastIndex] = $node;
133 }
134 }
135 }
136 }
137 return $accum;
138 }
139}
140
142class_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)