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
22 namespace MediaWiki\Parser
;
27 * Stack class to help Preprocessor::preprocessToObj()
30 // phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps
32 /** @var PPDStackElement_Hash[] */
40 * @var PPDStackElement_Hash|false
43 /** @var string|null */
46 public $elementClass = PPDStackElement_Hash
::class;
48 public function __construct() {
51 $this->rootAccum
= [];
52 $this->accum
=& $this->rootAccum
;
58 public function count() {
59 return count( $this->stack
);
62 public function &getAccum() {
67 * @return false|PPDPart_Hash
69 public function getCurrentPart() {
70 if ( $this->top
=== false ) {
73 return $this->top
->getCurrentPart();
77 public function push( $data ) {
78 if ( $data instanceof $this->elementClass
) {
79 $this->stack
[] = $data;
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();
99 $this->accum
=& $this->rootAccum
;
104 public function addPart( $s = '' ) {
105 $this->top
->addPart( $s );
106 $this->accum
=& $this->top
->getAccum();
112 public function getFlags() {
113 if ( $this->stack
=== [] ) {
115 'findEquals' => false,
117 'inHeading' => false,
120 return $this->top
->getFlags();
125 /** @deprecated class alias since 1.43 */
126 class_alias( PPDStack_Hash
::class, 'PPDStack_Hash' );