MediaWiki  master
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 }
Stack class to help Preprocessor::preprocessToObj()
Definition: PPDStack.php:26
getCurrentPart()
Definition: PPDStack.php:63
static $false
Definition: PPDStack.php:40
push( $data)
Definition: PPDStack.php:71
& getAccum()
Definition: PPDStack.php:56
addPart( $s='')
Definition: PPDStack.php:98
getFlags()
Definition: PPDStack.php:106
PPDStackElement [] $stack
Definition: PPDStack.php:28
__construct()
Definition: PPDStack.php:42
PPDStackElement false $top
Definition: PPDStack.php:36
$elementClass
Definition: PPDStack.php:38
string array $accum
Definition: PPDStack.php:31