MediaWiki master
PPDStack_Hash.php
Go to the documentation of this file.
1<?php
8namespace MediaWiki\Parser;
9
10use RuntimeException;
11
16// phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps
19 public $stack;
21 public $rootAccum;
23 public $accum;
24
28 public $top;
30 public $out;
32 public $elementClass = PPDStackElement_Hash::class;
33
34 public function __construct() {
35 $this->stack = [];
36 $this->top = false;
37 $this->rootAccum = [];
38 $this->accum =& $this->rootAccum;
39 }
40
44 public function count() {
45 return count( $this->stack );
46 }
47
49 public function &getAccum() {
50 return $this->accum;
51 }
52
56 public function getCurrentPart() {
57 if ( $this->top === false ) {
58 return false;
59 } else {
60 return $this->top->getCurrentPart();
61 }
62 }
63
67 public function push( $data ) {
68 if ( $data instanceof $this->elementClass ) {
69 $this->stack[] = $data;
70 } else {
71 $class = $this->elementClass;
72 $this->stack[] = new $class( $data );
73 }
74 $this->top = $this->stack[count( $this->stack ) - 1];
75 $this->accum =& $this->top->getAccum();
76 }
77
79 public function pop() {
80 if ( $this->stack === [] ) {
81 throw new RuntimeException( __METHOD__ . ': no elements remaining' );
82 }
83 $temp = array_pop( $this->stack );
84
85 if ( count( $this->stack ) ) {
86 $this->top = $this->stack[count( $this->stack ) - 1];
87 $this->accum =& $this->top->getAccum();
88 } else {
89 $this->top = false;
90 $this->accum =& $this->rootAccum;
91 }
92 return $temp;
93 }
94
98 public function addPart( $s = '' ) {
99 $this->top->addPart( $s );
100 $this->accum =& $this->top->getAccum();
101 }
102
106 public function getFlags() {
107 if ( $this->stack === [] ) {
108 return [
109 'findEquals' => false,
110 'findPipe' => false,
111 'inHeading' => false,
112 ];
113 } else {
114 return $this->top->getFlags();
115 }
116 }
117}
118
120class_alias( PPDStack_Hash::class, 'PPDStack_Hash' );
Stack class to help Preprocessor::preprocessToObj()
PPDStackElement_Hash false $top
PPDStackElement_Hash[] $stack
class string< PPDStackElement_Hash > $elementClass