| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
namespace MediaWiki\Parser; |
| 23 |
|
| 24 |
use RuntimeException; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
class PPDStack_Hash { |
| 32 |
|
| 33 |
public $stack; |
| 34 |
|
| 35 |
public $rootAccum; |
| 36 |
|
| 37 |
public $accum; |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
public $top; |
| 43 |
|
| 44 |
public $out; |
| 45 |
|
| 46 |
public $elementClass = PPDStackElement_Hash::class; |
| 47 |
|
| 48 |
public function __construct() { |
| 49 |
$this->stack = []; |
| 50 |
$this->top = false; |
| 51 |
$this->rootAccum = []; |
| 52 |
$this->accum =& $this->rootAccum; |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
public function count() { |
| 59 |
return count( $this->stack ); |
| 60 |
} |
| 61 |
|
| 62 |
public function &getAccum() { |
| 63 |
return $this->accum; |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
public function getCurrentPart() { |
| 70 |
if ( $this->top === false ) { |
| 71 |
return false; |
| 72 |
} else { |
| 73 |
return $this->top->getCurrentPart(); |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
public function push( $data ) { |
| 78 |
if ( $data instanceof $this->elementClass ) { |
| 79 |
$this->stack[] = $data; |
| 80 |
} else { |
| 81 |
$class = $this->elementClass; |
| 82 |
$this->stack[] = new $class( $data ); |
| 83 |
} |
| 84 |
$this->top = $this->stack[count( $this->stack ) - 1]; |
| 85 |
$this->accum =& $this->top->getAccum(); |
| 86 |
} |
| 87 |
|
| 88 |
public function pop() { |
| 89 |
if ( $this->stack === [] ) { |
| 90 |
throw new RuntimeException( __METHOD__ . ': no elements remaining' ); |
| 91 |
} |
| 92 |
$temp = array_pop( $this->stack ); |
| 93 |
|
| 94 |
if ( count( $this->stack ) ) { |
| 95 |
$this->top = $this->stack[count( $this->stack ) - 1]; |
| 96 |
$this->accum =& $this->top->getAccum(); |
| 97 |
} else { |
| 98 |
$this->top = false; |
| 99 |
$this->accum =& $this->rootAccum; |
| 100 |
} |
| 101 |
return $temp; |
| 102 |
} |
| 103 |
|
| 104 |
public function addPart( $s = '' ) { |
| 105 |
$this->top->addPart( $s ); |
| 106 |
$this->accum =& $this->top->getAccum(); |
| 107 |
} |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
public function getFlags() { |
| 113 |
if ( $this->stack === [] ) { |
| 114 |
return [ |
| 115 |
'findEquals' => false, |
| 116 |
'findPipe' => false, |
| 117 |
'inHeading' => false, |
| 118 |
]; |
| 119 |
} else { |
| 120 |
return $this->top->getFlags(); |
| 121 |
} |
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
class_alias( PPDStack_Hash::class, 'PPDStack_Hash' ); |