1 | <?php |
||
12 | class Style implements Component |
||
13 | { |
||
14 | /** |
||
15 | * @var int |
||
16 | */ |
||
17 | private $id; |
||
18 | |||
19 | /** |
||
20 | * @var Font |
||
21 | */ |
||
22 | private $font; |
||
23 | |||
24 | /** |
||
25 | * @var Fill |
||
26 | */ |
||
27 | private $fill; |
||
28 | |||
29 | /** |
||
30 | * @var Border |
||
31 | */ |
||
32 | private $border; |
||
33 | |||
34 | /** |
||
35 | * @var bool |
||
36 | */ |
||
37 | private $isLocked = false; |
||
38 | |||
39 | /** |
||
40 | * Style constructor. |
||
41 | */ |
||
42 | 15 | public function __construct() |
|
43 | { |
||
44 | 15 | $this->font = new Font(); |
|
45 | 15 | $this->fill = new Fill(); |
|
46 | 15 | $this->border = new Border(); |
|
47 | 15 | } |
|
48 | |||
49 | /** |
||
50 | * @return int|null |
||
51 | */ |
||
52 | 11 | public function getId() |
|
53 | { |
||
54 | 11 | return $this->id; |
|
55 | } |
||
56 | |||
57 | /** |
||
58 | * @param int $id |
||
59 | * @return Style |
||
60 | */ |
||
61 | 8 | public function setId($id) |
|
62 | { |
||
63 | 8 | $this->id = $id; |
|
64 | 8 | return $this; |
|
65 | } |
||
66 | |||
67 | /** |
||
68 | * @return Font |
||
69 | */ |
||
70 | 12 | public function getFont() |
|
71 | { |
||
72 | 12 | if ($this->isLocked) { |
|
73 | 3 | return clone $this->font; |
|
74 | } |
||
75 | 12 | return $this->font; |
|
76 | } |
||
77 | |||
78 | /** |
||
79 | * @return Fill |
||
80 | */ |
||
81 | 9 | public function getFill() |
|
82 | { |
||
83 | 9 | if ($this->isLocked) { |
|
84 | 1 | return clone $this->fill; |
|
85 | } |
||
86 | 9 | return $this->fill; |
|
87 | } |
||
88 | |||
89 | /** |
||
90 | * @return Border |
||
91 | */ |
||
92 | 10 | public function getBorder() |
|
93 | { |
||
94 | 10 | if ($this->isLocked) { |
|
95 | return clone $this->border; |
||
96 | } |
||
97 | 10 | return $this->border; |
|
98 | } |
||
99 | |||
100 | /** |
||
101 | * @param string $name |
||
102 | * @return Style |
||
103 | */ |
||
104 | 2 | public function setFontName($name) |
|
105 | { |
||
106 | 2 | $this->getFont()->setName($name); |
|
107 | 2 | return $this; |
|
108 | } |
||
109 | |||
110 | /** |
||
111 | * @param string $size |
||
112 | * @return Style |
||
113 | */ |
||
114 | 2 | public function setFontSize($size) |
|
115 | { |
||
116 | 2 | $this->getFont()->setSize($size); |
|
117 | 2 | return $this; |
|
118 | } |
||
119 | |||
120 | /** |
||
121 | * @param string $color |
||
122 | * @return Style |
||
123 | */ |
||
124 | 1 | public function setFontColor($color) |
|
129 | |||
130 | /** |
||
131 | * @return Style |
||
132 | */ |
||
133 | 2 | public function setFontBold() |
|
138 | |||
139 | /** |
||
140 | * @return Style |
||
141 | */ |
||
142 | 1 | public function setFontItalic() |
|
147 | |||
148 | /** |
||
149 | * @return Style |
||
150 | */ |
||
151 | 1 | public function setFontUnderline() |
|
152 | { |
||
153 | 1 | $this->getFont()->setUnderline(); |
|
154 | 1 | return $this; |
|
155 | } |
||
156 | |||
157 | /** |
||
158 | * @return Style |
||
159 | */ |
||
160 | 1 | public function setFontStrikethrough() |
|
165 | |||
166 | /** |
||
167 | * @param string $color |
||
168 | * @return Style |
||
169 | */ |
||
170 | 2 | public function setFillColor($color) |
|
175 | |||
176 | /** |
||
177 | * @param string $pattern |
||
178 | * @return Style |
||
179 | */ |
||
180 | 9 | public function setFillPattern($pattern) |
|
185 | |||
186 | /** |
||
187 | * Convenience method to set all borders at once. |
||
188 | * |
||
189 | * @param string $style |
||
190 | * @param string $color |
||
191 | * @return Style |
||
192 | */ |
||
193 | 1 | public function setSurroundingBorder($style = BorderStyle::THIN, $color = '000000') |
|
201 | |||
202 | /** |
||
203 | * @param string $style |
||
204 | * @param string $color |
||
205 | * @return Style |
||
206 | */ |
||
207 | 1 | public function setBorderLeft($style = BorderStyle::THIN, $color = '000000') |
|
212 | |||
213 | /** |
||
214 | * @param string $style |
||
215 | * @param string $color |
||
216 | * @return Style |
||
217 | */ |
||
218 | 1 | public function setBorderRight($style = BorderStyle::THIN, $color = '000000') |
|
223 | |||
224 | /** |
||
225 | * @param string $style |
||
226 | * @param string $color |
||
227 | * @return Style |
||
228 | */ |
||
229 | 1 | public function setBorderTop($style = BorderStyle::THIN, $color = '000000') |
|
234 | |||
235 | /** |
||
236 | * @param string $style |
||
237 | * @param string $color |
||
238 | * @return Style |
||
239 | */ |
||
240 | 1 | public function setBorderBottom($style = BorderStyle::THIN, $color = '000000') |
|
245 | |||
246 | /** |
||
247 | * @param string $style |
||
248 | * @param string $color |
||
249 | * @return Style |
||
250 | */ |
||
251 | 1 | public function setBorderDiagonalUp($style = BorderStyle::THIN, $color = '000000') |
|
256 | |||
257 | /** |
||
258 | * @param string $style |
||
259 | * @param string $color |
||
260 | * @return Style |
||
261 | */ |
||
262 | 1 | public function setBorderDiagonalDown($style = BorderStyle::THIN, $color = '000000') |
|
267 | |||
268 | /** |
||
269 | * Lock current style to prevent overwriting of existing styles. |
||
270 | * |
||
271 | * @return Style |
||
272 | */ |
||
273 | 8 | public function lock() |
|
278 | |||
279 | /** |
||
280 | * Return single <xf> string for current style. |
||
281 | * |
||
282 | * @return string |
||
283 | */ |
||
284 | 8 | public function asXml() |
|
293 | } |
||
294 |