* $q = $session->createFindQuery( 'Person' ); * $q->where( $q->expr->gt( 'age', $q->bindValue( 15 ) ) ) * ->orderBy( 'name' ) * ->limit( 10 ); * $objects = $session->findIterator( $q, 'Person' ); * * foreach ( $objects as $object ) * { * if ( ... ) * { * $objects->flush(); * break; * } * } * * * @version 1.6alpha1 * @package PersistentObject */ class ezcPersistentIdentityFindIterator extends ezcPersistentFindIterator { /** * Identity map. * * @var ezcPersistentIdentityMap */ protected $idMap; /** * Identity session options * * @var ezcPersistentIdentitySessionOptions */ protected $options; /** * Initializes the iterator with the statement $stmt and the definition $def.. * * The statement $stmt must be executed but not used to retrieve any results yet. * The iterator will return objects with they persistent object type provided by * $def. * * The $idMap will be used to retrieve existing identities and to store new * ones, if discovered. * * @param PDOStatement $stmt * @param ezcPersistentObjectDefinition $def * @oaram ezcPersistentIdentityMap $idMap */ public function __construct( PDOStatement $stmt, ezcPersistentObjectDefinition $def, ezcPersistentIdentityMap $idMap, ezcPersistentIdentitySessionOptions $options ) { parent::__construct( $stmt, $def ); $this->idMap = $idMap; $this->options = $options; } /** * Returns the next persistent object in the result set. * * The next object is set to the current object of the iterator. * Returns null and sets the current object to null if there * are no more results in the result set. * * @return object */ public function next() { $object = parent::next(); if ( $object !== null ) { $identity = null; if ( !$this->options->refetch ) { $class = get_class( $object ); $state = $object->getState(); $identity = $this->idMap->getIdentity( $class, $state[$this->def->idProperty->propertyName] ); } if ( $identity !== null ) { $this->object = $identity; } else { $this->idMap->setIdentity( $object ); } } return $this->object; } } ?>