MediaWiki master
PPDStack_Hash.php
Go to the documentation of this file.
1<?php
22namespace MediaWiki\Parser;
23
24use RuntimeException;
25
30// phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps
33 public $stack;
35 public $rootAccum;
37 public $accum;
38
42 public $top;
44 public $out;
46 public $elementClass = PPDStackElement_Hash::class;
47
48 public function __construct() {
49 $this->stack = [];
50 $this->top = false;
51 $this->rootAccum = [];
52 $this->accum =& $this->rootAccum;
53 }
54
58 public function count() {
59 return count( $this->stack );
60 }
61
62 public function &getAccum() {
63 return $this->accum;
64 }
65
69 public function getCurrentPart() {
70 if ( $this->top === false ) {
71 return false;
72 } else {
73 return $this->top->getCurrentPart();
74 }
75 }
76
77 public function push( $data ) {
78 if ( $data instanceof $this->elementClass ) {
79 $this->stack[] = $data;
80 } else {
81 $class = $this->elementClass;
82 $this->stack[] = new $class( $data );
83 }
84 $this->top = $this->stack[count( $this->stack ) - 1];
85 $this->accum =& $this->top->getAccum();
86 }
87
88 public function pop() {
89 if ( $this->stack === [] ) {
90 throw new RuntimeException( __METHOD__ . ': no elements remaining' );
91 }
92 $temp = array_pop( $this->stack );
93
94 if ( count( $this->stack ) ) {
95 $this->top = $this->stack[count( $this->stack ) - 1];
96 $this->accum =& $this->top->getAccum();
97 } else {
98 $this->top = false;
99 $this->accum =& $this->rootAccum;
100 }
101 return $temp;
102 }
103
104 public function addPart( $s = '' ) {
105 $this->top->addPart( $s );
106 $this->accum =& $this->top->getAccum();
107 }
108
112 public function getFlags() {
113 if ( $this->stack === [] ) {
114 return [
115 'findEquals' => false,
116 'findPipe' => false,
117 'inHeading' => false,
118 ];
119 } else {
120 return $this->top->getFlags();
121 }
122 }
123}
124
126class_alias( PPDStack_Hash::class, 'PPDStack_Hash' );
Stack class to help Preprocessor::preprocessToObj()
PPDStackElement_Hash false $top
PPDStackElement_Hash[] $stack