Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 1
<?php
2
 
3
namespace PhpOffice\PhpSpreadsheet\Worksheet;
4
 
5
use PhpOffice\PhpSpreadsheet\Spreadsheet;
6
 
7
/**
8
 * @implements \Iterator<int, Worksheet>
9
 */
10
class Iterator implements \Iterator
11
{
12
    /**
13
     * Spreadsheet to iterate.
14
     */
15
    private Spreadsheet $subject;
16
 
17
    /**
18
     * Current iterator position.
19
     */
20
    private int $position = 0;
21
 
22
    /**
23
     * Create a new worksheet iterator.
24
     */
25
    public function __construct(Spreadsheet $subject)
26
    {
27
        // Set subject
28
        $this->subject = $subject;
29
    }
30
 
31
    /**
32
     * Rewind iterator.
33
     */
34
    public function rewind(): void
35
    {
36
        $this->position = 0;
37
    }
38
 
39
    /**
40
     * Current Worksheet.
41
     */
42
    public function current(): Worksheet
43
    {
44
        return $this->subject->getSheet($this->position);
45
    }
46
 
47
    /**
48
     * Current key.
49
     */
50
    public function key(): int
51
    {
52
        return $this->position;
53
    }
54
 
55
    /**
56
     * Next value.
57
     */
58
    public function next(): void
59
    {
60
        ++$this->position;
61
    }
62
 
63
    /**
64
     * Are there more Worksheet instances available?
65
     */
66
    public function valid(): bool
67
    {
68
        return $this->position < $this->subject->getSheetCount() && $this->position >= 0;
69
    }
70
}