Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
     * @var Worksheet
28
     */
29
    protected $worksheet;
30
 
31
    /**
32
     * Cell Collection to iterate.
33
     *
34
     * @var Cells
35
     */
36
    protected $cellCollection;
37
 
38
    /**
39
     * Iterate only existing cells.
40
     *
41
     * @var bool
42
     */
43
    protected $onlyExistingCells = false;
44
 
45
    /**
46
     * If iterating all cells, and a cell doesn't exist, identifies whether a new cell should be created,
47
     *    or if the iterator should return a null value.
48
     *
49
     * @var bool
50
     */
51
    protected $ifNotExists = self::IF_NOT_EXISTS_CREATE_NEW;
52
 
53
    /**
54
     * Destructor.
55
     */
56
    public function __destruct()
57
    {
58
        // @phpstan-ignore-next-line
59
        $this->worksheet = $this->cellCollection = null;
60
    }
61
 
62
    public function getIfNotExists(): bool
63
    {
64
        return $this->ifNotExists;
65
    }
66
 
67
    public function setIfNotExists(bool $ifNotExists = self::IF_NOT_EXISTS_CREATE_NEW): void
68
    {
69
        $this->ifNotExists = $ifNotExists;
70
    }
71
 
72
    /**
73
     * Get loop only existing cells.
74
     */
75
    public function getIterateOnlyExistingCells(): bool
76
    {
77
        return $this->onlyExistingCells;
78
    }
79
 
80
    /**
81
     * Validate start/end values for 'IterateOnlyExistingCells' mode, and adjust if necessary.
82
     */
83
    abstract protected function adjustForExistingOnlyRange(): void;
84
 
85
    /**
86
     * Set the iterator to loop only existing cells.
87
     */
88
    public function setIterateOnlyExistingCells(bool $value): void
89
    {
90
        $this->onlyExistingCells = (bool) $value;
91
 
92
        $this->adjustForExistingOnlyRange();
93
    }
94
}