<?php
/**
 * Implementation of a class a bidirectional infinite iterator over the simple
 * array
 *
 * @package Library
 * @author Miroslav Kubelik (koubel@volny.cz)
 * @copyright Copyright (c) 2007-2009 Miroslav Kubelik
 * @license http://opensource.org/licenses/gpl-license.php GNU GPL
 */
/**
 * Bidirectional infinite iterator over the simple array
 *
 * It rewinds to the begin if the end is reached with direct iteration via {@link next()}.
 * It rewinds to the end if the begin is reached with backward iteration via {@link previouos()}.
 *
 * @package Library
 * @author Miroslav Kubelik (koubel@volny.cz)
 * @copyright Copyright (c) 2007-2009 Miroslav Kubelik
 * @license http://opensource.org/licenses/gpl-license.php GNU GPL
 */
class BidirInfSimpleArrIterator extends BidirSimpleArrIterator {

    /**
     * Moves to previous element in loop.
     * If begin is reached, rewind to the end.
     */
    public function previous() {
        parent::previous();
        if (!$this->valid()) {
            $this->seekToEnd();
        }
    }

    /**
     * Moves to next element in loop.
     * If end is reached, rewind to the begin.
     */
    public function next() {
        parent::next();
        if (!$this->valid()) {
            $this->rewind();
        }
    }
}
