MediaWiki fundraising/REL1_35
PPDStackElement.php
Go to the documentation of this file.
1<?php
31 public $open;
32
36 public $close;
37
42 public $savedPrefix = '';
43
47 public $count;
48
52 public $parts;
53
58 public $lineStart;
59
60 public $partClass = PPDPart::class;
61
62 public function __construct( $data = [] ) {
63 $class = $this->partClass;
64 $this->parts = [ new $class ];
65
66 foreach ( $data as $name => $value ) {
67 $this->$name = $value;
68 }
69 }
70
71 public function &getAccum() {
72 return $this->parts[count( $this->parts ) - 1]->out;
73 }
74
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 $s = $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 $s = $this->savedPrefix . $s;
119 $first = true;
120 foreach ( $this->parts as $part ) {
121 if ( $first ) {
122 $first = false;
123 } else {
124 $s .= '|';
125 }
126 $s .= $part->out;
127 }
128 }
129 return $s;
130 }
131}
string $open
Opening character (\n for heading)
bool $lineStart
True if the open char appeared at the start of the input line.
PPDPart[] $parts
Array of PPDPart objects describing pipe-separated parts.
string $savedPrefix
Saved prefix that may affect later processing, e.g.
string $close
Matching closing character.
__construct( $data=[])
breakSyntax( $openingCount=false)
Get the output string that would result if the close is not found.
int $count
Number of opening characters found (number of "=" for heading)