MediaWiki master
PPDStackElement_Hash.php
Go to the documentation of this file.
1<?php
22namespace MediaWiki\Parser;
23
30// phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps
35 public $open;
36
40 public $close;
41
46 public $savedPrefix = '';
47
51 public $startPos;
52
56 public $count;
57
61 public $parts;
62
67 public $lineStart;
68
70 public $partClass = PPDPart_Hash::class;
71
72 public function __construct( $data = [] ) {
73 $class = $this->partClass;
74 $this->parts = [ new $class ];
75
76 foreach ( $data as $name => $value ) {
77 $this->$name = $value;
78 }
79 }
80
81 public function &getAccum() {
82 return $this->parts[count( $this->parts ) - 1]->out;
83 }
84
85 public function addPart( $s = '' ) {
86 $class = $this->partClass;
87 $this->parts[] = new $class( $s );
88 }
89
93 public function getCurrentPart() {
94 return $this->parts[count( $this->parts ) - 1];
95 }
96
100 public function getFlags() {
101 $partCount = count( $this->parts );
102 $findPipe = $this->open != "\n" && $this->open != '[';
103 return [
104 'findPipe' => $findPipe,
105 'findEquals' => $findPipe && $partCount > 1 && !isset( $this->parts[$partCount - 1]->eqpos ),
106 'inHeading' => $this->open == "\n",
107 ];
108 }
109
116 public function breakSyntax( $openingCount = false ) {
117 if ( $this->open == "\n" ) {
118 $accum = array_merge( [ $this->savedPrefix ], $this->parts[0]->out );
119 } else {
120 if ( $openingCount === false ) {
121 $openingCount = $this->count;
122 }
123 $s = substr( $this->open, 0, -1 );
124 $s .= str_repeat(
125 substr( $this->open, -1 ),
126 $openingCount - strlen( $s )
127 );
128 $accum = [ $this->savedPrefix . $s ];
129 $lastIndex = 0;
130 $first = true;
131 foreach ( $this->parts as $part ) {
132 if ( $first ) {
133 $first = false;
134 } elseif ( is_string( $accum[$lastIndex] ) ) {
135 $accum[$lastIndex] .= '|';
136 } else {
137 $accum[++$lastIndex] = '|';
138 }
139
140 foreach ( $part->out as $node ) {
141 if ( is_string( $node ) && is_string( $accum[$lastIndex] ) ) {
142 $accum[$lastIndex] .= $node;
143 } else {
144 $accum[++$lastIndex] = $node;
145 }
146 }
147 }
148 }
149 return $accum;
150 }
151}
152
154class_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.
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)