StyleMerger and RowManager changes
Move DI of StyleMerger to get rid of business logic in the entities Cell and Row Simplify RowManager
This commit is contained in:
1 parent
111f82d35f
commit
ddfa40e8b3
10 files changed
+67
-166
No files matched your search
@@ -5,8 +5,6 @@ namespace Box\Spout\Writer\Common\Creator;
|
||||
use Box\Spout\Writer\Common\Entity\Cell;
|
||||
use Box\Spout\Writer\Common\Entity\Row;
|
||||
use Box\Spout\Writer\Common\Entity\Style\Style;
|
||||
use Box\Spout\Writer\Common\Manager\RowManager;
|
||||
use Box\Spout\Writer\Common\Manager\Style\StyleMerger;
|
||||
use Box\Spout\Writer\WriterInterface;
|
||||
|
||||
/**
|
||||
@@ -34,10 +32,7 @@ class EntityFactory
|
||||
*/
|
||||
public static function createRow(array $cells = [], Style $rowStyle = null)
|
||||
{
|
||||
$styleMerger = new StyleMerger();
|
||||
$rowManager = new RowManager($styleMerger);
|
||||
|
||||
return new Row($cells, $rowStyle, $rowManager);
|
||||
return new Row($cells, $rowStyle);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,14 +42,11 @@ class EntityFactory
|
||||
*/
|
||||
public static function createRowFromArray(array $cellValues = [], Style $rowStyle = null)
|
||||
{
|
||||
$styleMerger = new StyleMerger();
|
||||
$rowManager = new RowManager($styleMerger);
|
||||
|
||||
$cells = array_map(function ($cellValue) {
|
||||
return new Cell($cellValue);
|
||||
}, $cellValues);
|
||||
|
||||
return new Row($cells, $rowStyle, $rowManager);
|
||||
return new Row($cells, $rowStyle);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -198,20 +198,4 @@ class Cell
|
||||
{
|
||||
return (string) $this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Style|null $style
|
||||
* @return Cell
|
||||
*/
|
||||
public function applyStyle($style)
|
||||
{
|
||||
if ($style === null) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$mergedStyle = $this->styleMerger->merge($this->style, $style);
|
||||
$this->setStyle($mergedStyle);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace Box\Spout\Writer\Common\Entity;
|
||||
|
||||
use Box\Spout\Writer\Common\Entity\Style\Style;
|
||||
use Box\Spout\Writer\Common\Manager\RowManager;
|
||||
|
||||
class Row
|
||||
{
|
||||
@@ -19,25 +18,16 @@ class Row
|
||||
*/
|
||||
protected $style;
|
||||
|
||||
/**
|
||||
* Thw row manager
|
||||
* @var RowManager
|
||||
*/
|
||||
protected $rowManager;
|
||||
|
||||
/**
|
||||
* Row constructor.
|
||||
* @param Cell[] $cells
|
||||
* @param Style|null $style
|
||||
* @param RowManager $rowManager
|
||||
*/
|
||||
public function __construct(array $cells, $style, RowManager $rowManager)
|
||||
public function __construct(array $cells, $style)
|
||||
{
|
||||
$this
|
||||
->setCells($cells)
|
||||
->setStyle($style);
|
||||
|
||||
$this->rowManager = $rowManager;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,17 +71,6 @@ class Row
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Style $style
|
||||
* @return Row
|
||||
*/
|
||||
public function applyStyle($style)
|
||||
{
|
||||
$this->rowManager->applyStyle($this, $style);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Cell $cell
|
||||
* @return Row
|
||||
@@ -102,25 +81,4 @@ class Row
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether a row has cells
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasCells()
|
||||
{
|
||||
return $this->rowManager->hasCells($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect whether this row is considered empty.
|
||||
* An empty row has either no cells at all - or only empty cells
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isEmpty()
|
||||
{
|
||||
return $this->rowManager->isEmpty($this);
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace Box\Spout\Writer\Common\Manager;
|
||||
|
||||
use Box\Spout\Writer\Common\Entity\Row;
|
||||
use Box\Spout\Writer\Common\Entity\Style\Style;
|
||||
use Box\Spout\Writer\Common\Manager\Style\StyleMerger;
|
||||
|
||||
class RowManager
|
||||
@@ -21,28 +20,6 @@ class RowManager
|
||||
$this->styleMerger = $styleMerger;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Row $row
|
||||
* @param Style $style
|
||||
* @return $this
|
||||
*/
|
||||
public function applyStyle(Row $row, Style $style)
|
||||
{
|
||||
$mergedStyle = $this->styleMerger->merge($row->getStyle(), $style);
|
||||
$row->setStyle($mergedStyle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether a row has cells
|
||||
*
|
||||
* @param Row $row
|
||||
* @return bool
|
||||
*/
|
||||
public function hasCells(Row $row)
|
||||
{
|
||||
return count($row->getCells()) !== 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect whether a row is considered empty.
|
||||
* An empty row has either no cells at all - or only one empty cell
|
||||
|
||||
Reference in new issue
Block a user