rename EntityFactory for writers and readers #526
This commit is contained in:
1 parent
e1acdc1fc5
commit
8a1c48b6b0
18 files changed
+97
-97
No files matched your search
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace Box\Spout\Writer\Common\Creator;
|
||||
|
||||
use Box\Spout\Common\Entity\Cell;
|
||||
use Box\Spout\Common\Entity\Row;
|
||||
use Box\Spout\Common\Entity\Style\Style;
|
||||
use Box\Spout\Writer\WriterInterface;
|
||||
|
||||
/**
|
||||
* Class WriterEntityFactory
|
||||
* Factory to create external entities
|
||||
*/
|
||||
class WriterEntityFactory
|
||||
{
|
||||
/**
|
||||
* This creates an instance of the appropriate writer, given the type of the file to be written
|
||||
*
|
||||
* @param string $writerType Type of the writer to instantiate
|
||||
* @throws \Box\Spout\Common\Exception\UnsupportedTypeException
|
||||
* @return WriterInterface
|
||||
*/
|
||||
public static function createWriter($writerType)
|
||||
{
|
||||
return (new WriterFactory())->create($writerType);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Cell[] $cells
|
||||
* @param Style|null $rowStyle
|
||||
* @return Row
|
||||
*/
|
||||
public static function createRow(array $cells = [], Style $rowStyle = null)
|
||||
{
|
||||
return new Row($cells, $rowStyle);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $cellValues
|
||||
* @param Style|null $rowStyle
|
||||
* @return Row
|
||||
*/
|
||||
public static function createRowFromArray(array $cellValues = [], Style $rowStyle = null)
|
||||
{
|
||||
$cells = array_map(function ($cellValue) {
|
||||
return new Cell($cellValue);
|
||||
}, $cellValues);
|
||||
|
||||
return new Row($cells, $rowStyle);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $cellValue
|
||||
* @param Style|null $cellStyle
|
||||
* @return Cell
|
||||
*/
|
||||
public static function createCell($cellValue, Style $cellStyle = null)
|
||||
{
|
||||
return new Cell($cellValue, $cellStyle);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user