Consolidate external EntityFactory

All entities will now be created through a single factory (including the Writers).
Also, added a EntityFactory::createRowFromArray() to make it easier to create rows
This commit is contained in:
Adrien Loison committed 2017-11-05 13:18:29 +01:00
1 parent 2d2151ac8d
commit 3d0f108b1d
12 files changed
+201 -170

No files matched your search

+16 -24
View File
@@ -13,28 +13,30 @@ trait RowCreationHelper
{
/**
* @param array $cellValues
* @param Style|null $rowStyle
* @return Row
*/
protected function createRowFromValues(array $cellValues, Style $rowStyle = null)
protected function createRowFromValues(array $cellValues)
{
$row = EntityFactory::createRow([], $rowStyle);
foreach ($cellValues as $cellValue) {
$row->addCell(EntityFactory::createCell($cellValue));
}
return $row;
return $this->createStyledRowFromValues($cellValues, null);
}
/**
* @param array $cellValues
* @param Style $rowStyle
* @param Style|null $rowStyle
* @return Row
*/
protected function createStyledRowFromValues(array $cellValues, Style $rowStyle)
protected function createStyledRowFromValues(array $cellValues, Style $rowStyle = null)
{
return $this->createRowFromValues($cellValues, $rowStyle);
return EntityFactory::createRowFromArray($cellValues, $rowStyle);
}
/**
* @param array $rowValues
* @return Row[]
*/
protected function createRowsFromValues(array $rowValues)
{
return $this->createStyledRowsFromValues($rowValues, null);
}
/**
@@ -42,24 +44,14 @@ trait RowCreationHelper
* @param Style|null $rowsStyle
* @return Row[]
*/
protected function createRowsFromValues(array $rowValues, Style $rowsStyle = null)
protected function createStyledRowsFromValues(array $rowValues, Style $rowsStyle = null)
{
$rows = [];
foreach ($rowValues as $cellValues) {
$rows[] = $this->createRowFromValues($cellValues, $rowsStyle);
$rows[] = $this->createStyledRowFromValues($cellValues, $rowsStyle);
}
return $rows;
}
/**
* @param array $rowValues
* @param Style $rowsStyle
* @return Row[]
*/
protected function createStyledRowsFromValues(array $rowValues, Style $rowsStyle)
{
return $this->createRowsFromValues($rowValues, $rowsStyle);
}
}