class Horde_Rdo_List implements Iterator, Countable
{
/**
+ * Rdo Query
+ * @var mixed
+ */
+ protected $_query;
+
+ /**
* Rdo Mapper
* @var Horde_Rdo_Mapper
*/
list($this->_sql, $this->_bindParams) = $query;
}
- // Keep a handle on the Mapper object for running the query.
- $this->_mapper = $mapper;
+ if (!$mapper) {
+ throw new Horde_Rdo_Exception('Mapper must be provided either explicitly or in a Query object');
+ }
- $this->_count = $this->_mapper->count($query);
+ $this->_query = $query;
+ $this->_mapper = $mapper;
}
/**
return !$this->_eof;
}
+ /**
+ * Implementation of count() for Countable
+ *
+ * @return integer Number of elements in the list
+ */
public function count()
{
+ if (is_null($this->_count)) {
+ $this->_count = $this->_mapper->count($this->_query);
+ }
return $this->_count;
}