sfActionStack.class.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /*
  3. * This file is part of the symfony package.
  4. * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
  5. * (c) 2004-2006 Sean Kerr <sean@code-box.org>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. /**
  11. * sfActionStack keeps a list of all requested actions and provides accessor
  12. * methods for retrieving individual entries.
  13. *
  14. * @package symfony
  15. * @subpackage action
  16. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  17. * @author Sean Kerr <sean@code-box.org>
  18. * @version SVN: $Id: sfActionStack.class.php 17858 2009-05-01 21:22:50Z FabianLange $
  19. */
  20. class sfActionStack
  21. {
  22. protected
  23. $stack = array();
  24. /**
  25. * Adds an entry to the action stack.
  26. *
  27. * @param string $moduleName A module name
  28. * @param string $actionName An action name
  29. * @param sfAction $actionInstance An sfAction implementation instance
  30. *
  31. * @return sfActionStackEntry sfActionStackEntry instance
  32. */
  33. public function addEntry($moduleName, $actionName, $actionInstance)
  34. {
  35. // create our action stack entry and add it to our stack
  36. $actionEntry = new sfActionStackEntry($moduleName, $actionName, $actionInstance);
  37. $this->stack[] = $actionEntry;
  38. return $actionEntry;
  39. }
  40. /**
  41. * Retrieves the entry at a specific index.
  42. *
  43. * @param int $index An entry index
  44. *
  45. * @return sfActionStackEntry An action stack entry implementation.
  46. */
  47. public function getEntry($index)
  48. {
  49. $retval = null;
  50. if ($index > -1 && $index < count($this->stack))
  51. {
  52. $retval = $this->stack[$index];
  53. }
  54. return $retval;
  55. }
  56. /**
  57. * Removes the entry at a specific index.
  58. *
  59. * @return sfActionStackEntry An action stack entry implementation.
  60. */
  61. public function popEntry()
  62. {
  63. return array_pop($this->stack);
  64. }
  65. /**
  66. * Retrieves the first entry.
  67. *
  68. * @return mixed An action stack entry implementation or null if there is no sfAction instance in the stack
  69. */
  70. public function getFirstEntry()
  71. {
  72. $retval = null;
  73. if (isset($this->stack[0]))
  74. {
  75. $retval = $this->stack[0];
  76. }
  77. return $retval;
  78. }
  79. /**
  80. * Retrieves the last entry.
  81. *
  82. * @return mixed An action stack entry implementation or null if there is no sfAction instance in the stack
  83. */
  84. public function getLastEntry()
  85. {
  86. $count = count($this->stack);
  87. $retval = null;
  88. if (isset($this->stack[0]))
  89. {
  90. $retval = $this->stack[$count - 1];
  91. }
  92. return $retval;
  93. }
  94. /**
  95. * Retrieves the size of this stack.
  96. *
  97. * @return int The size of this stack.
  98. */
  99. public function getSize()
  100. {
  101. return count($this->stack);
  102. }
  103. }