1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Box\Spout\Writer\Common\Entity\Style; |
4
|
|
|
|
5
|
|
|
use Box\Spout\Writer\Exception\Border\InvalidNameException; |
6
|
|
|
use Box\Spout\Writer\Exception\Border\InvalidStyleException; |
7
|
|
|
use Box\Spout\Writer\Exception\Border\InvalidWidthException; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class BorderPart |
11
|
|
|
* |
12
|
|
|
* @package \Box\Spout\Writer\Common\Entity\Style |
13
|
|
|
*/ |
14
|
|
|
class BorderPart |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var string The style of this border part. |
18
|
|
|
*/ |
19
|
|
|
protected $style; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var string The name of this border part. |
23
|
|
|
*/ |
24
|
|
|
protected $name; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string The color of this border part. |
28
|
|
|
*/ |
29
|
|
|
protected $color; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string The width of this border part. |
33
|
|
|
*/ |
34
|
|
|
protected $width; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var array Allowed style constants for parts. |
38
|
|
|
*/ |
39
|
|
|
protected static $allowedStyles = [ |
40
|
|
|
'none', |
41
|
|
|
'solid', |
42
|
|
|
'dashed', |
43
|
|
|
'dotted', |
44
|
|
|
'double' |
45
|
|
|
]; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var array Allowed names constants for border parts. |
49
|
|
|
*/ |
50
|
|
|
protected static $allowedNames = [ |
51
|
|
|
'left', |
52
|
|
|
'right', |
53
|
|
|
'top', |
54
|
|
|
'bottom', |
55
|
|
|
]; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var array Allowed width constants for border parts. |
59
|
|
|
*/ |
60
|
|
|
protected static $allowedWidths = [ |
61
|
|
|
'thin', |
62
|
|
|
'medium', |
63
|
|
|
'thick', |
64
|
|
|
]; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param string $name @see BorderPart::$allowedNames |
68
|
|
|
* @param string $color A RGB color code |
69
|
|
|
* @param string $width @see BorderPart::$allowedWidths |
70
|
|
|
* @param string $style @see BorderPart::$allowedStyles |
71
|
|
|
* @throws InvalidNameException |
72
|
|
|
* @throws InvalidStyleException |
73
|
|
|
* @throws InvalidWidthException |
74
|
|
|
*/ |
75
|
16 |
|
public function __construct($name, $color = Color::BLACK, $width = Border::WIDTH_MEDIUM, $style = Border::STYLE_SOLID) |
76
|
|
|
{ |
77
|
16 |
|
$this->setName($name); |
78
|
15 |
|
$this->setColor($color); |
79
|
15 |
|
$this->setWidth($width); |
80
|
14 |
|
$this->setStyle($style); |
81
|
13 |
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return string |
85
|
|
|
*/ |
86
|
13 |
|
public function getName() |
87
|
|
|
{ |
88
|
13 |
|
return $this->name; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param string $name The name of the border part @see BorderPart::$allowedNames |
93
|
|
|
* @throws InvalidNameException |
94
|
|
|
* @return void |
95
|
|
|
*/ |
96
|
16 |
|
public function setName($name) |
97
|
|
|
{ |
98
|
16 |
|
if (!in_array($name, self::$allowedNames)) { |
99
|
1 |
|
throw new InvalidNameException($name); |
100
|
|
|
} |
101
|
15 |
|
$this->name = $name; |
102
|
15 |
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @return string |
106
|
|
|
*/ |
107
|
6 |
|
public function getStyle() |
108
|
|
|
{ |
109
|
6 |
|
return $this->style; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @param string $style The style of the border part @see BorderPart::$allowedStyles |
114
|
|
|
* @throws InvalidStyleException |
115
|
|
|
* @return void |
116
|
|
|
*/ |
117
|
14 |
|
public function setStyle($style) |
118
|
|
|
{ |
119
|
14 |
|
if (!in_array($style, self::$allowedStyles)) { |
120
|
1 |
|
throw new InvalidStyleException($style); |
121
|
|
|
} |
122
|
13 |
|
$this->style = $style; |
123
|
13 |
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @return string |
127
|
|
|
*/ |
128
|
6 |
|
public function getColor() |
129
|
|
|
{ |
130
|
6 |
|
return $this->color; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @param string $color The color of the border part @see Color::rgb() |
135
|
|
|
* @return void |
136
|
|
|
*/ |
137
|
15 |
|
public function setColor($color) |
138
|
|
|
{ |
139
|
15 |
|
$this->color = $color; |
140
|
15 |
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @return string |
144
|
|
|
*/ |
145
|
6 |
|
public function getWidth() |
146
|
|
|
{ |
147
|
6 |
|
return $this->width; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @param string $width The width of the border part @see BorderPart::$allowedWidths |
152
|
|
|
* @throws InvalidWidthException |
153
|
|
|
* @return void |
154
|
|
|
*/ |
155
|
15 |
|
public function setWidth($width) |
156
|
|
|
{ |
157
|
15 |
|
if (!in_array($width, self::$allowedWidths)) { |
158
|
1 |
|
throw new InvalidWidthException($width); |
159
|
|
|
} |
160
|
14 |
|
$this->width = $width; |
161
|
14 |
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @return array |
165
|
|
|
*/ |
166
|
2 |
|
public static function getAllowedStyles() |
167
|
|
|
{ |
168
|
2 |
|
return self::$allowedStyles; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @return array |
173
|
|
|
*/ |
174
|
2 |
|
public static function getAllowedNames() |
175
|
|
|
{ |
176
|
2 |
|
return self::$allowedNames; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @return array |
181
|
|
|
*/ |
182
|
2 |
|
public static function getAllowedWidths() |
183
|
|
|
{ |
184
|
2 |
|
return self::$allowedWidths; |
185
|
|
|
} |
186
|
|
|
} |
187
|
|
|
|