diff --git a/README.md b/README.md index 2b6d027..821c3b7 100644 --- a/README.md +++ b/README.md @@ -154,19 +154,24 @@ Adding borders to a row requires a ```Border``` object. ```php use Box\Spout\Common\Type; -use Box\Spout\Writer\WriterFactory; -use Box\Spout\Writer\Style\StyleBuilder; +use Box\Spout\Writer\Style\Border; use Box\Spout\Writer\Style\BorderBuilder; +use Box\Spout\Writer\Style\Color; +use Box\Spout\Writer\Style\StyleBuilder; +use Box\Spout\Writer\WriterFactory; $border = (new BorderBuilder()) - ->setBorderBottom(Border::STYLE_DASHED, Color::GREEN, Border::WIDTH_THIN) - ->build(); + ->setBorderBottom(Color::GREEN, Border::WIDTH_THIN, Border::STYLE_DASHED) + ->build(); $style = (new StyleBuilder()) - ->setBorder($border) - ->build(); + ->setBorder($border) + ->build(); -$writer->addRowWithStyle(['Border Bottom Dashed Green Thin'], $style); +$writer = WriterFactory::create(Type::ODS); +$writer->openToFile(__DIR__ . '/borders.xlsx'); + +$writer->addRowWithStyle(['Border Bottom Green Thin Dashed'], $style) $writer->close(); diff --git a/src/Spout/Writer/Style/BorderBuilder.php b/src/Spout/Writer/Style/BorderBuilder.php index 83d797a..c0b8aea 100644 --- a/src/Spout/Writer/Style/BorderBuilder.php +++ b/src/Spout/Writer/Style/BorderBuilder.php @@ -18,50 +18,50 @@ class BorderBuilder } /** - * @param string|void $style Border style @see BorderPart::allowedStyles * @param string|void $color Border A RGB color code * @param string|void $width Border width @see BorderPart::allowedWidths - * @return self + * @param string|void $style Border style @see BorderPart::allowedStyles + * @return BorderBuilder */ - public function setBorderTop($style = Border::STYLE_SOLID, $color = Color::BLACK, $width = Border::WIDTH_THICK) + public function setBorderTop($color = Color::BLACK, $width = Border::WIDTH_MEDIUM, $style = Border::STYLE_SOLID) { - $this->border->addPart(new BorderPart(Border::TOP, $style, $color, $width)); + $this->border->addPart(new BorderPart(Border::TOP, $color, $width, $style)); return $this; } /** - * @param string|void $style Border style @see BorderPart::allowedStyles * @param string|void $color Border A RGB color code * @param string|void $width Border width @see BorderPart::allowedWidths - * @return self + * @param string|void $style Border style @see BorderPart::allowedStyles + * @return BorderBuilder */ - public function setBorderRight($style = Border::STYLE_SOLID, $color = Color::BLACK, $width = Border::WIDTH_THICK) + public function setBorderRight($color = Color::BLACK, $width = Border::WIDTH_MEDIUM, $style = Border::STYLE_SOLID) { - $this->border->addPart(new BorderPart(Border::RIGHT, $style, $color, $width)); + $this->border->addPart(new BorderPart(Border::RIGHT, $color, $width, $style)); return $this; } /** - * @param string|void $style Border style @see BorderPart::allowedStyles * @param string|void $color Border A RGB color code * @param string|void $width Border width @see BorderPart::allowedWidths - * @return self + * @param string|void $style Border style @see BorderPart::allowedStyles + * @return BorderBuilder */ - public function setBorderBottom($style = Border::STYLE_SOLID, $color = Color::BLACK, $width = Border::WIDTH_THICK) + public function setBorderBottom($color = Color::BLACK, $width = Border::WIDTH_MEDIUM, $style = Border::STYLE_SOLID) { - $this->border->addPart(new BorderPart(Border::BOTTOM, $style, $color, $width)); + $this->border->addPart(new BorderPart(Border::BOTTOM, $color, $width, $style)); return $this; } /** - * @param string|void $style Border style @see BorderPart::allowedStyles * @param string|void $color Border A RGB color code * @param string|void $width Border width @see BorderPart::allowedWidths - * @return self + * @param string|void $style Border style @see BorderPart::allowedStyles + * @return BorderBuilder */ - public function setBorderLeft($style = Border::STYLE_SOLID, $color = Color::BLACK, $width = Border::WIDTH_THICK) + public function setBorderLeft($color = Color::BLACK, $width = Border::WIDTH_MEDIUM, $style = Border::STYLE_SOLID) { - $this->border->addPart(new BorderPart(Border::LEFT, $style, $color, $width)); + $this->border->addPart(new BorderPart(Border::LEFT, $color, $width, $style)); return $this; } diff --git a/src/Spout/Writer/Style/BorderPart.php b/src/Spout/Writer/Style/BorderPart.php index 42951d8..9ade797 100644 --- a/src/Spout/Writer/Style/BorderPart.php +++ b/src/Spout/Writer/Style/BorderPart.php @@ -63,19 +63,19 @@ class BorderPart /** * @param string $name @see BorderPart::$allowedNames - * @param string $style @see BorderPart::$allowedStyles - * @param string $width @see BorderPart::$allowedWidths * @param string $color A RGB color code + * @param string $width @see BorderPart::$allowedWidths + * @param string $style @see BorderPart::$allowedStyles * @throws InvalidNameException * @throws InvalidStyleException * @throws InvalidWidthException */ - public function __construct($name, $style = Border::STYLE_SOLID, $color = Color::BLACK, $width = Border::WIDTH_MEDIUM) + public function __construct($name, $color = Color::BLACK, $width = Border::WIDTH_MEDIUM, $style = Border::STYLE_SOLID) { $this->setName($name); - $this->setStyle($style); - $this->setWidth($width); $this->setColor($color); + $this->setWidth($width); + $this->setStyle($style); } /** diff --git a/tests/Spout/Writer/ODS/WriterWithStyleTest.php b/tests/Spout/Writer/ODS/WriterWithStyleTest.php index 273528a..7a7c190 100644 --- a/tests/Spout/Writer/ODS/WriterWithStyleTest.php +++ b/tests/Spout/Writer/ODS/WriterWithStyleTest.php @@ -253,11 +253,11 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase ]; $borderBottomGreenThickSolid = (new BorderBuilder()) - ->setBorderBottom(Border::STYLE_SOLID, Color::GREEN, Border::WIDTH_THICK)->build(); + ->setBorderBottom(Color::GREEN, Border::WIDTH_THICK, Border::STYLE_SOLID)->build(); $borderTopRedThinDashed = (new BorderBuilder()) - ->setBorderTop(Border::STYLE_DASHED, Color::RED, Border::WIDTH_THIN)->build(); + ->setBorderTop(Color::RED, Border::WIDTH_THIN, Border::STYLE_DASHED)->build(); $styles = [ (new StyleBuilder())->setBorder($borderBottomGreenThickSolid)->build(), @@ -272,13 +272,8 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase $this->assertEquals(3, count($styleElements), 'There should be 3 styles)'); // Use reflection for protected members here - $widthMapReflection = new \ReflectionProperty('Box\Spout\Writer\ODS\Helper\BorderHelper', 'widthMap'); - $widthMapReflection->setAccessible(true); - $widthMap = $widthMapReflection->getValue(); - - $styleMapReflection = new \ReflectionProperty('Box\Spout\Writer\ODS\Helper\BorderHelper', 'styleMap'); - $styleMapReflection->setAccessible(true); - $styleMap = $styleMapReflection->getValue(); + $widthMap = \ReflectionHelper::getStaticValue('Box\Spout\Writer\ODS\Helper\BorderHelper', 'widthMap'); + $styleMap = \ReflectionHelper::getStaticValue('Box\Spout\Writer\ODS\Helper\BorderHelper', 'styleMap'); $expectedFirst = sprintf( '%s %s #%s', diff --git a/tests/Spout/Writer/Style/BorderTest.php b/tests/Spout/Writer/Style/BorderTest.php index bb768b1..181d8cf 100644 --- a/tests/Spout/Writer/Style/BorderTest.php +++ b/tests/Spout/Writer/Style/BorderTest.php @@ -28,7 +28,7 @@ class BorderTest extends \PHPUnit_Framework_TestCase */ public function testInvalidBorderPartStyle() { - $invalidBorderPartStyle = new BorderPart(Border::LEFT, 'invalid'); + $invalidBorderPartStyle = new BorderPart(Border::LEFT, Color::BLACK, Border::WIDTH_THIN, 'invalid'); } /** @@ -36,7 +36,7 @@ class BorderTest extends \PHPUnit_Framework_TestCase */ public function testInvalidBorderPartWidth() { - $invalidBorderPartStyle = new BorderPart(Border::LEFT, Border::STYLE_DASHED, Color::BLACK, 'invalid'); + $invalidBorderPartStyle = new BorderPart(Border::LEFT, Color::BLACK, 'invalid', Border::STYLE_DASHED); } /** @@ -92,7 +92,7 @@ class BorderTest extends \PHPUnit_Framework_TestCase foreach (BorderPart::getAllowedNames() as $allowedName) { foreach (BorderPart::getAllowedStyles() as $allowedStyle) { foreach (BorderPart::getAllowedWidths() as $allowedWidth) { - $borderPart = new BorderPart($allowedName, $allowedStyle, $color, $allowedWidth); + $borderPart = new BorderPart($allowedName, $color, $allowedWidth, $allowedStyle); $border = new Border(); $border->addPart($borderPart); $this->assertEquals(1, count($border->getParts())); @@ -108,4 +108,3 @@ class BorderTest extends \PHPUnit_Framework_TestCase } } } - diff --git a/tests/Spout/Writer/Style/StyleTest.php b/tests/Spout/Writer/Style/StyleTest.php index 03e31fe..7d3ec36 100644 --- a/tests/Spout/Writer/Style/StyleTest.php +++ b/tests/Spout/Writer/Style/StyleTest.php @@ -147,7 +147,7 @@ class StyleTest extends \PHPUnit_Framework_TestCase */ public function testStyleBuilderShouldMergeBorders() { - $border = (new BorderBuilder())->setBorderBottom(Border::STYLE_DASHED, Color::RED, Border::WIDTH_THIN)->build(); + $border = (new BorderBuilder())->setBorderBottom(Color::RED, Border::WIDTH_THIN, Border::STYLE_DASHED)->build(); $baseStyle = (new StyleBuilder())->setBorder($border)->build(); $currentStyle = (new StyleBuilder())->build(); diff --git a/tests/Spout/Writer/XLSX/WriterWithStyleTest.php b/tests/Spout/Writer/XLSX/WriterWithStyleTest.php index e013f9b..df34a33 100644 --- a/tests/Spout/Writer/XLSX/WriterWithStyleTest.php +++ b/tests/Spout/Writer/XLSX/WriterWithStyleTest.php @@ -248,11 +248,11 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase ]; $borderBottomGreenThickSolid = (new BorderBuilder()) - ->setBorderBottom(Border::STYLE_SOLID, Color::GREEN, Border::WIDTH_THICK)->build(); + ->setBorderBottom(Color::GREEN, Border::WIDTH_THICK, Border::STYLE_SOLID)->build(); $borderTopRedThinDashed = (new BorderBuilder()) - ->setBorderTop(Border::STYLE_DASHED, Color::RED, Border::WIDTH_THIN)->build(); + ->setBorderTop(Color::RED, Border::WIDTH_THIN, Border::STYLE_DASHED)->build(); $styles = [ (new StyleBuilder())->setBorder($borderBottomGreenThickSolid)->build(),