CyclicReferenceStack.php 1.2 KB

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