Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/*
3
 *  $Id: Iterator.php 7490 2010-03-29 19:53:27Z jwage $
4
 *
5
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
6
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
7
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
8
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
9
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
10
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
15
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16
 *
17
 * This software consists of voluntary contributions made by many individuals
18
 * and is licensed under the LGPL. For more information, see
19
 * <http://www.doctrine-project.org>.
20
 */
21
 
22
/**
23
 * Doctrine_Collection_Iterator
24
 * iterates through Doctrine_Collection
25
 *
26
 * @package     Doctrine
27
 * @subpackage  Collection
28
 * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
29
 * @link        www.doctrine-project.org
30
 * @since       1.0
31
 * @version     $Revision: 7490 $
32
 * @author      Konsta Vesterinen <kvesteri@cc.hut.fi>
33
 */
34
abstract class Doctrine_Collection_Iterator implements Iterator
35
{
36
    /**
37
     * @var Doctrine_Collection $collection
38
     */
39
    protected $collection;
40
 
41
    /**
42
     * @var array $keys
43
     */
44
    protected $keys;
45
 
46
    /**
47
     * @var mixed $key
48
     */
49
    protected $key;
50
 
51
    /**
52
     * @var integer $index
53
     */
54
    protected $index;
55
 
56
    /**
57
     * @var integer $count
58
     */
59
    protected $count;
60
 
61
    /**
62
     * constructor
63
     * @var Doctrine_Collection $collection
64
     */
65
    public function __construct($collection)
66
    {
67
        $this->collection = $collection;
68
        $this->keys       = $this->collection->getKeys();
69
        $this->count      = $this->collection->count();
70
    }
71
 
72
    /**
73
     * rewinds the iterator
74
     *
75
     * @return void
76
     */
77
    public function rewind()
78
    {
79
        $this->index = 0;
80
        $i = $this->index;
81
        if (isset($this->keys[$i])) {
82
            $this->key   = $this->keys[$i];
83
        }
84
    }
85
 
86
    /**
87
     * returns the current key
88
     *
89
     * @return integer
90
     */
91
    public function key()
92
    {
93
        return $this->key;
94
    }
95
 
96
    /**
97
     * returns the current record
98
     *
99
     * @return Doctrine_Record
100
     */
101
    public function current()
102
    {
103
        return $this->collection->get($this->key);
104
    }
105
 
106
    /**
107
     * advances the internal pointer
108
     *
109
     * @return void
110
     */
111
    public function next()
112
    {
113
        $this->index++;
114
        $i = $this->index;
115
        if (isset($this->keys[$i])) {
116
            $this->key   = $this->keys[$i];
117
        }
118
    }
119
}