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