Merge "mediawiki.api: Remove console warning for legacy token type"
[mediawiki.git] / includes / parser / PPDStack_Hash.php
blob386f75a86882e80806dd7c5dbd6158072f8ad150
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
18 * @file
19 * @ingroup Parser
22 namespace MediaWiki\Parser;
24 use RuntimeException;
26 /**
27 * Stack class to help Preprocessor::preprocessToObj()
28 * @ingroup Parser
30 // phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps
31 class PPDStack_Hash {
32 /** @var PPDStackElement_Hash[] */
33 public $stack;
34 /** @var string[] */
35 public $rootAccum;
36 /** @var string[] */
37 public $accum;
39 /**
40 * @var PPDStackElement_Hash|false
42 public $top;
43 /** @var string|null */
44 public $out;
45 /** @var string */
46 public $elementClass = PPDStackElement_Hash::class;
48 public function __construct() {
49 $this->stack = [];
50 $this->top = false;
51 $this->rootAccum = [];
52 $this->accum =& $this->rootAccum;
55 /**
56 * @return int
58 public function count() {
59 return count( $this->stack );
62 public function &getAccum() {
63 return $this->accum;
66 /**
67 * @return false|PPDPart_Hash
69 public function getCurrentPart() {
70 if ( $this->top === false ) {
71 return false;
72 } else {
73 return $this->top->getCurrentPart();
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 );
84 $this->top = $this->stack[count( $this->stack ) - 1];
85 $this->accum =& $this->top->getAccum();
88 public function pop() {
89 if ( $this->stack === [] ) {
90 throw new RuntimeException( __METHOD__ . ': no elements remaining' );
92 $temp = array_pop( $this->stack );
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;
101 return $temp;
104 public function addPart( $s = '' ) {
105 $this->top->addPart( $s );
106 $this->accum =& $this->top->getAccum();
110 * @return array
112 public function getFlags() {
113 if ( $this->stack === [] ) {
114 return [
115 'findEquals' => false,
116 'findPipe' => false,
117 'inHeading' => false,
119 } else {
120 return $this->top->getFlags();
125 /** @deprecated class alias since 1.43 */
126 class_alias( PPDStack_Hash::class, 'PPDStack_Hash' );