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\Style;
4
 
5
use PhpOffice\PhpSpreadsheet\IComparable;
6
use PhpOffice\PhpSpreadsheet\Spreadsheet;
7
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
8
 
9
abstract class Supervisor implements IComparable
10
{
11
    /**
12
     * Supervisor?
13
     */
14
    protected bool $isSupervisor;
15
 
16
    /**
17
     * Parent. Only used for supervisor.
18
     *
19
     * @var Spreadsheet|Supervisor
20
     */
21
    protected $parent;
22
 
23
    /**
24
     * Parent property name.
25
     */
26
    protected ?string $parentPropertyName = null;
27
 
28
    /**
29
     * Create a new Supervisor.
30
     *
31
     * @param bool $isSupervisor Flag indicating if this is a supervisor or not
32
     *                                    Leave this value at default unless you understand exactly what
33
     *                                        its ramifications are
34
     */
35
    public function __construct(bool $isSupervisor = false)
36
    {
37
        // Supervisor?
38
        $this->isSupervisor = $isSupervisor;
39
    }
40
 
41
    /**
42
     * Bind parent. Only used for supervisor.
43
     *
44
     * @return $this
45
     */
46
    public function bindParent(Spreadsheet|self $parent, ?string $parentPropertyName = null)
47
    {
48
        $this->parent = $parent;
49
        $this->parentPropertyName = $parentPropertyName;
50
 
51
        return $this;
52
    }
53
 
54
    /**
55
     * Is this a supervisor or a cell style component?
56
     */
57
    public function getIsSupervisor(): bool
58
    {
59
        return $this->isSupervisor;
60
    }
61
 
62
    /**
63
     * Get the currently active sheet. Only used for supervisor.
64
     */
65
    public function getActiveSheet(): Worksheet
66
    {
67
        return $this->parent->getActiveSheet();
68
    }
69
 
70
    /**
71
     * Get the currently active cell coordinate in currently active sheet.
72
     * Only used for supervisor.
73
     *
74
     * @return string E.g. 'A1'
75
     */
76
    public function getSelectedCells(): string
77
    {
78
        return $this->getActiveSheet()->getSelectedCells();
79
    }
80
 
81
    /**
82
     * Get the currently active cell coordinate in currently active sheet.
83
     * Only used for supervisor.
84
     *
85
     * @return string E.g. 'A1'
86
     */
87
    public function getActiveCell(): string
88
    {
89
        return $this->getActiveSheet()->getActiveCell();
90
    }
91
 
92
    /**
93
     * Implement PHP __clone to create a deep clone, not just a shallow copy.
94
     */
95
    public function __clone()
96
    {
97
        $vars = get_object_vars($this);
98
        foreach ($vars as $key => $value) {
99
            if ((is_object($value)) && ($key != 'parent')) {
100
                $this->$key = clone $value;
101
            } else {
102
                $this->$key = $value;
103
            }
104
        }
105
    }
106
 
107
    /**
108
     * Export style as array.
109
     *
110
     * Available to anything which extends this class:
111
     * Alignment, Border, Borders, Color, Fill, Font,
112
     * NumberFormat, Protection, and Style.
113
     */
114
    final public function exportArray(): array
115
    {
116
        return $this->exportArray1();
117
    }
118
 
119
    /**
120
     * Abstract method to be implemented in anything which
121
     * extends this class.
122
     *
123
     * This method invokes exportArray2 with the names and values
124
     * of all properties to be included in output array,
125
     * returning that array to exportArray, then to caller.
126
     */
127
    abstract protected function exportArray1(): array;
128
 
129
    /**
130
     * Populate array from exportArray1.
131
     * This method is available to anything which extends this class.
132
     * The parameter index is the key to be added to the array.
133
     * The parameter objOrValue is either a primitive type,
134
     * which is the value added to the array,
135
     * or a Style object to be recursively added via exportArray.
136
     */
137
    final protected function exportArray2(array &$exportedArray, string $index, mixed $objOrValue): void
138
    {
139
        if ($objOrValue instanceof self) {
140
            $exportedArray[$index] = $objOrValue->exportArray();
141
        } else {
142
            $exportedArray[$index] = $objOrValue;
143
        }
144
    }
145
 
146
    /**
147
     * Get the shared style component for the currently active cell in currently active sheet.
148
     * Only used for style supervisor.
149
     */
150
    abstract public function getSharedComponent(): mixed;
151
 
152
    /**
153
     * Build style array from subcomponents.
154
     */
155
    abstract public function getStyleArray(array $array): array;
156
}