add Horde_Support_Stack
authorChuck Hagenbuch <chuck@horde.org>
Mon, 8 Jun 2009 14:48:35 +0000 (10:48 -0400)
committerChuck Hagenbuch <chuck@horde.org>
Mon, 8 Jun 2009 14:48:35 +0000 (10:48 -0400)
framework/Support/lib/Horde/Support/Stack.php [new file with mode: 0644]
framework/Support/package.xml

diff --git a/framework/Support/lib/Horde/Support/Stack.php b/framework/Support/lib/Horde/Support/Stack.php
new file mode 100644 (file)
index 0000000..30499f7
--- /dev/null
@@ -0,0 +1,48 @@
+<?php
+/**
+ * @category   Horde
+ * @package    Support
+ * @copyright  2008-2009 The Horde Project (http://www.horde.org/)
+ * @license    http://opensource.org/licenses/bsd-license.php
+ */
+
+/**
+ * Simple class for using an array as a stack.
+ *
+ * @category   Horde
+ * @package    Support
+ * @copyright  2008-2009 The Horde Project (http://www.horde.org/)
+ * @license    http://opensource.org/licenses/bsd-license.php
+ */
+class Horde_Support_Stack
+{
+    /**
+     * @var array
+     */
+    protected $_stack = array();
+
+    public function __construct($stack = array())
+    {
+        $this->_a = $stack;
+    }
+
+    public function push($value)
+    {
+        $this->_stack[] = $value;
+    }
+
+    public function pop()
+    {
+        return array_pop($this->_stack);
+    }
+
+    public function peek($offset = 1)
+    {
+        if (isset($this->_stack[count($this->_stack) - $offset])) {
+            return $this->_stack[count($this->_stack) - $offset];
+        } else {
+            return null;
+        }
+    }
+
+}
index 470adcc..d882740 100644 (file)
@@ -29,6 +29,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
    * Initial Horde_Support_Array object
    * Initial Horde_Support_ConsistentHash object
    * Initial Horde_Support_Inflector object
+   * Initial Horde_Support_Stack object
    * Initial Horde_Support_Stub object
    * Initial Horde_Support_Timer object
    * Initial Horde_Support_Uuid object
@@ -49,6 +50,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
       <file name="ConsistentHash.php" role="php" />
       <file name="Inflector.php" role="php" />
       <file name="Numerizer.php" role="php" />
+      <file name="Stack.php" role="php" />
       <file name="Stub.php" role="php" />
       <file name="Timer.php" role="php" />
       <file name="Uuid.php" role="php" />
@@ -75,6 +77,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
    <install name="lib/Horde/Support/Numerizer/Locale/Base.php" as="Horde/Support/Numerizer/Locale/Base.php" />
    <install name="lib/Horde/Support/Numerizer/Locale/De.php" as="Horde/Support/Numerizer/Locale/De.php" />
    <install name="lib/Horde/Support/Numerizer.php" as="Horde/Support/Numerizer.php" />
+   <install name="lib/Horde/Support/Stack.php" as="Horde/Support/Stack.php" />
    <install name="lib/Horde/Support/Stub.php" as="Horde/Support/Stub.php" />
    <install name="lib/Horde/Support/Timer.php" as="Horde/Support/Timer.php" />
    <install name="lib/Horde/Support/Uuid.php" as="Horde/Support/Uuid.php" />