MediaWiki  1.34.0
PPDStack.php
Go to the documentation of this file.
1 <?php
26 class PPDStack {
28  public $stack;
29  public $rootAccum;
31  public $accum;
32 
36  public $top;
37  public $out;
38  public $elementClass = PPDStackElement::class;
39 
40  public static $false = false;
41 
42  public function __construct() {
43  $this->stack = [];
44  $this->top = false;
45  $this->rootAccum = '';
46  $this->accum =& $this->rootAccum;
47  }
48 
52  public function count() {
53  return count( $this->stack );
54  }
55 
56  public function &getAccum() {
57  return $this->accum;
58  }
59 
63  public function getCurrentPart() {
64  if ( $this->top === false ) {
65  return false;
66  } else {
67  return $this->top->getCurrentPart();
68  }
69  }
70 
71  public function push( $data ) {
72  if ( $data instanceof $this->elementClass ) {
73  $this->stack[] = $data;
74  } else {
75  $class = $this->elementClass;
76  $this->stack[] = new $class( $data );
77  }
78  $this->top = $this->stack[count( $this->stack ) - 1];
79  $this->accum =& $this->top->getAccum();
80  }
81 
82  public function pop() {
83  if ( $this->stack === [] ) {
84  throw new MWException( __METHOD__ . ': no elements remaining' );
85  }
86  $temp = array_pop( $this->stack );
87 
88  if ( count( $this->stack ) ) {
89  $this->top = $this->stack[count( $this->stack ) - 1];
90  $this->accum =& $this->top->getAccum();
91  } else {
92  $this->top = self::$false;
93  $this->accum =& $this->rootAccum;
94  }
95  return $temp;
96  }
97 
98  public function addPart( $s = '' ) {
99  $this->top->addPart( $s );
100  $this->accum =& $this->top->getAccum();
101  }
102 
106  public function getFlags() {
107  if ( $this->stack === [] ) {
108  return [
109  'findEquals' => false,
110  'findPipe' => false,
111  'inHeading' => false,
112  ];
113  } else {
114  return $this->top->getFlags();
115  }
116  }
117 }
PPDStack\pop
pop()
Definition: PPDStack.php:82
PPDStack\push
push( $data)
Definition: PPDStack.php:71
PPDStack\$false
static $false
Definition: PPDStack.php:40
PPDStack\$elementClass
$elementClass
Definition: PPDStack.php:38
$s
$s
Definition: mergeMessageFileList.php:185
PPDStackElement
Definition: PPDStackElement.php:27
PPDStack\getAccum
& getAccum()
Definition: PPDStack.php:56
PPDStack\$accum
string array $accum
Definition: PPDStack.php:31
PPDStack\count
count()
Definition: PPDStack.php:52
MWException
MediaWiki exception.
Definition: MWException.php:26
PPDStack\$top
PPDStackElement false $top
Definition: PPDStack.php:36
PPDStack\$rootAccum
$rootAccum
Definition: PPDStack.php:29
PPDStack\addPart
addPart( $s='')
Definition: PPDStack.php:98
PPDStack\__construct
__construct()
Definition: PPDStack.php:42
PPDStack\$out
$out
Definition: PPDStack.php:37
PPDStack
Stack class to help Preprocessor::preprocessToObj()
Definition: PPDStack.php:26
PPDStack\$stack
PPDStackElement[] $stack
Definition: PPDStack.php:28
PPDStack\getCurrentPart
getCurrentPart()
Definition: PPDStack.php:63
PPDStack\getFlags
getFlags()
Definition: PPDStack.php:106