| 1 |
<?php |
| 2 |
|
| 3 |
namespace Box\Spout\Writer\XLSX\Helper; |
| 4 |
|
| 5 |
use Box\Spout\Writer\Style\Border; |
| 6 |
use Box\Spout\Writer\Style\BorderPart; |
| 7 |
|
| 8 |
class BorderHelper |
| 9 |
{ |
| 10 |
public static $xlsxStyleMap = [ |
| 11 |
Border::STYLE_SOLID => [ |
| 12 |
Border::WIDTH_THIN => 'thin', |
| 13 |
Border::WIDTH_MEDIUM => 'medium', |
| 14 |
Border::WIDTH_THICK => 'thick' |
| 15 |
], |
| 16 |
Border::STYLE_DOTTED => [ |
| 17 |
Border::WIDTH_THIN => 'dotted', |
| 18 |
Border::WIDTH_MEDIUM => 'dotted', |
| 19 |
Border::WIDTH_THICK => 'dotted', |
| 20 |
], |
| 21 |
Border::STYLE_DASHED => [ |
| 22 |
Border::WIDTH_THIN => 'dashed', |
| 23 |
Border::WIDTH_MEDIUM => 'mediumDashed', |
| 24 |
Border::WIDTH_THICK => 'mediumDashed', |
| 25 |
], |
| 26 |
Border::STYLE_DOUBLE => [ |
| 27 |
Border::WIDTH_THIN => 'double', |
| 28 |
Border::WIDTH_MEDIUM => 'double', |
| 29 |
Border::WIDTH_THICK => 'double', |
| 30 |
], |
| 31 |
Border::STYLE_NONE => [ |
| 32 |
Border::WIDTH_THIN => 'none', |
| 33 |
Border::WIDTH_MEDIUM => 'none', |
| 34 |
Border::WIDTH_THICK => 'none', |
| 35 |
], |
| 36 |
]; |
| 37 |
|
| 38 |
/** |
| 39 |
* @param BorderPart $borderPart |
| 40 |
* @return string |
| 41 |
*/ |
| 42 |
public static function serializeBorderPart(BorderPart $borderPart) |
| 43 |
{ |
| 44 |
$borderStyle = self::getBorderStyle($borderPart); |
| 45 |
|
| 46 |
$colorEl = $borderPart->getColor() ? sprintf('<color rgb="%s"/>', $borderPart->getColor()) : ''; |
| 47 |
$partEl = sprintf( |
| 48 |
'<%s style="%s">%s</%s>', |
| 49 |
$borderPart->getName(), |
| 50 |
$borderStyle, |
| 51 |
$colorEl, |
| 52 |
$borderPart->getName() |
| 53 |
); |
| 54 |
|
| 55 |
return $partEl . PHP_EOL; |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Get the style definition from the style map |
| 60 |
* |
| 61 |
* @param BorderPart $borderPart |
| 62 |
* @return string |
| 63 |
*/ |
| 64 |
protected static function getBorderStyle(BorderPart $borderPart) |
| 65 |
{ |
| 66 |
return self::$xlsxStyleMap[$borderPart->getStyle()][$borderPart->getWidth()]; |
| 67 |
} |
| 68 |
} |
| 69 |
|