MediaWiki  master
PPDStackElement_Hash.php
Go to the documentation of this file.
1 <?php
28 // phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps
33  public $open;
34 
38  public $close;
39 
44  public $savedPrefix = '';
45 
49  public $count;
50 
54  public $parts;
55 
60  public $lineStart;
61 
63  public $partClass = PPDPart_Hash::class;
64 
65  public function __construct( $data = [] ) {
66  $class = $this->partClass;
67  $this->parts = [ new $class ];
68 
69  foreach ( $data as $name => $value ) {
70  $this->$name = $value;
71  }
72  }
73 
74  public function &getAccum() {
75  return $this->parts[count( $this->parts ) - 1]->out;
76  }
77 
78  public function addPart( $s = '' ) {
79  $class = $this->partClass;
80  $this->parts[] = new $class( $s );
81  }
82 
86  public function getCurrentPart() {
87  return $this->parts[count( $this->parts ) - 1];
88  }
89 
93  public function getFlags() {
94  $partCount = count( $this->parts );
95  $findPipe = $this->open != "\n" && $this->open != '[';
96  return [
97  'findPipe' => $findPipe,
98  'findEquals' => $findPipe && $partCount > 1 && !isset( $this->parts[$partCount - 1]->eqpos ),
99  'inHeading' => $this->open == "\n",
100  ];
101  }
102 
109  public function breakSyntax( $openingCount = false ) {
110  if ( $this->open == "\n" ) {
111  $accum = array_merge( [ $this->savedPrefix ], $this->parts[0]->out );
112  } else {
113  if ( $openingCount === false ) {
114  $openingCount = $this->count;
115  }
116  $s = substr( $this->open, 0, -1 );
117  $s .= str_repeat(
118  substr( $this->open, -1 ),
119  $openingCount - strlen( $s )
120  );
121  $accum = [ $this->savedPrefix . $s ];
122  $lastIndex = 0;
123  $first = true;
124  foreach ( $this->parts as $part ) {
125  if ( $first ) {
126  $first = false;
127  } elseif ( is_string( $accum[$lastIndex] ) ) {
128  $accum[$lastIndex] .= '|';
129  } else {
130  $accum[++$lastIndex] = '|';
131  }
132 
133  foreach ( $part->out as $node ) {
134  if ( is_string( $node ) && is_string( $accum[$lastIndex] ) ) {
135  $accum[$lastIndex] .= $node;
136  } else {
137  $accum[++$lastIndex] = $node;
138  }
139  }
140  }
141  }
142  return $accum;
143  }
144 }
PPDPart_Hash
Definition: PPDPart_Hash.php:31
PPDStackElement_Hash\getCurrentPart
getCurrentPart()
Definition: PPDStackElement_Hash.php:86
PPDStackElement_Hash\$parts
PPDPart_Hash[] $parts
Array of PPDPart objects describing pipe-separated parts.
Definition: PPDStackElement_Hash.php:54
PPDStackElement_Hash\$count
int $count
Number of opening characters found (number of "=" for heading)
Definition: PPDStackElement_Hash.php:49
PPDStackElement_Hash\$open
string $open
Opening character (\n for heading)
Definition: PPDStackElement_Hash.php:33
PPDStackElement_Hash
Definition: PPDStackElement_Hash.php:29
PPDStackElement_Hash\addPart
addPart( $s='')
Definition: PPDStackElement_Hash.php:78
PPDStackElement_Hash\__construct
__construct( $data=[])
Definition: PPDStackElement_Hash.php:65
PPDStackElement_Hash\$partClass
string $partClass
Definition: PPDStackElement_Hash.php:63
$s
foreach( $mmfl['setupFiles'] as $fileName) if( $queue) if(empty( $mmfl['quiet'])) $s
Definition: mergeMessageFileList.php:206
PPDStackElement_Hash\getAccum
& getAccum()
Definition: PPDStackElement_Hash.php:74
PPDStackElement_Hash\$lineStart
bool $lineStart
True if the open char appeared at the start of the input line.
Definition: PPDStackElement_Hash.php:60
PPDStackElement_Hash\breakSyntax
breakSyntax( $openingCount=false)
Get the accumulator that would result if the close is not found.
Definition: PPDStackElement_Hash.php:109
PPDStackElement_Hash\$savedPrefix
string $savedPrefix
Saved prefix that may affect later processing, e.g.
Definition: PPDStackElement_Hash.php:44
PPDStackElement_Hash\getFlags
getFlags()
Definition: PPDStackElement_Hash.php:93
PPDStackElement_Hash\$close
string $close
Matching closing character.
Definition: PPDStackElement_Hash.php:38