summaryrefslogtreecommitdiff
path: root/framework/collections/CStackIterator.php
diff options
context:
space:
mode:
Diffstat (limited to 'framework/collections/CStackIterator.php')
-rw-r--r--framework/collections/CStackIterator.php94
1 files changed, 94 insertions, 0 deletions
diff --git a/framework/collections/CStackIterator.php b/framework/collections/CStackIterator.php
new file mode 100644
index 0000000..cefa933
--- /dev/null
+++ b/framework/collections/CStackIterator.php
@@ -0,0 +1,94 @@
+<?php
+/**
+ * CStackIterator class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.yiiframework.com/
+ * @copyright Copyright &copy; 2008-2011 Yii Software LLC
+ * @license http://www.yiiframework.com/license/
+ */
+
+/**
+ * CStackIterator implements an interator for {@link CStack}.
+ *
+ * It allows CStack to return a new iterator for traversing the items in the stack.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id: CStackIterator.php 2799 2011-01-01 19:31:13Z qiang.xue $
+ * @package system.collections
+ * @since 1.0
+ */
+class CStackIterator implements Iterator
+{
+ /**
+ * @var array the data to be iterated through
+ */
+ private $_d;
+ /**
+ * @var integer index of the current item
+ */
+ private $_i;
+ /**
+ * @var integer count of the data items
+ */
+ private $_c;
+
+ /**
+ * Constructor.
+ * @param array $data the data to be iterated through
+ */
+ public function __construct(&$data)
+ {
+ $this->_d=&$data;
+ $this->_i=0;
+ $this->_c=count($this->_d);
+ }
+
+ /**
+ * Rewinds internal array pointer.
+ * This method is required by the interface Iterator.
+ */
+ public function rewind()
+ {
+ $this->_i=0;
+ }
+
+ /**
+ * Returns the key of the current array item.
+ * This method is required by the interface Iterator.
+ * @return integer the key of the current array item
+ */
+ public function key()
+ {
+ return $this->_i;
+ }
+
+ /**
+ * Returns the current array item.
+ * This method is required by the interface Iterator.
+ * @return mixed the current array item
+ */
+ public function current()
+ {
+ return $this->_d[$this->_i];
+ }
+
+ /**
+ * Moves the internal pointer to the next array item.
+ * This method is required by the interface Iterator.
+ */
+ public function next()
+ {
+ $this->_i++;
+ }
+
+ /**
+ * Returns whether there is an item at current position.
+ * This method is required by the interface Iterator.
+ * @return boolean
+ */
+ public function valid()
+ {
+ return $this->_i<$this->_c;
+ }
+}