| 1 |
<?php |
| 2 |
|
| 3 |
namespace TablePress\PhpOffice\PhpSpreadsheet\Calculation\Engine; |
| 4 |
|
| 5 |
class CyclicReferenceStack |
| 6 |
{ |
| 7 |
/** |
| 8 |
* The call stack for calculated cells. |
| 9 |
* |
| 10 |
* @var mixed[] |
| 11 |
*/ |
| 12 |
private array $stack = []; |
| 13 |
|
| 14 |
/** |
| 15 |
* Return the number of entries on the stack. |
| 16 |
*/ |
| 17 |
public function count(): int |
| 18 |
{ |
| 19 |
return count($this->stack); |
| 20 |
} |
| 21 |
|
| 22 |
/** |
| 23 |
* Push a new entry onto the stack. |
| 24 |
* |
| 25 |
* @param int|string $value The value to test |
| 26 |
*/ |
| 27 |
public function push($value): void |
| 28 |
{ |
| 29 |
$this->stack[$value] = $value; |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* Pop the last entry from the stack. |
| 34 |
* @return mixed |
| 35 |
*/ |
| 36 |
public function pop() |
| 37 |
{ |
| 38 |
return array_pop($this->stack); |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Test to see if a specified entry exists on the stack. |
| 43 |
* |
| 44 |
* @param int|string $value The value to test |
| 45 |
*/ |
| 46 |
public function onStack($value): bool |
| 47 |
{ |
| 48 |
return isset($this->stack[$value]); |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Clear the stack. |
| 53 |
*/ |
| 54 |
public function clear(): void |
| 55 |
{ |
| 56 |
$this->stack = []; |
| 57 |
} |
| 58 |
|
| 59 |
/** |
| 60 |
* Return an array of all entries on the stack. |
| 61 |
* |
| 62 |
* @return mixed[] |
| 63 |
*/ |
| 64 |
public function showStack(): array |
| 65 |
{ |
| 66 |
return $this->stack; |
| 67 |
} |
| 68 |
} |
| 69 |
|