| 1 |
<?php |
| 2 |
|
| 3 |
namespace StoreEngine\Classes\EvalMath; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; |
| 7 |
} |
| 8 |
|
| 9 |
/** |
| 10 |
* Class EvalMathStack |
| 11 |
* |
| 12 |
* Expression-evaluator stack. |
| 13 |
*/ |
| 14 |
class EvalMathStack { |
| 15 |
|
| 16 |
/** |
| 17 |
* Stack array. |
| 18 |
* |
| 19 |
* @var array |
| 20 |
*/ |
| 21 |
public $stack = array(); |
| 22 |
|
| 23 |
/** |
| 24 |
* Stack counter. |
| 25 |
* |
| 26 |
* @var integer |
| 27 |
*/ |
| 28 |
public $count = 0; |
| 29 |
|
| 30 |
/** |
| 31 |
* Push value into stack. |
| 32 |
* |
| 33 |
* @param mixed $val |
| 34 |
*/ |
| 35 |
public function push( $val ) { |
| 36 |
$this->stack[ $this->count ] = $val; |
| 37 |
$this->count++; |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Pop value from stack. |
| 42 |
* |
| 43 |
* @return mixed |
| 44 |
*/ |
| 45 |
public function pop() { |
| 46 |
if ( $this->count > 0 ) { |
| 47 |
$this->count--; |
| 48 |
return $this->stack[ $this->count ]; |
| 49 |
} |
| 50 |
return null; |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Get last value from stack. |
| 55 |
* |
| 56 |
* @param int $n |
| 57 |
* |
| 58 |
* @return mixed |
| 59 |
*/ |
| 60 |
public function last( $n = 1 ) { |
| 61 |
$key = $this->count - $n; |
| 62 |
return array_key_exists( $key, $this->stack ) ? $this->stack[ $key ] : null; |
| 63 |
} |
| 64 |
} |
| 65 |
|