spout/tests/Spout/Writer/RowCreationHelper.php
Adrien Loison ec5335cc23 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
2017-11-05 13:14:33 +01:00

58 lines
1.3 KiB
PHP

<?php
namespace Box\Spout\Writer;
use Box\Spout\Writer\Common\Creator\EntityFactory;
use Box\Spout\Writer\Common\Entity\Row;
use Box\Spout\Writer\Common\Entity\Style\Style;
/**
* Trait RowCreationHelper
*/
trait RowCreationHelper
{
/**
* @param array $cellValues
* @return Row
*/
protected function createRowFromValues(array $cellValues)
{
return $this->createStyledRowFromValues($cellValues, null);
}
/**
* @param array $cellValues
* @param Style|null $rowStyle
* @return Row
*/
protected function createStyledRowFromValues(array $cellValues, Style $rowStyle = null)
{
return EntityFactory::createRowFromArray($cellValues, $rowStyle);
}
/**
* @param array $rowValues
* @return Row[]
*/
protected function createRowsFromValues(array $rowValues)
{
return $this->createStyledRowsFromValues($rowValues, null);
}
/**
* @param array $rowValues
* @param Style|null $rowsStyle
* @return Row[]
*/
protected function createStyledRowsFromValues(array $rowValues, Style $rowsStyle = null)
{
$rows = [];
foreach ($rowValues as $cellValues) {
$rows[] = $this->createStyledRowFromValues($cellValues, $rowsStyle);
}
return $rows;
}
}