MediaWiki  1.34.0
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 }
PPDPart
Definition: PPDPart.php:29
PPDStackElement\__construct
__construct( $data=[])
Definition: PPDStackElement.php:62
PPDStackElement\$parts
PPDPart[] $parts
Array of PPDPart objects describing pipe-separated parts.
Definition: PPDStackElement.php:52
PPDStackElement\getCurrentPart
getCurrentPart()
Definition: PPDStackElement.php:83
$s
$s
Definition: mergeMessageFileList.php:185
PPDStackElement
Definition: PPDStackElement.php:27
PPDStackElement\$close
string $close
Matching closing character.
Definition: PPDStackElement.php:36
PPDStackElement\getAccum
& getAccum()
Definition: PPDStackElement.php:71
PPDStackElement\$lineStart
bool $lineStart
True if the open char appeared at the start of the input line.
Definition: PPDStackElement.php:58
PPDStackElement\breakSyntax
breakSyntax( $openingCount=false)
Get the output string that would result if the close is not found.
Definition: PPDStackElement.php:106
PPDStackElement\getFlags
getFlags()
Definition: PPDStackElement.php:90
PPDStackElement\addPart
addPart( $s='')
Definition: PPDStackElement.php:75
PPDStackElement\$count
int $count
Number of opening characters found (number of "=" for heading)
Definition: PPDStackElement.php:47
PPDStackElement\$partClass
$partClass
Definition: PPDStackElement.php:60
PPDStackElement\$open
string $open
Opening character (\n for heading)
Definition: PPDStackElement.php:31
PPDStackElement\$savedPrefix
string $savedPrefix
Saved prefix that may affect later processing, e.g.
Definition: PPDStackElement.php:42