/deprecated/includes/stack.class.php

  1. <?php if ( ! defined( 'ABSPATH' ) ) exit; 
  2.  
  3. /** 
  4. * Basic Stack Class 
  5. * 
  6. * Created for use with eqEOS. May eventually be replaced with native 
  7. * PHP functions `array_pop()`, `array_push()`, and `end()` 
  8. * 
  9. * @author Jon Lawrence <jlawrence11@gmail.com> 
  10. * @copyright Copyright *2005-2013 Jon Lawrence 
  11. * @license http://opensource.org/licenses/LGPL-2.1 LGPL 2.1 License 
  12. * @package eos.class.php 
  13. * @version 2.0 
  14. */ 
  15. class phpStack { 
  16. private $index; 
  17. private $locArray; 
  18.  
  19. /** 
  20. * Constructor 
  21. * 
  22. * Initializes the stack 
  23. */ 
  24. public function __construct() { 
  25. //define the private vars 
  26. $this->locArray = array(); 
  27. $this->index = -1; 
  28.  
  29. /** 
  30. * Peek 
  31. * 
  32. * Will view the last element of the stack without removing it 
  33. * 
  34. * @return Mixed An element of the array or false if none exist 
  35. */ 
  36. public function peek() { 
  37. if($this->index > -1) 
  38. return $this->locArray[$this->index]; 
  39. else 
  40. return false; 
  41.  
  42. /** 
  43. * Poke 
  44. * 
  45. * Will add an element to the end of the stack 
  46. * 
  47. * @param Mixed Element to add 
  48. */ 
  49. public function poke($data) { 
  50. $this->locArray[++$this->index] = $data; 
  51.  
  52. /** 
  53. * Push 
  54. * 
  55. * Alias of {@see phpStack::poke()} 
  56. * Adds element to the stack 
  57. * 
  58. * @param Mixed Element to add 
  59. */ 
  60. public function push($data) { 
  61. //allias for 'poke' 
  62. $this->poke($data); 
  63.  
  64. /** 
  65. * Pop 
  66. * 
  67. * Retrives an element from the end of the stack, and removes it from 
  68. * the stack at the same time. If no elements, returns boolean false 
  69. * 
  70. * @return Mixed Element at end of stack or false if none exist 
  71. */ 
  72. public function pop() { 
  73. if($this->index > -1) 
  74. $this->index--; 
  75. return $this->locArray[$this->index+1]; 
  76. else 
  77. return false; 
  78.  
  79. /** 
  80. * Clear 
  81. * 
  82. * Clears the stack to be reused. 
  83. */ 
  84. public function clear() { 
  85. $this->index = -1; 
  86. $this->locArray = array(); 
  87.  
  88. /** 
  89. * Get Stack 
  90. * 
  91. * Returns the array of stack elements, keeping all, indexed at 0 
  92. * 
  93. * @return Mixed Array of stack elements or false if none exist. 
  94. */ 
  95. public function getStack() { 
  96. if($this->index > -1) 
  97. return array_values($this->locArray); 
  98. else 
  99. return false; 
  100.  
  101. ?> 
.