various improvements
This commit is contained in:
1 parent
102e17159c
commit
4d1d1c1e87
19 files changed
+90
-112
No files matched your search
@@ -116,7 +116,7 @@ class InternalEntityFactory implements InternalEntityFactoryInterface
|
||||
* @param Cell[] $cells
|
||||
* @return Row
|
||||
*/
|
||||
public function createRow(array $cells)
|
||||
public function createRow(array $cells = [])
|
||||
{
|
||||
return new Row($cells);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Box\Spout\Reader\XLSX\Creator;
|
||||
|
||||
use Box\Spout\Reader\XLSX\Manager\RowManager;
|
||||
use Box\Spout\Reader\Common\Manager\RowManager;
|
||||
use Box\Spout\Reader\XLSX\Manager\SharedStringsCaching\CachingStrategyFactory;
|
||||
use Box\Spout\Reader\XLSX\Manager\SharedStringsManager;
|
||||
use Box\Spout\Reader\XLSX\Manager\SheetManager;
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Box\Spout\Reader\XLSX\Manager;
|
||||
|
||||
use Box\Spout\Reader\Common\Entity\Row;
|
||||
use Box\Spout\Reader\XLSX\Creator\InternalEntityFactory;
|
||||
|
||||
/**
|
||||
* Class RowManager
|
||||
*/
|
||||
class RowManager
|
||||
{
|
||||
/** @var InternalEntityFactory Factory to create entities */
|
||||
private $entityFactory;
|
||||
|
||||
/**
|
||||
* @param InternalEntityFactory $entityFactory Factory to create entities
|
||||
*/
|
||||
public function __construct(InternalEntityFactory $entityFactory)
|
||||
{
|
||||
$this->entityFactory = $entityFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect whether a row is considered empty.
|
||||
* An empty row has all of its cells empty.
|
||||
*
|
||||
* @param Row $row
|
||||
* @return bool
|
||||
*/
|
||||
public function isEmpty(Row $row)
|
||||
{
|
||||
foreach ($row->getCells() as $cell) {
|
||||
if (!$cell->isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fills the missing indexes of a row with empty cells.
|
||||
*
|
||||
* @param Row $row
|
||||
* @return Row
|
||||
*/
|
||||
public function fillMissingIndexesWithEmptyCells(Row $row)
|
||||
{
|
||||
$rowCells = $row->getCells();
|
||||
if (count($rowCells) === 0) {
|
||||
return $row;
|
||||
}
|
||||
|
||||
$maxCellIndex = max(array_keys($rowCells));
|
||||
|
||||
for ($cellIndex = 0; $cellIndex < $maxCellIndex; $cellIndex++) {
|
||||
if (!isset($rowCells[$cellIndex])) {
|
||||
$row->setCellAtIndex($this->entityFactory->createCell(''), $cellIndex);
|
||||
}
|
||||
}
|
||||
|
||||
return $row;
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ namespace Box\Spout\Reader\XLSX;
|
||||
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;
|
||||
use Box\Spout\Reader\Exception\XMLProcessingException;
|
||||
@@ -13,7 +14,6 @@ use Box\Spout\Reader\Wrapper\XMLReader;
|
||||
use Box\Spout\Reader\XLSX\Creator\InternalEntityFactory;
|
||||
use Box\Spout\Reader\XLSX\Helper\CellHelper;
|
||||
use Box\Spout\Reader\XLSX\Helper\CellValueFormatter;
|
||||
use Box\Spout\Reader\XLSX\Manager\RowManager;
|
||||
|
||||
/**
|
||||
* Class RowIterator
|
||||
@@ -47,7 +47,7 @@ class RowIterator implements IteratorInterface
|
||||
/** @var Helper\CellValueFormatter Helper to format cell values */
|
||||
protected $cellValueFormatter;
|
||||
|
||||
/** @var \Box\Spout\Reader\XLSX\Manager\RowManager Manages rows */
|
||||
/** @var \Box\Spout\Reader\Common\Manager\RowManager Manages rows */
|
||||
protected $rowManager;
|
||||
|
||||
/** @var \Box\Spout\Reader\XLSX\Creator\InternalEntityFactory Factory to create entities */
|
||||
@@ -215,7 +215,7 @@ class RowIterator implements IteratorInterface
|
||||
*/
|
||||
protected function readDataForNextRow()
|
||||
{
|
||||
$this->currentlyProcessedRow = $this->entityFactory->createRow([]);
|
||||
$this->currentlyProcessedRow = $this->entityFactory->createRow();
|
||||
|
||||
try {
|
||||
$this->xmlProcessor->readUntilStopped();
|
||||
@@ -386,7 +386,7 @@ class RowIterator implements IteratorInterface
|
||||
if ($this->lastRowIndexProcessed !== $this->nextRowIndexToBeProcessed) {
|
||||
// return empty row if mismatch between last processed row
|
||||
// and the row that needs to be returned
|
||||
$rowToBeProcessed = $this->entityFactory->createRow([]);
|
||||
$rowToBeProcessed = $this->entityFactory->createRow();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user