Merge Reader and Writer entities

Merged Cell/Row/Style entities
This commit is contained in:
Adrien Loison committed 2017-11-19 02:54:17 +01:00
1 parent 4d1d1c1e87
commit f5168114d0
66 files changed
+183 -576

No files matched your search

@@ -3,11 +3,11 @@
namespace Box\Spout\Reader\CSV\Creator;
use Box\Spout\Common\Creator\HelperFactory;
use Box\Spout\Common\Entity\Cell;
use Box\Spout\Common\Entity\Row;
use Box\Spout\Common\Helper\GlobalFunctionsHelper;
use Box\Spout\Common\Manager\OptionsManagerInterface;
use Box\Spout\Reader\Common\Creator\InternalEntityFactoryInterface;
use Box\Spout\Reader\Common\Entity\Cell;
use Box\Spout\Reader\Common\Entity\Row;
use Box\Spout\Reader\CSV\RowIterator;
use Box\Spout\Reader\CSV\Sheet;
use Box\Spout\Reader\CSV\SheetIterator;
@@ -71,7 +71,7 @@ class InternalEntityFactory implements InternalEntityFactoryInterface
*/
public function createRow(array $cells = [])
{
return new Row($cells);
return new Row($cells, null);
}
/**
+1 -1
View File
@@ -2,11 +2,11 @@
namespace Box\Spout\Reader\CSV;
use Box\Spout\Common\Entity\Row;
use Box\Spout\Common\Helper\EncodingHelper;
use Box\Spout\Common\Helper\GlobalFunctionsHelper;
use Box\Spout\Common\Manager\OptionsManagerInterface;
use Box\Spout\Reader\Common\Entity\Options;
use Box\Spout\Reader\Common\Entity\Row;
use Box\Spout\Reader\CSV\Creator\InternalEntityFactory;
use Box\Spout\Reader\IteratorInterface;
@@ -2,8 +2,8 @@
namespace Box\Spout\Reader\Common\Creator;
use Box\Spout\Reader\Common\Entity\Cell;
use Box\Spout\Reader\Common\Entity\Row;
use Box\Spout\Common\Entity\Cell;
use Box\Spout\Common\Entity\Row;
/**
* Interface EntityFactoryInterface
-175
View File
@@ -1,175 +0,0 @@
<?php
namespace Box\Spout\Reader\Common\Entity;
use Box\Spout\Common\Helper\CellTypeHelper;
/**
* Class Cell
*/
class Cell
{
/**
* Numeric cell type (whole numbers, fractional numbers, dates)
*/
const TYPE_NUMERIC = 0;
/**
* String (text) cell type
*/
const TYPE_STRING = 1;
/**
* Formula cell type
* Not used at the moment
*/
const TYPE_FORMULA = 2;
/**
* Empty cell type
*/
const TYPE_EMPTY = 3;
/**
* Boolean cell type
*/
const TYPE_BOOLEAN = 4;
/**
* Date cell type
*/
const TYPE_DATE = 5;
/**
* Error cell type
*/
const TYPE_ERROR = 6;
/**
* The value of this cell
* @var mixed|null
*/
protected $value;
/**
* The cell type
* @var int|null
*/
protected $type;
/**
* @param $value mixed
*/
public function __construct($value)
{
$this->setValue($value);
}
/**
* @param mixed|null $value
*/
public function setValue($value)
{
$this->value = $value;
$this->type = $this->detectType($value);
}
/**
* @return mixed|null
*/
public function getValue()
{
return $this->value;
}
/**
* @return int|null
*/
public function getType()
{
return $this->type;
}
/**
* @param int $type
*/
public function setType($type)
{
$this->type = $type;
}
/**
* Get the current value type
*
* @param mixed|null $value
* @return int
*/
protected function detectType($value)
{
if (CellTypeHelper::isBoolean($value)) {
return self::TYPE_BOOLEAN;
}
if (CellTypeHelper::isEmpty($value)) {
return self::TYPE_EMPTY;
}
if (CellTypeHelper::isNumeric($value)) {
return self::TYPE_NUMERIC;
}
if (CellTypeHelper::isDateTimeOrDateInterval($value)) {
return self::TYPE_DATE;
}
if (CellTypeHelper::isNonEmptyString($value)) {
return self::TYPE_STRING;
}
return self::TYPE_ERROR;
}
/**
* @return bool
*/
public function isBoolean()
{
return $this->type === self::TYPE_BOOLEAN;
}
/**
* @return bool
*/
public function isEmpty()
{
return $this->type === self::TYPE_EMPTY;
}
/**
* @return bool
*/
public function isNumeric()
{
return $this->type === self::TYPE_NUMERIC;
}
/**
* @return bool
*/
public function isString()
{
return $this->type === self::TYPE_STRING;
}
/**
* @return bool
*/
public function isError()
{
return $this->type === self::TYPE_ERROR;
}
/**
* @return string
*/
public function __toString()
{
return (string) $this->value;
}
}
-85
View File
@@ -1,85 +0,0 @@
<?php
namespace Box\Spout\Reader\Common\Entity;
class Row
{
/**
* The cells in this row
* @var Cell[]
*/
protected $cells = [];
/**
* Row constructor.
* @param Cell[] $cells
*/
public function __construct(array $cells)
{
$this->setCells($cells);
}
/**
* @return Cell[] $cells
*/
public function getCells()
{
return $this->cells;
}
/**
* @param Cell[] $cells
* @return Row
*/
public function setCells(array $cells)
{
$this->cells = [];
foreach ($cells as $cell) {
$this->addCell($cell);
}
return $this;
}
/**
* @param Cell $cell
* @param mixed $cellIndex
* @parma int $cellIndex
* @return Row
*/
public function setCellAtIndex(Cell $cell, $cellIndex)
{
$this->cells[$cellIndex] = $cell;
return $this;
}
/**
* @param Cell $cell
* @return Row
*/
public function addCell(Cell $cell)
{
$this->cells[] = $cell;
return $this;
}
/**
* @return int
*/
public function getNumCells()
{
return count($this->cells);
}
/**
* @return array The row values, as array
*/
public function toArray()
{
return array_map(function (Cell $cell) {
return !$cell->isError() ? $cell->getValue() : null;
}, $this->cells);
}
}
@@ -2,8 +2,8 @@
namespace Box\Spout\Reader\Common\Manager;
use Box\Spout\Common\Entity\Row;
use Box\Spout\Reader\Common\Creator\InternalEntityFactoryInterface;
use Box\Spout\Reader\Common\Entity\Row;
/**
* Class RowManager
@@ -2,10 +2,10 @@
namespace Box\Spout\Reader\ODS\Creator;
use Box\Spout\Common\Entity\Cell;
use Box\Spout\Common\Entity\Row;
use Box\Spout\Reader\Common\Creator\InternalEntityFactoryInterface;
use Box\Spout\Reader\Common\Entity\Cell;
use Box\Spout\Reader\Common\Entity\Options;
use Box\Spout\Reader\Common\Entity\Row;
use Box\Spout\Reader\Common\XMLProcessor;
use Box\Spout\Reader\ODS\RowIterator;
use Box\Spout\Reader\ODS\Sheet;
@@ -84,7 +84,7 @@ class InternalEntityFactory implements InternalEntityFactoryInterface
*/
public function createRow(array $cells = [])
{
return new Row($cells);
return new Row($cells, null);
}
/**
+2 -2
View File
@@ -2,11 +2,11 @@
namespace Box\Spout\Reader\ODS;
use Box\Spout\Common\Entity\Cell;
use Box\Spout\Common\Entity\Row;
use Box\Spout\Common\Exception\IOException;
use Box\Spout\Common\Manager\OptionsManagerInterface;
use Box\Spout\Reader\Common\Entity\Cell;
use Box\Spout\Reader\Common\Entity\Options;
use Box\Spout\Reader\Common\Entity\Row;
use Box\Spout\Reader\Common\Manager\RowManager;
use Box\Spout\Reader\Common\XMLProcessor;
use Box\Spout\Reader\Exception\InvalidValueException;
@@ -2,10 +2,10 @@
namespace Box\Spout\Reader\XLSX\Creator;
use Box\Spout\Common\Entity\Cell;
use Box\Spout\Common\Entity\Row;
use Box\Spout\Reader\Common\Creator\InternalEntityFactoryInterface;
use Box\Spout\Reader\Common\Entity\Cell;
use Box\Spout\Reader\Common\Entity\Options;
use Box\Spout\Reader\Common\Entity\Row;
use Box\Spout\Reader\Common\XMLProcessor;
use Box\Spout\Reader\Wrapper\XMLReader;
use Box\Spout\Reader\XLSX\Manager\SharedStringsManager;
@@ -118,7 +118,7 @@ class InternalEntityFactory implements InternalEntityFactoryInterface
*/
public function createRow(array $cells = [])
{
return new Row($cells);
return new Row($cells, null);
}
/**
+2 -2
View File
@@ -2,9 +2,9 @@
namespace Box\Spout\Reader\XLSX;
use Box\Spout\Common\Entity\Cell;
use Box\Spout\Common\Entity\Row;
use Box\Spout\Common\Exception\IOException;
use Box\Spout\Reader\Common\Entity\Cell;
use Box\Spout\Reader\Common\Entity\Row;
use Box\Spout\Reader\Common\Manager\RowManager;
use Box\Spout\Reader\Common\XMLProcessor;
use Box\Spout\Reader\Exception\InvalidValueException;