mirror of
https://github.com/dg/dibi.git
synced 2025-07-30 19:00:13 +02:00
DibiResult::getIterator() - removed optional $offset and $limit parameters (BC break!)
This commit is contained in:
@@ -176,13 +176,14 @@ class DibiResult extends DibiObject implements IDataSource
|
||||
|
||||
/**
|
||||
* Required by the IteratorAggregate interface.
|
||||
* @param int offset
|
||||
* @param int limit
|
||||
* @return DibiResultIterator
|
||||
*/
|
||||
final public function getIterator($offset = NULL, $limit = NULL)
|
||||
final public function getIterator()
|
||||
{
|
||||
return new DibiResultIterator($this, $offset, $limit);
|
||||
if (func_num_args()) {
|
||||
trigger_error(__METHOD__ . ' arguments $offset & $limit have been dropped; use SQL clauses instead.', E_USER_WARNING);
|
||||
}
|
||||
return new DibiResultIterator($this);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -24,13 +24,6 @@
|
||||
* unset($result);
|
||||
* </code>
|
||||
*
|
||||
* Optionally you can specify offset and limit:
|
||||
* <code>
|
||||
* foreach ($result->getIterator(2, 3) as $row) {
|
||||
* print_r($row);
|
||||
* }
|
||||
* </code>
|
||||
*
|
||||
* @copyright Copyright (c) 2005, 2010 David Grudl
|
||||
* @package dibi
|
||||
*/
|
||||
@@ -39,12 +32,6 @@ class DibiResultIterator implements Iterator, Countable
|
||||
/** @var DibiResult */
|
||||
private $result;
|
||||
|
||||
/** @var int */
|
||||
private $offset;
|
||||
|
||||
/** @var int */
|
||||
private $limit;
|
||||
|
||||
/** @var int */
|
||||
private $row;
|
||||
|
||||
@@ -54,14 +41,10 @@ class DibiResultIterator implements Iterator, Countable
|
||||
|
||||
/**
|
||||
* @param DibiResult
|
||||
* @param int offset
|
||||
* @param int limit
|
||||
*/
|
||||
public function __construct(DibiResult $result, $offset = NULL, $limit = NULL)
|
||||
public function __construct(DibiResult $result)
|
||||
{
|
||||
$this->result = $result;
|
||||
$this->offset = (int) $offset;
|
||||
$this->limit = $limit === NULL ? -1 : (int) $limit;
|
||||
}
|
||||
|
||||
|
||||
@@ -73,7 +56,7 @@ class DibiResultIterator implements Iterator, Countable
|
||||
public function rewind()
|
||||
{
|
||||
$this->pointer = 0;
|
||||
$this->result->seek($this->offset);
|
||||
$this->result->seek(0);
|
||||
$this->row = $this->result->fetch();
|
||||
}
|
||||
|
||||
@@ -107,7 +90,6 @@ class DibiResultIterator implements Iterator, Countable
|
||||
*/
|
||||
public function next()
|
||||
{
|
||||
//$this->result->seek($this->offset + $this->pointer + 1);
|
||||
$this->row = $this->result->fetch();
|
||||
$this->pointer++;
|
||||
}
|
||||
@@ -120,7 +102,7 @@ class DibiResultIterator implements Iterator, Countable
|
||||
*/
|
||||
public function valid()
|
||||
{
|
||||
return !empty($this->row) && ($this->limit < 0 || $this->pointer < $this->limit);
|
||||
return !empty($this->row);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -64,19 +64,6 @@ foreach ($res as $n => $row) {
|
||||
}
|
||||
|
||||
|
||||
// fetch row by row with defined offset
|
||||
echo "<h2>getIterator(2)</h2>\n";
|
||||
foreach ($res->getIterator(2) as $n => $row) {
|
||||
Debug::dump($row);
|
||||
}
|
||||
|
||||
// fetch row by row with defined offset and limit
|
||||
echo "<h2>getIterator(2, 1)</h2>\n";
|
||||
foreach ($res->getIterator(2, 1) as $n => $row) {
|
||||
Debug::dump($row);
|
||||
}
|
||||
|
||||
|
||||
// more complex association array
|
||||
$res = dibi::query('
|
||||
SELECT *
|
||||
|
Reference in New Issue
Block a user