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 Iterator as NativeIterator;
6
use PhpOffice\PhpSpreadsheet\Cell\Cell;
7
use PhpOffice\PhpSpreadsheet\Collection\Cells;
8
 
9
/**
10
 * @template TKey
11
 *
12
 * @implements NativeIterator<TKey, Cell>
13
 */
14
abstract class CellIterator implements NativeIterator
15
{
16
    public const TREAT_NULL_VALUE_AS_EMPTY_CELL = 1;
17
 
18
    public const TREAT_EMPTY_STRING_AS_EMPTY_CELL = 2;
19
 
20
    public const IF_NOT_EXISTS_RETURN_NULL = false;
21
 
22
    public const IF_NOT_EXISTS_CREATE_NEW = true;
23
 
24
    /**
25
     * Worksheet to iterate.
26
     */
27
    protected Worksheet $worksheet;
28
 
29
    /**
30
     * Cell Collection to iterate.
31
     */
32
    protected Cells $cellCollection;
33
 
34
    /**
35
     * Iterate only existing cells.
36
     */
37
    protected bool $onlyExistingCells = false;
38
 
39
    /**
40
     * If iterating all cells, and a cell doesn't exist, identifies whether a new cell should be created,
41
     *    or if the iterator should return a null value.
42
     */
43
    protected bool $ifNotExists = self::IF_NOT_EXISTS_CREATE_NEW;
44
 
45
    /**
46
     * Destructor.
47
     */
48
    public function __destruct()
49
    {
50
        unset($this->worksheet, $this->cellCollection);
51
    }
52
 
53
    public function getIfNotExists(): bool
54
    {
55
        return $this->ifNotExists;
56
    }
57
 
58
    public function setIfNotExists(bool $ifNotExists = self::IF_NOT_EXISTS_CREATE_NEW): void
59
    {
60
        $this->ifNotExists = $ifNotExists;
61
    }
62
 
63
    /**
64
     * Get loop only existing cells.
65
     */
66
    public function getIterateOnlyExistingCells(): bool
67
    {
68
        return $this->onlyExistingCells;
69
    }
70
 
71
    /**
72
     * Validate start/end values for 'IterateOnlyExistingCells' mode, and adjust if necessary.
73
     */
74
    abstract protected function adjustForExistingOnlyRange(): void;
75
 
76
    /**
77
     * Set the iterator to loop only existing cells.
78
     */
79
    public function setIterateOnlyExistingCells(bool $value): void
80
    {
81
        $this->onlyExistingCells = (bool) $value;
82
 
83
        $this->adjustForExistingOnlyRange();
84
    }
85
}