Debian Codegraph @

vendor/wikimedia/remex-html/src/TreeBuilder/TemplateModeStack.php

raw
1 <?php
2
3 namespace Wikimedia\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 int|null
15 */
16 public $current;
17
18 /**
19 * The remainder of the stack
20 *
21 * @var array
22 */
23 private $nonCurrentModes = [];
24
25 /**
26 * Push a mode on to the stack
27 * @param int $mode
28 */
29 public function push( $mode ) {
30 $this->nonCurrentModes[] = $this->current;
31 $this->current = $mode;
32 }
33
34 /**
35 * Pop a mode from the stack
36 */
37 public function pop() {
38 $this->current = array_pop( $this->nonCurrentModes );
39 }
40
41 /**
42 * Return true if the stack is empty, false otherwise
43 * @return bool
44 */
45 public function isEmpty() {
46 return $this->current === null;
47 }
48 }