2009-01-14 00:56:43 +03:00
|
|
|
<?php
|
2009-02-17 13:54:18 +03:00
|
|
|
/*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* This software consists of voluntary contributions made by many individuals
|
2012-05-26 16:37:00 +04:00
|
|
|
* and is licensed under the MIT license. For more information, see
|
2009-02-17 13:54:18 +03:00
|
|
|
* <http://www.doctrine-project.org>.
|
|
|
|
*/
|
2009-01-22 22:38:10 +03:00
|
|
|
|
|
|
|
namespace Doctrine\ORM\Internal\Hydration;
|
|
|
|
|
2009-01-14 00:56:43 +03:00
|
|
|
/**
|
|
|
|
* Represents a result structure that can be iterated over, hydrating row-by-row
|
|
|
|
* during the iteration. An IterableResult is obtained by AbstractHydrator#iterate().
|
|
|
|
*
|
|
|
|
* @author robo
|
|
|
|
* @since 2.0
|
|
|
|
*/
|
2009-11-20 18:10:45 +03:00
|
|
|
class IterableResult implements \Iterator
|
2009-01-14 00:56:43 +03:00
|
|
|
{
|
2009-11-20 18:10:45 +03:00
|
|
|
/**
|
2011-12-12 00:52:29 +04:00
|
|
|
* @var \Doctrine\ORM\Internal\Hydration\AbstractHydrator
|
2009-11-20 18:10:45 +03:00
|
|
|
*/
|
2009-01-14 00:56:43 +03:00
|
|
|
private $_hydrator;
|
|
|
|
|
2009-11-20 18:10:45 +03:00
|
|
|
/**
|
2010-03-29 17:20:41 +04:00
|
|
|
* @var boolean
|
2009-11-20 18:10:45 +03:00
|
|
|
*/
|
|
|
|
private $_rewinded = false;
|
|
|
|
|
|
|
|
/**
|
2010-03-29 17:20:41 +04:00
|
|
|
* @var integer
|
2009-11-20 18:10:45 +03:00
|
|
|
*/
|
|
|
|
private $_key = -1;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var object
|
|
|
|
*/
|
|
|
|
private $_current = null;
|
|
|
|
|
|
|
|
/**
|
2011-12-12 00:52:29 +04:00
|
|
|
* @param \Doctrine\ORM\Internal\Hydration\AbstractHydrator $hydrator
|
2009-11-20 18:10:45 +03:00
|
|
|
*/
|
2009-01-14 00:56:43 +03:00
|
|
|
public function __construct($hydrator)
|
|
|
|
{
|
|
|
|
$this->_hydrator = $hydrator;
|
|
|
|
}
|
|
|
|
|
2009-11-20 18:10:45 +03:00
|
|
|
public function rewind()
|
|
|
|
{
|
2010-03-29 17:20:41 +04:00
|
|
|
if ($this->_rewinded == true) {
|
2009-11-20 18:10:45 +03:00
|
|
|
throw new HydrationException("Can only iterate a Result once.");
|
|
|
|
} else {
|
|
|
|
$this->_current = $this->next();
|
|
|
|
$this->_rewinded = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-14 00:56:43 +03:00
|
|
|
/**
|
|
|
|
* Gets the next set of results.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function next()
|
|
|
|
{
|
2009-11-20 18:10:45 +03:00
|
|
|
$this->_current = $this->_hydrator->hydrateRow();
|
|
|
|
$this->_key++;
|
|
|
|
return $this->_current;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function current()
|
|
|
|
{
|
|
|
|
return $this->_current;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function key()
|
|
|
|
{
|
|
|
|
return $this->_key;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function valid()
|
|
|
|
{
|
|
|
|
return ($this->_current!=false);
|
2009-01-14 00:56:43 +03:00
|
|
|
}
|
2012-05-26 16:37:00 +04:00
|
|
|
}
|