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