]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - vendor/wikimedia/remex-html/RemexHtml/TreeBuilder/TemplateModeStack.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / vendor / wikimedia / remex-html / RemexHtml / TreeBuilder / TemplateModeStack.php
1 <?php
2
3 namespace RemexHtml\TreeBuilder;
4
5 /**
6  * The stack of template insertion modes. We use a storage model optimised for
7  * access to the element at the top of the stack, which is stored separately
8  * from the rest of the stack.
9  */
10 class TemplateModeStack {
11         /**
12          * The insertion mode at the top of the stack. This is public for
13          * performance reasons but should be treated as read-only.
14          * @var integer|null
15          */
16         public $current;
17
18         /**
19          * The remainder of the stack
20          */
21         private $nonCurrentModes = [];
22
23         /**
24          * Push a mode on to the stack
25          * @param integer $mode
26          */
27         public function push( $mode ) {
28                 $this->nonCurrentModes[] = $this->current;
29                 $this->current = $mode;
30         }
31
32         /**
33          * Pop a mode from the stack
34          */
35         public function pop() {
36                 $this->current = array_pop( $this->nonCurrentModes );
37         }
38
39         /**
40          * Return true if the stack is empty, false otherwise
41          * @return bool
42          */
43         public function isEmpty() {
44                 return $this->current === null;
45         }
46 }