Move entities and managers back to Common (#431)
This commit is contained in:
1 parent
878c4a9c8b
commit
c4e25a168e
32 files changed
+79
-80
No files matched your search
@@ -0,0 +1,167 @@
|
||||
<?php
|
||||
|
||||
namespace Box\Spout\Writer\Common\Entity;
|
||||
|
||||
use Box\Spout\Writer\Common\Helper\CellHelper;
|
||||
|
||||
/**
|
||||
* Class Cell
|
||||
*
|
||||
* @package Box\Spout\Writer\Common\Entity
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
* Error cell type
|
||||
*/
|
||||
const TYPE_ERROR = 5;
|
||||
|
||||
/**
|
||||
* The value of this cell
|
||||
* @var mixed|null
|
||||
*/
|
||||
protected $value = null;
|
||||
|
||||
/**
|
||||
* The cell type
|
||||
* @var int|null
|
||||
*/
|
||||
protected $type = null;
|
||||
|
||||
/**
|
||||
* Cell constructor.
|
||||
* @param $value mixed
|
||||
*/
|
||||
public function __construct($value)
|
||||
{
|
||||
$this->setValue($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value mixed|null
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current value type
|
||||
* @param mixed|null $value
|
||||
* @return int
|
||||
*/
|
||||
protected function detectType($value)
|
||||
{
|
||||
if (CellHelper::isBoolean($value)) {
|
||||
return self::TYPE_BOOLEAN;
|
||||
} elseif (CellHelper::isEmpty($value)) {
|
||||
return self::TYPE_EMPTY;
|
||||
} elseif (CellHelper::isNumeric($this->getValue())) {
|
||||
return self::TYPE_NUMERIC;
|
||||
} elseif (CellHelper::isNonEmptyString($value)) {
|
||||
return self::TYPE_STRING;
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Not used at the moment
|
||||
* @return bool
|
||||
*/
|
||||
public function isFormula()
|
||||
{
|
||||
return $this->type === self::TYPE_FORMULA;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Box\Spout\Writer\Common\Entity;
|
||||
|
||||
/**
|
||||
* Class Options
|
||||
* Writer' options holder
|
||||
*
|
||||
* @package Box\Spout\Writer\Common\Entity
|
||||
*/
|
||||
abstract class Options
|
||||
{
|
||||
// CSV specific options
|
||||
const FIELD_DELIMITER = 'fieldDelimiter';
|
||||
const FIELD_ENCLOSURE = 'fieldEnclosure';
|
||||
const SHOULD_ADD_BOM = 'shouldAddBOM';
|
||||
|
||||
// Multisheets options
|
||||
const TEMP_FOLDER = 'tempFolder';
|
||||
const DEFAULT_ROW_STYLE = 'defaultRowStyle';
|
||||
const SHOULD_CREATE_NEW_SHEETS_AUTOMATICALLY = 'shouldCreateNewSheetsAutomatically';
|
||||
|
||||
// XLSX specific options
|
||||
const SHOULD_USE_INLINE_STRINGS = 'shouldUseInlineStrings';
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Box\Spout\Writer\Common\Entity;
|
||||
|
||||
/**
|
||||
* Class Workbook
|
||||
* Entity describing a workbook
|
||||
*
|
||||
* @package Box\Spout\Writer\Common\Entity
|
||||
*/
|
||||
class Workbook
|
||||
{
|
||||
/** @var Worksheet[] List of the workbook's sheets */
|
||||
private $worksheets = [];
|
||||
|
||||
/** @var string Timestamp based unique ID identifying the workbook */
|
||||
private $internalId;
|
||||
|
||||
/**
|
||||
* Workbook constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->internalId = uniqid();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Worksheet[]
|
||||
*/
|
||||
public function getWorksheets()
|
||||
{
|
||||
return $this->worksheets;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Worksheet[] $worksheets
|
||||
*/
|
||||
public function setWorksheets($worksheets)
|
||||
{
|
||||
$this->worksheets = $worksheets;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getInternalId()
|
||||
{
|
||||
return $this->internalId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
namespace Box\Spout\Writer\Common\Entity;
|
||||
|
||||
use Box\Spout\Writer\Common\Sheet;
|
||||
|
||||
/**
|
||||
* Class Worksheet
|
||||
* Entity describing a Worksheet
|
||||
*
|
||||
* @package Box\Spout\Writer\Common\Entity
|
||||
*/
|
||||
class Worksheet
|
||||
{
|
||||
/** @var string Path to the XML file that will contain the sheet data */
|
||||
private $filePath;
|
||||
|
||||
/** @var Resource Pointer to the sheet data file (e.g. xl/worksheets/sheet1.xml) */
|
||||
private $filePointer;
|
||||
|
||||
/** @var Sheet The "external" sheet */
|
||||
private $externalSheet;
|
||||
|
||||
/** @var int Maximum number of columns among all the written rows */
|
||||
private $maxNumColumns;
|
||||
|
||||
/** @var int Index of the last written row */
|
||||
private $lastWrittenRowIndex;
|
||||
|
||||
/**
|
||||
* Worksheet constructor.
|
||||
*
|
||||
* @param string $worksheetFilePath
|
||||
* @param Sheet $externalSheet
|
||||
*/
|
||||
public function __construct($worksheetFilePath, Sheet $externalSheet)
|
||||
{
|
||||
$this->filePath = $worksheetFilePath;
|
||||
$this->filePointer = null;
|
||||
$this->externalSheet = $externalSheet;
|
||||
$this->maxNumColumns = 0;
|
||||
$this->lastWrittenRowIndex = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getFilePath()
|
||||
{
|
||||
return $this->filePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Resource
|
||||
*/
|
||||
public function getFilePointer()
|
||||
{
|
||||
return $this->filePointer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Resource $filePointer
|
||||
*/
|
||||
public function setFilePointer($filePointer)
|
||||
{
|
||||
$this->filePointer = $filePointer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Sheet
|
||||
*/
|
||||
public function getExternalSheet()
|
||||
{
|
||||
return $this->externalSheet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getMaxNumColumns()
|
||||
{
|
||||
return $this->maxNumColumns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $maxNumColumns
|
||||
*/
|
||||
public function setMaxNumColumns($maxNumColumns)
|
||||
{
|
||||
$this->maxNumColumns = $maxNumColumns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getLastWrittenRowIndex()
|
||||
{
|
||||
return $this->lastWrittenRowIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $lastWrittenRowIndex
|
||||
*/
|
||||
public function setLastWrittenRowIndex($lastWrittenRowIndex)
|
||||
{
|
||||
$this->lastWrittenRowIndex = $lastWrittenRowIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int The ID of the worksheet
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
// sheet index is zero-based, while ID is 1-based
|
||||
return $this->externalSheet->getIndex() + 1;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user