CyclicReferenceStack.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * PHPExcel_CalcEngine_CyclicReferenceStack
  4. *
  5. * Copyright (c) 2006 - 2015 PHPExcel
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * @category PHPExcel
  22. * @package PHPExcel_Calculation
  23. * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version ##VERSION##, ##DATE##
  26. */
  27. class PHPExcel_CalcEngine_CyclicReferenceStack
  28. {
  29. /**
  30. * The call stack for calculated cells
  31. *
  32. * @var mixed[]
  33. */
  34. private $stack = array();
  35. /**
  36. * Return the number of entries on the stack
  37. *
  38. * @return integer
  39. */
  40. public function count()
  41. {
  42. return count($this->stack);
  43. }
  44. /**
  45. * Push a new entry onto the stack
  46. *
  47. * @param mixed $value
  48. */
  49. public function push($value)
  50. {
  51. $this->stack[$value] = $value;
  52. }
  53. /**
  54. * Pop the last entry from the stack
  55. *
  56. * @return mixed
  57. */
  58. public function pop()
  59. {
  60. return array_pop($this->stack);
  61. }
  62. /**
  63. * Test to see if a specified entry exists on the stack
  64. *
  65. * @param mixed $value The value to test
  66. */
  67. public function onStack($value)
  68. {
  69. return isset($this->stack[$value]);
  70. }
  71. /**
  72. * Clear the stack
  73. */
  74. public function clear()
  75. {
  76. $this->stack = array();
  77. }
  78. /**
  79. * Return an array of all entries on the stack
  80. *
  81. * @return mixed[]
  82. */
  83. public function showStack()
  84. {
  85. return $this->stack;
  86. }
  87. }