1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheet\Style; |
4
|
|
|
|
5
|
|
|
use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; |
6
|
|
|
|
7
|
|
|
class Protection extends Supervisor |
8
|
|
|
{ |
9
|
|
|
/** Protection styles */ |
10
|
|
|
const PROTECTION_INHERIT = 'inherit'; |
11
|
|
|
const PROTECTION_PROTECTED = 'protected'; |
12
|
|
|
const PROTECTION_UNPROTECTED = 'unprotected'; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Locked. |
16
|
|
|
* |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
protected $locked; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Hidden. |
23
|
|
|
* |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
protected $hidden; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Create a new Protection. |
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
|
|
|
* @param bool $isConditional Flag indicating if this is a conditional style or not |
35
|
|
|
* Leave this value at default unless you understand exactly what |
36
|
|
|
* its ramifications are |
37
|
|
|
*/ |
38
|
172 |
|
public function __construct($isSupervisor = false, $isConditional = false) |
39
|
|
|
{ |
40
|
|
|
// Supervisor? |
41
|
172 |
|
parent::__construct($isSupervisor); |
42
|
|
|
|
43
|
|
|
// Initialise values |
44
|
172 |
|
if (!$isConditional) { |
45
|
172 |
|
$this->locked = self::PROTECTION_INHERIT; |
46
|
172 |
|
$this->hidden = self::PROTECTION_INHERIT; |
47
|
|
|
} |
48
|
172 |
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Get the shared style component for the currently active cell in currently active sheet. |
52
|
|
|
* Only used for style supervisor. |
53
|
|
|
* |
54
|
|
|
* @return Protection |
55
|
|
|
*/ |
56
|
|
|
public function getSharedComponent() |
57
|
|
|
{ |
58
|
|
|
return $this->parent->getSharedComponent()->getProtection(); |
|
|
|
|
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Build style array from subcomponents. |
63
|
|
|
* |
64
|
|
|
* @param array $array |
65
|
|
|
* |
66
|
|
|
* @return array |
67
|
|
|
*/ |
68
|
13 |
|
public function getStyleArray($array) |
69
|
|
|
{ |
70
|
13 |
|
return ['protection' => $array]; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Apply styles from array. |
75
|
|
|
* |
76
|
|
|
* <code> |
77
|
|
|
* $spreadsheet->getActiveSheet()->getStyle('B2')->getLocked()->applyFromArray( |
78
|
|
|
* [ |
79
|
|
|
* 'locked' => TRUE, |
80
|
|
|
* 'hidden' => FALSE |
81
|
|
|
* ] |
82
|
|
|
* ); |
83
|
|
|
* </code> |
84
|
|
|
* |
85
|
|
|
* @param array $pStyles Array containing style information |
86
|
|
|
* |
87
|
|
|
* @throws PhpSpreadsheetException |
88
|
|
|
* |
89
|
|
|
* @return Protection |
90
|
|
|
*/ |
91
|
13 |
|
public function applyFromArray(array $pStyles) |
92
|
|
|
{ |
93
|
13 |
|
if ($this->isSupervisor) { |
94
|
|
|
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles)); |
95
|
|
|
} else { |
96
|
13 |
|
if (isset($pStyles['locked'])) { |
97
|
13 |
|
$this->setLocked($pStyles['locked']); |
98
|
|
|
} |
99
|
13 |
|
if (isset($pStyles['hidden'])) { |
100
|
|
|
$this->setHidden($pStyles['hidden']); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
104
|
13 |
|
return $this; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Get locked. |
109
|
|
|
* |
110
|
|
|
* @return string |
111
|
|
|
*/ |
112
|
79 |
|
public function getLocked() |
113
|
|
|
{ |
114
|
79 |
|
if ($this->isSupervisor) { |
115
|
|
|
return $this->getSharedComponent()->getLocked(); |
116
|
|
|
} |
117
|
|
|
|
118
|
79 |
|
return $this->locked; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Set locked. |
123
|
|
|
* |
124
|
|
|
* @param string $pValue see self::PROTECTION_* |
125
|
|
|
* |
126
|
|
|
* @return Protection |
127
|
|
|
*/ |
128
|
33 |
|
public function setLocked($pValue) |
129
|
|
|
{ |
130
|
33 |
|
if ($this->isSupervisor) { |
131
|
13 |
|
$styleArray = $this->getStyleArray(['locked' => $pValue]); |
132
|
13 |
|
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); |
133
|
|
|
} else { |
134
|
33 |
|
$this->locked = $pValue; |
135
|
|
|
} |
136
|
|
|
|
137
|
33 |
|
return $this; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Get hidden. |
142
|
|
|
* |
143
|
|
|
* @return string |
144
|
|
|
*/ |
145
|
79 |
|
public function getHidden() |
146
|
|
|
{ |
147
|
79 |
|
if ($this->isSupervisor) { |
148
|
|
|
return $this->getSharedComponent()->getHidden(); |
149
|
|
|
} |
150
|
|
|
|
151
|
79 |
|
return $this->hidden; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Set hidden. |
156
|
|
|
* |
157
|
|
|
* @param string $pValue see self::PROTECTION_* |
158
|
|
|
* |
159
|
|
|
* @return Protection |
160
|
|
|
*/ |
161
|
21 |
|
public function setHidden($pValue) |
162
|
|
|
{ |
163
|
21 |
|
if ($this->isSupervisor) { |
164
|
|
|
$styleArray = $this->getStyleArray(['hidden' => $pValue]); |
165
|
|
|
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); |
166
|
|
|
} else { |
167
|
21 |
|
$this->hidden = $pValue; |
168
|
|
|
} |
169
|
|
|
|
170
|
21 |
|
return $this; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* Get hash code. |
175
|
|
|
* |
176
|
|
|
* @return string Hash code |
177
|
|
|
*/ |
178
|
95 |
|
public function getHashCode() |
179
|
|
|
{ |
180
|
95 |
|
if ($this->isSupervisor) { |
181
|
|
|
return $this->getSharedComponent()->getHashCode(); |
182
|
|
|
} |
183
|
|
|
|
184
|
95 |
|
return md5( |
185
|
95 |
|
$this->locked . |
186
|
95 |
|
$this->hidden . |
187
|
95 |
|
__CLASS__ |
188
|
|
|
); |
189
|
|
|
} |
190
|
|
|
} |
191
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.