| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- <?php
- /**
- * @category Thinkopen
- * @package Mooses_Mongodb_Mongo
- * @copyright Thinkopen s.r.l.
- * @license New BSD License
- * @author Coen Hyde
- */
- class Mooses_Mongodb_Mongo_Iterator_Default implements SeekableIterator, RecursiveIterator, Countable
- {
- protected $_document = null;
- protected $_position = null;
- protected $_properties = array();
- protected $_init = false;
- protected $_counter = 0;
-
- public function __construct(Mooses_Mongodb_Mongo_Document $document)
- {
- $this->_document = $document;
- $this->_properties = $document->getPropertyKeys();
- $this->_position = current($this->_properties);
-
- reset($this->_properties);
- }
-
- /**
- * Get the document
- *
- * @return Mooses_Mongodb_Mongo_Document
- */
- public function getDocument()
- {
- return $this->_document;
- }
-
- /**
- * Get the properties
- *
- * @return array
- */
- public function getDocumentProperties()
- {
- return $this->_properties;
- }
-
- /**
- * Seek to a position
- *
- * @param unknown_type $position
- */
- public function seek($position)
- {
- $this->_position = $position;
-
- if (!$this->valid()) {
- throw new OutOfBoundsException("invalid seek position ($position)");
- }
- }
-
- /**
- * Get the current value
- *
- * @return mixed
- */
- public function current()
- {
- return $this->getDocument()->getProperty($this->key());
- }
-
- /**
- * Get the current key
- *
- * @return string
- */
- public function key()
- {
- return $this->_position;
- }
-
- /**
- * Move next
- */
- public function next()
- {
- next($this->_properties);
- $this->_position = current($this->_properties);
- $this->_counter = $this->_counter + 1;
- }
-
- /**
- * Rewind the iterator
- */
- public function rewind()
- {
- reset($this->_properties);
- $this->_position = current($this->_properties);
- }
-
- /**
- * Is the current position valid
- *
- * @return boolean
- */
- public function valid()
- {
- return in_array($this->key(), $this->_properties, true);
- }
- /**
- * Count all properties
- *
- * @return int
- */
- public function count()
- {
- return count($this->getDocumentProperties());
- }
-
- /**
- * Determine if the current node has an children
- *
- * @return boolean
- */
- public function hasChildren()
- {
- return ($this->current() instanceof Mooses_Mongodb_Mongo_Document);
- }
-
- /*
- * Get children
- *
- * @return RecursiveIterator
- */
- public function getChildren()
- {
- return $this->current()->getIterator();
- }
- }
|