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
65 public function push( $data ) {
66 if ( $data instanceof $this->elementClass ) {
67 $this->stack[] = $data;
68 } else {
69 $class = $this->elementClass;
70 $this->stack[] = new $class( $data );
71 }
72 $this->top = $this->stack[count( $this->stack ) - 1];
73 $this->accum =& $this->top->getAccum();
74 }
75
77 public function pop() {
78 if ( $this->stack === [] ) {
79 throw new RuntimeException( __METHOD__ . ': no elements remaining' );
80 }
81 $temp = array_pop( $this->stack );
82
83 if ( count( $this->stack ) ) {
84 $this->top = $this->stack[count( $this->stack ) - 1];
85 $this->accum =& $this->top->getAccum();
86 } else {
87 $this->top = false;
88 $this->accum =& $this->rootAccum;
89 }
90 return $temp;
91 }
92
94 public function addPart( $s = '' ) {
95 $this->top->addPart( $s );
96 $this->accum =& $this->top->getAccum();
97 }
98
102 public function getFlags() {
103 if ( $this->stack === [] ) {
104 return [
105 'findEquals' => false,
106 'findPipe' => false,
107 'inHeading' => false,
108 ];
109 } else {
110 return $this->top->getFlags();
111 }
112 }
113}
114
116class_alias( PPDStack_Hash::class, 'PPDStack_Hash' );
Stack class to help Preprocessor::preprocessToObj()
PPDStackElement_Hash false $top
PPDStackElement_Hash[] $stack
class string< PPDStackElement_Hash > $elementClass