Fix code style
This commit is contained in:
1 parent
740fcfb8c1
commit
b968513cb9
171 files changed
+517
-792
No files matched your search
@@ -5,18 +5,16 @@ namespace Box\Spout\Reader\XLSX\Creator;
|
||||
use Box\Spout\Reader\Common\Creator\EntityFactoryInterface;
|
||||
use Box\Spout\Reader\Common\Entity\Options;
|
||||
use Box\Spout\Reader\Common\XMLProcessor;
|
||||
use Box\Spout\Reader\Wrapper\XMLReader;
|
||||
use Box\Spout\Reader\XLSX\Manager\SharedStringsManager;
|
||||
use Box\Spout\Reader\XLSX\RowIterator;
|
||||
use Box\Spout\Reader\XLSX\Sheet;
|
||||
use Box\Spout\Reader\XLSX\SheetIterator;
|
||||
use Box\Spout\Reader\Wrapper\XMLReader;
|
||||
use MongoDB\Driver\Manager;
|
||||
|
||||
/**
|
||||
* Class EntityFactory
|
||||
* Factory to create entities
|
||||
*
|
||||
* @package Box\Spout\Reader\XLSX\Creator
|
||||
*/
|
||||
class EntityFactory implements EntityFactoryInterface
|
||||
{
|
||||
@@ -45,6 +43,7 @@ class EntityFactory implements EntityFactoryInterface
|
||||
public function createSheetIterator($filePath, $optionsManager, $sharedStringsManager)
|
||||
{
|
||||
$sheetManager = $this->managerFactory->createSheetManager($filePath, $optionsManager, $sharedStringsManager, $this);
|
||||
|
||||
return new SheetIterator($sheetManager);
|
||||
}
|
||||
|
||||
@@ -65,9 +64,10 @@ class EntityFactory implements EntityFactoryInterface
|
||||
$sheetName,
|
||||
$isSheetActive,
|
||||
$optionsManager,
|
||||
$sharedStringsManager)
|
||||
{
|
||||
$sharedStringsManager
|
||||
) {
|
||||
$rowIterator = $this->createRowIterator($filePath, $sheetDataXMLFilePath, $optionsManager, $sharedStringsManager);
|
||||
|
||||
return new Sheet($rowIterator, $sheetIndex, $sheetName, $isSheetActive);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,17 +4,12 @@ namespace Box\Spout\Reader\XLSX\Creator;
|
||||
|
||||
use Box\Spout\Common\Helper\Escaper;
|
||||
use Box\Spout\Reader\XLSX\Helper\CellValueFormatter;
|
||||
use Box\Spout\Reader\XLSX\Manager\SharedStringsCaching\CachingStrategyFactory;
|
||||
use Box\Spout\Reader\XLSX\Manager\SharedStringsManager;
|
||||
use Box\Spout\Reader\XLSX\Manager\SheetManager;
|
||||
use Box\Spout\Reader\XLSX\Manager\StyleManager;
|
||||
|
||||
|
||||
/**
|
||||
* Class HelperFactory
|
||||
* Factory to create helpers
|
||||
*
|
||||
* @package Box\Spout\Reader\XLSX\Creator
|
||||
*/
|
||||
class HelperFactory extends \Box\Spout\Common\Creator\HelperFactory
|
||||
{
|
||||
@@ -27,6 +22,7 @@ class HelperFactory extends \Box\Spout\Common\Creator\HelperFactory
|
||||
public function createCellValueFormatter($sharedStringsManager, $styleManager, $shouldFormatDates)
|
||||
{
|
||||
$escaper = $this->createStringsEscaper();
|
||||
|
||||
return new CellValueFormatter($sharedStringsManager, $styleManager, $shouldFormatDates, $escaper);
|
||||
}
|
||||
|
||||
@@ -35,7 +31,7 @@ class HelperFactory extends \Box\Spout\Common\Creator\HelperFactory
|
||||
*/
|
||||
public function createStringsEscaper()
|
||||
{
|
||||
/** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */
|
||||
/* @noinspection PhpUnnecessaryFullyQualifiedNameInspection */
|
||||
return new Escaper\XLSX();
|
||||
}
|
||||
}
|
||||
@@ -7,12 +7,9 @@ use Box\Spout\Reader\XLSX\Manager\SharedStringsManager;
|
||||
use Box\Spout\Reader\XLSX\Manager\SheetManager;
|
||||
use Box\Spout\Reader\XLSX\Manager\StyleManager;
|
||||
|
||||
|
||||
/**
|
||||
* Class ManagerFactory
|
||||
* Factory to create managers
|
||||
*
|
||||
* @package Box\Spout\Reader\XLSX\Creator
|
||||
*/
|
||||
class ManagerFactory
|
||||
{
|
||||
@@ -53,6 +50,7 @@ class ManagerFactory
|
||||
public function createSheetManager($filePath, $optionsManager, $sharedStringsManager, $entityFactory)
|
||||
{
|
||||
$escaper = $this->helperFactory->createStringsEscaper();
|
||||
|
||||
return new SheetManager($filePath, $optionsManager, $sharedStringsManager, $escaper, $entityFactory);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,8 +7,6 @@ use Box\Spout\Common\Exception\InvalidArgumentException;
|
||||
/**
|
||||
* Class CellHelper
|
||||
* This class provides helper functions when working with cells
|
||||
*
|
||||
* @package Box\Spout\Reader\XLSX\Helper
|
||||
*/
|
||||
class CellHelper
|
||||
{
|
||||
@@ -51,8 +49,8 @@ class CellHelper
|
||||
* The mapping is zero based, so that A1 maps to 0, B2 maps to 1, Z13 to 25 and AA4 to 26.
|
||||
*
|
||||
* @param string $cellIndex The Excel cell index ('A1', 'BC13', ...)
|
||||
* @return int
|
||||
* @throws \Box\Spout\Common\Exception\InvalidArgumentException When the given cell index is invalid
|
||||
* @return int
|
||||
*/
|
||||
public static function getColumnIndexFromCellIndex($cellIndex)
|
||||
{
|
||||
|
||||
@@ -8,8 +8,6 @@ use Box\Spout\Reader\XLSX\Manager\StyleManager;
|
||||
/**
|
||||
* Class CellValueFormatter
|
||||
* This class provides helper functions to format cell values
|
||||
*
|
||||
* @package Box\Spout\Reader\XLSX\Helper
|
||||
*/
|
||||
class CellValueFormatter
|
||||
{
|
||||
@@ -77,7 +75,7 @@ class CellValueFormatter
|
||||
{
|
||||
// Default cell type is "n"
|
||||
$cellType = $node->getAttribute(self::XML_ATTRIBUTE_TYPE) ?: self::CELL_TYPE_NUMERIC;
|
||||
$cellStyleId = intval($node->getAttribute(self::XML_ATTRIBUTE_STYLE_ID));
|
||||
$cellStyleId = (int) $node->getAttribute(self::XML_ATTRIBUTE_STYLE_ID);
|
||||
$vNodeValue = $this->getVNodeValue($node);
|
||||
|
||||
if (($vNodeValue === '') && ($cellType !== self::CELL_TYPE_INLINE_STRING)) {
|
||||
@@ -113,6 +111,7 @@ class CellValueFormatter
|
||||
// for cell types having a "v" tag containing the value.
|
||||
// if not, the returned value should be empty string.
|
||||
$vNode = $node->getElementsByTagName(self::XML_NODE_VALUE)->item(0);
|
||||
|
||||
return ($vNode !== null) ? $vNode->nodeValue : '';
|
||||
}
|
||||
|
||||
@@ -128,6 +127,7 @@ class CellValueFormatter
|
||||
// <c r="A1" t="inlineStr"><is><t>[INLINE_STRING]</t></is></c>
|
||||
$tNode = $node->getElementsByTagName(self::XML_NODE_INLINE_STRING_VALUE)->item(0);
|
||||
$cellValue = $this->escaper->unescape($tNode->nodeValue);
|
||||
|
||||
return $cellValue;
|
||||
}
|
||||
|
||||
@@ -141,9 +141,10 @@ class CellValueFormatter
|
||||
{
|
||||
// shared strings are formatted this way:
|
||||
// <c r="A1" t="s"><v>[SHARED_STRING_INDEX]</v></c>
|
||||
$sharedStringIndex = intval($nodeValue);
|
||||
$sharedStringIndex = (int) $nodeValue;
|
||||
$escapedCellValue = $this->sharedStringsManager->getStringAtIndex($sharedStringIndex);
|
||||
$cellValue = $this->escaper->unescape($escapedCellValue);
|
||||
|
||||
return $cellValue;
|
||||
}
|
||||
|
||||
@@ -157,6 +158,7 @@ class CellValueFormatter
|
||||
{
|
||||
$escapedCellValue = trim($nodeValue);
|
||||
$cellValue = $this->escaper->unescape($escapedCellValue);
|
||||
|
||||
return $cellValue;
|
||||
}
|
||||
|
||||
@@ -175,9 +177,9 @@ class CellValueFormatter
|
||||
$shouldFormatAsDate = $this->styleManager->shouldFormatNumericValueAsDate($cellStyleId);
|
||||
|
||||
if ($shouldFormatAsDate) {
|
||||
$cellValue = $this->formatExcelTimestampValue(floatval($nodeValue), $cellStyleId);
|
||||
$cellValue = $this->formatExcelTimestampValue((float) $nodeValue, $cellStyleId);
|
||||
} else {
|
||||
$nodeIntValue = intval($nodeValue);
|
||||
$nodeIntValue = (int) $nodeValue;
|
||||
$nodeFloatValue = (float) $nodeValue;
|
||||
$cellValue = ((float) $nodeIntValue === $nodeFloatValue) ? $nodeIntValue : $nodeFloatValue;
|
||||
}
|
||||
@@ -204,7 +206,7 @@ class CellValueFormatter
|
||||
if ($nodeValue >= 1) {
|
||||
// Values greater than 1 represent "dates". The value 1.0 representing the "base" date: 1900-01-01.
|
||||
$cellValue = $this->formatExcelTimestampValueAsDateValue($nodeValue, $cellStyleId);
|
||||
} else if ($nodeValue >= 0) {
|
||||
} elseif ($nodeValue >= 0) {
|
||||
// Values between 0 and 1 represent "times".
|
||||
$cellValue = $this->formatExcelTimestampValueAsTimeValue($nodeValue, $cellStyleId);
|
||||
} else {
|
||||
@@ -262,7 +264,7 @@ class CellValueFormatter
|
||||
|
||||
try {
|
||||
$dateObj = \DateTime::createFromFormat('|Y-m-d', '1899-12-31');
|
||||
$dateObj->modify('+' . intval($nodeValue) . 'days');
|
||||
$dateObj->modify('+' . (int) $nodeValue . 'days');
|
||||
$dateObj->modify('+' . $secondsRemainder . 'seconds');
|
||||
|
||||
if ($this->shouldFormatDates) {
|
||||
|
||||
@@ -5,8 +5,6 @@ namespace Box\Spout\Reader\XLSX\Helper;
|
||||
/**
|
||||
* Class DateFormatHelper
|
||||
* This class provides helper functions to format Excel dates
|
||||
*
|
||||
* @package Box\Spout\Reader\XLSX\Helper
|
||||
*/
|
||||
class DateFormatHelper
|
||||
{
|
||||
@@ -104,9 +102,10 @@ class DateFormatHelper
|
||||
// Finally, to have the date format compatible with the DateTime::format() function, we need to escape
|
||||
// all characters that are inside double quotes (and double quotes must be removed).
|
||||
// For instance, ["Day " dd] should become [\D\a\y\ dd]
|
||||
$phpDateFormat = preg_replace_callback('/"(.+?)"/', function($matches) {
|
||||
$phpDateFormat = preg_replace_callback('/"(.+?)"/', function ($matches) {
|
||||
$stringToEscape = $matches[1];
|
||||
$letters = preg_split('//u', $stringToEscape, -1, PREG_SPLIT_NO_EMPTY);
|
||||
|
||||
return '\\' . implode('\\', $letters);
|
||||
}, $phpDateFormat);
|
||||
|
||||
|
||||
@@ -8,13 +8,11 @@ use Box\Spout\Reader\Common\Entity\Options;
|
||||
/**
|
||||
* Class OptionsManager
|
||||
* XLSX Reader options manager
|
||||
*
|
||||
* @package Box\Spout\Reader\XLSX\Manager
|
||||
*/
|
||||
class OptionsManager extends OptionsManagerAbstract
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getSupportedOptions()
|
||||
{
|
||||
@@ -26,7 +24,7 @@ class OptionsManager extends OptionsManagerAbstract
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setDefaultOptions()
|
||||
{
|
||||
|
||||
@@ -6,8 +6,6 @@ use Box\Spout\Reader\XLSX\Creator\HelperFactory;
|
||||
|
||||
/**
|
||||
* Class CachingStrategyFactory
|
||||
*
|
||||
* @package Box\Spout\Reader\XLSX\Manager\SharedStringsCaching
|
||||
*/
|
||||
class CachingStrategyFactory
|
||||
{
|
||||
@@ -52,7 +50,6 @@ class CachingStrategyFactory
|
||||
*/
|
||||
const MAX_NUM_STRINGS_PER_TEMP_FILE = 10000;
|
||||
|
||||
|
||||
/**
|
||||
* Returns the best caching strategy, given the number of unique shared strings
|
||||
* and the amount of memory available.
|
||||
@@ -114,7 +111,7 @@ class CachingStrategyFactory
|
||||
}
|
||||
|
||||
if (preg_match('/(\d+)([bkmgt])b?/', $memoryLimitFormatted, $matches)) {
|
||||
$amount = intval($matches[1]);
|
||||
$amount = (int) ($matches[1]);
|
||||
$unit = $matches[2];
|
||||
|
||||
switch ($unit) {
|
||||
|
||||
@@ -4,8 +4,6 @@ namespace Box\Spout\Reader\XLSX\Manager\SharedStringsCaching;
|
||||
|
||||
/**
|
||||
* Interface CachingStrategyInterface
|
||||
*
|
||||
* @package Box\Spout\Reader\XLSX\Manager\SharedStringsCaching
|
||||
*/
|
||||
interface CachingStrategyInterface
|
||||
{
|
||||
@@ -30,8 +28,8 @@ interface CachingStrategyInterface
|
||||
* Returns the string located at the given index from the cache.
|
||||
*
|
||||
* @param int $sharedStringIndex Index of the shared string in the sharedStrings.xml file
|
||||
* @return string The shared string at the given index
|
||||
* @throws \Box\Spout\Reader\Exception\SharedStringNotFoundException If no shared string found for the given index
|
||||
* @return string The shared string at the given index
|
||||
*/
|
||||
public function getStringAtIndex($sharedStringIndex);
|
||||
|
||||
|
||||
@@ -11,8 +11,6 @@ use Box\Spout\Reader\XLSX\Creator\HelperFactory;
|
||||
* This class implements the file-based caching strategy for shared strings.
|
||||
* Shared strings are stored in small files (with a max number of strings per file).
|
||||
* This strategy is slower than an in-memory strategy but is used to avoid out of memory crashes.
|
||||
*
|
||||
* @package Box\Spout\Reader\XLSX\Manager\SharedStringsCaching
|
||||
*/
|
||||
class FileBasedStrategy implements CachingStrategyInterface
|
||||
{
|
||||
@@ -98,7 +96,8 @@ class FileBasedStrategy implements CachingStrategyInterface
|
||||
*/
|
||||
protected function getSharedStringTempFilePath($sharedStringIndex)
|
||||
{
|
||||
$numTempFile = intval($sharedStringIndex / $this->maxNumStringsPerTempFile);
|
||||
$numTempFile = (int) ($sharedStringIndex / $this->maxNumStringsPerTempFile);
|
||||
|
||||
return $this->tempFolder . '/sharedstrings' . $numTempFile;
|
||||
}
|
||||
|
||||
@@ -116,13 +115,12 @@ class FileBasedStrategy implements CachingStrategyInterface
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the string located at the given index from the cache.
|
||||
*
|
||||
* @param int $sharedStringIndex Index of the shared string in the sharedStrings.xml file
|
||||
* @return string The shared string at the given index
|
||||
* @throws \Box\Spout\Reader\Exception\SharedStringNotFoundException If no shared string found for the given index
|
||||
* @return string The shared string at the given index
|
||||
*/
|
||||
public function getStringAtIndex($sharedStringIndex)
|
||||
{
|
||||
|
||||
@@ -9,8 +9,6 @@ use Box\Spout\Reader\Exception\SharedStringNotFoundException;
|
||||
*
|
||||
* This class implements the in-memory caching strategy for shared strings.
|
||||
* This strategy is used when the number of unique strings is low, compared to the memory available.
|
||||
*
|
||||
* @package Box\Spout\Reader\XLSX\Manager\SharedStringsCaching
|
||||
*/
|
||||
class InMemoryStrategy implements CachingStrategyInterface
|
||||
{
|
||||
@@ -58,8 +56,8 @@ class InMemoryStrategy implements CachingStrategyInterface
|
||||
* Returns the string located at the given index from the cache.
|
||||
*
|
||||
* @param int $sharedStringIndex Index of the shared string in the sharedStrings.xml file
|
||||
* @return string The shared string at the given index
|
||||
* @throws \Box\Spout\Reader\Exception\SharedStringNotFoundException If no shared string found for the given index
|
||||
* @return string The shared string at the given index
|
||||
*/
|
||||
public function getStringAtIndex($sharedStringIndex)
|
||||
{
|
||||
|
||||
@@ -13,8 +13,6 @@ use Box\Spout\Reader\XLSX\Manager\SharedStringsCaching\CachingStrategyInterface;
|
||||
/**
|
||||
* Class SharedStringsManager
|
||||
* This class manages the shared strings defined in the associated XML file
|
||||
*
|
||||
* @package Box\Spout\Reader\XLSX\Manager
|
||||
*/
|
||||
class SharedStringsManager
|
||||
{
|
||||
@@ -98,8 +96,8 @@ class SharedStringsManager
|
||||
* The XML file can be really big with sheets containing a lot of data. That is why
|
||||
* we need to use a XML reader that provides streaming like the XMLReader library.
|
||||
*
|
||||
* @return void
|
||||
* @throws \Box\Spout\Common\Exception\IOException If sharedStrings.xml can't be read
|
||||
* @return void
|
||||
*/
|
||||
public function extractSharedStrings()
|
||||
{
|
||||
@@ -125,7 +123,6 @@ class SharedStringsManager
|
||||
}
|
||||
|
||||
$this->cachingStrategy->closeCache();
|
||||
|
||||
} catch (XMLProcessingException $exception) {
|
||||
throw new IOException("The sharedStrings.xml file is invalid and cannot be read. [{$exception->getMessage()}]");
|
||||
}
|
||||
@@ -137,8 +134,8 @@ class SharedStringsManager
|
||||
* Returns the shared strings unique count, as specified in <sst> tag.
|
||||
*
|
||||
* @param \Box\Spout\Reader\Wrapper\XMLReader $xmlReader XMLReader instance
|
||||
* @return int|null Number of unique shared strings in the sharedStrings.xml file
|
||||
* @throws \Box\Spout\Common\Exception\IOException If sharedStrings.xml is invalid and can't be read
|
||||
* @return int|null Number of unique shared strings in the sharedStrings.xml file
|
||||
*/
|
||||
protected function getSharedStringsUniqueCount($xmlReader)
|
||||
{
|
||||
@@ -157,7 +154,7 @@ class SharedStringsManager
|
||||
$uniqueCount = $xmlReader->getAttribute(self::XML_ATTRIBUTE_COUNT);
|
||||
}
|
||||
|
||||
return ($uniqueCount !== null) ? intval($uniqueCount) : null;
|
||||
return ($uniqueCount !== null) ? (int) $uniqueCount : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -210,6 +207,7 @@ class SharedStringsManager
|
||||
protected function shouldExtractTextNodeValue($textNode)
|
||||
{
|
||||
$parentTagName = $textNode->parentNode->localName;
|
||||
|
||||
return ($parentTagName === self::XML_NODE_SI || $parentTagName === self::XML_NODE_R);
|
||||
}
|
||||
|
||||
@@ -222,6 +220,7 @@ class SharedStringsManager
|
||||
protected function shouldPreserveWhitespace($textNode)
|
||||
{
|
||||
$spaceValue = $textNode->getAttribute(self::XML_ATTRIBUTE_XML_SPACE);
|
||||
|
||||
return ($spaceValue === self::XML_ATTRIBUTE_VALUE_PRESERVE);
|
||||
}
|
||||
|
||||
@@ -229,8 +228,8 @@ class SharedStringsManager
|
||||
* Returns the shared string at the given index, using the previously chosen caching strategy.
|
||||
*
|
||||
* @param int $sharedStringIndex Index of the shared string in the sharedStrings.xml file
|
||||
* @return string The shared string at the given index
|
||||
* @throws \Box\Spout\Reader\Exception\SharedStringNotFoundException If no shared string found for the given index
|
||||
* @return string The shared string at the given index
|
||||
*/
|
||||
public function getStringAtIndex($sharedStringIndex)
|
||||
{
|
||||
|
||||
@@ -2,15 +2,12 @@
|
||||
|
||||
namespace Box\Spout\Reader\XLSX\Manager;
|
||||
|
||||
use Box\Spout\Reader\Wrapper\XMLReader;
|
||||
use Box\Spout\Reader\XLSX\Creator\EntityFactory;
|
||||
use Box\Spout\Reader\XLSX\Sheet;
|
||||
|
||||
/**
|
||||
* Class SheetManager
|
||||
* This class manages XLSX sheets
|
||||
*
|
||||
* @package Box\Spout\Reader\XLSX\Manager
|
||||
*/
|
||||
class SheetManager
|
||||
{
|
||||
@@ -55,6 +52,7 @@ class SheetManager
|
||||
* @param \Box\Spout\Reader\XLSX\Manager\SharedStringsManager $sharedStringsManager Manages shared strings
|
||||
* @param \Box\Spout\Common\Helper\Escaper\XLSX $escaper Used to unescape XML data
|
||||
* @param EntityFactory $entityFactory Factory to create entities
|
||||
* @param mixed $sharedStringsManager
|
||||
*/
|
||||
public function __construct($filePath, $optionsManager, $sharedStringsManager, $escaper, $entityFactory)
|
||||
{
|
||||
@@ -85,11 +83,11 @@ class SheetManager
|
||||
// The "workbookView" node is located before "sheet" nodes, ensuring that
|
||||
// the active sheet is known before parsing sheets data.
|
||||
$activeSheetIndex = (int) $xmlReader->getAttribute(self::XML_ATTRIBUTE_ACTIVE_TAB);
|
||||
} else if ($xmlReader->isPositionedOnStartingNode(self::XML_NODE_SHEET)) {
|
||||
} elseif ($xmlReader->isPositionedOnStartingNode(self::XML_NODE_SHEET)) {
|
||||
$isSheetActive = ($sheetIndex === $activeSheetIndex);
|
||||
$sheets[] = $this->getSheetFromSheetXMLNode($xmlReader, $sheetIndex, $isSheetActive);
|
||||
$sheetIndex++;
|
||||
} else if ($xmlReader->isPositionedOnEndingNode(self::XML_NODE_SHEETS)) {
|
||||
} elseif ($xmlReader->isPositionedOnEndingNode(self::XML_NODE_SHEETS)) {
|
||||
// stop reading once all sheets have been read
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -7,8 +7,6 @@ use Box\Spout\Reader\XLSX\Creator\EntityFactory;
|
||||
/**
|
||||
* Class StyleManager
|
||||
* This class manages XLSX styles
|
||||
*
|
||||
* @package Box\Spout\Reader\XLSX\Manager
|
||||
*/
|
||||
class StyleManager
|
||||
{
|
||||
@@ -118,8 +116,7 @@ class StyleManager
|
||||
while ($xmlReader->read()) {
|
||||
if ($xmlReader->isPositionedOnStartingNode(self::XML_NODE_NUM_FMTS)) {
|
||||
$this->extractNumberFormats($xmlReader);
|
||||
|
||||
} else if ($xmlReader->isPositionedOnStartingNode(self::XML_NODE_CELL_XFS)) {
|
||||
} elseif ($xmlReader->isPositionedOnStartingNode(self::XML_NODE_CELL_XFS)) {
|
||||
$this->extractStyleAttributes($xmlReader);
|
||||
}
|
||||
}
|
||||
@@ -140,10 +137,10 @@ class StyleManager
|
||||
{
|
||||
while ($xmlReader->read()) {
|
||||
if ($xmlReader->isPositionedOnStartingNode(self::XML_NODE_NUM_FMT)) {
|
||||
$numFmtId = intval($xmlReader->getAttribute(self::XML_ATTRIBUTE_NUM_FMT_ID));
|
||||
$numFmtId = (int) ($xmlReader->getAttribute(self::XML_ATTRIBUTE_NUM_FMT_ID));
|
||||
$formatCode = $xmlReader->getAttribute(self::XML_ATTRIBUTE_FORMAT_CODE);
|
||||
$this->customNumberFormats[$numFmtId] = $formatCode;
|
||||
} else if ($xmlReader->isPositionedOnEndingNode(self::XML_NODE_NUM_FMTS)) {
|
||||
} elseif ($xmlReader->isPositionedOnEndingNode(self::XML_NODE_NUM_FMTS)) {
|
||||
// Once done reading "numFmts" node's children
|
||||
break;
|
||||
}
|
||||
@@ -163,16 +160,16 @@ class StyleManager
|
||||
while ($xmlReader->read()) {
|
||||
if ($xmlReader->isPositionedOnStartingNode(self::XML_NODE_XF)) {
|
||||
$numFmtId = $xmlReader->getAttribute(self::XML_ATTRIBUTE_NUM_FMT_ID);
|
||||
$normalizedNumFmtId = ($numFmtId !== null) ? intval($numFmtId) : null;
|
||||
$normalizedNumFmtId = ($numFmtId !== null) ? (int) $numFmtId : null;
|
||||
|
||||
$applyNumberFormat = $xmlReader->getAttribute(self::XML_ATTRIBUTE_APPLY_NUMBER_FORMAT);
|
||||
$normalizedApplyNumberFormat = ($applyNumberFormat !== null) ? !!$applyNumberFormat : null;
|
||||
$normalizedApplyNumberFormat = ($applyNumberFormat !== null) ? (bool) $applyNumberFormat : null;
|
||||
|
||||
$this->stylesAttributes[] = [
|
||||
self::XML_ATTRIBUTE_NUM_FMT_ID => $normalizedNumFmtId,
|
||||
self::XML_ATTRIBUTE_NUM_FMT_ID => $normalizedNumFmtId,
|
||||
self::XML_ATTRIBUTE_APPLY_NUMBER_FORMAT => $normalizedApplyNumberFormat,
|
||||
];
|
||||
} else if ($xmlReader->isPositionedOnEndingNode(self::XML_NODE_CELL_XFS)) {
|
||||
} elseif ($xmlReader->isPositionedOnEndingNode(self::XML_NODE_CELL_XFS)) {
|
||||
// Once done reading "cellXfs" node's children
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -14,8 +14,6 @@ use Box\Spout\Reader\XLSX\Creator\ManagerFactory;
|
||||
/**
|
||||
* Class Reader
|
||||
* This class provides support to read data from a XLSX file
|
||||
*
|
||||
* @package Box\Spout\Reader\XLSX
|
||||
*/
|
||||
class Reader extends ReaderAbstract
|
||||
{
|
||||
@@ -31,7 +29,6 @@ class Reader extends ReaderAbstract
|
||||
/** @var SheetIterator To iterator over the XLSX sheets */
|
||||
protected $sheetIterator;
|
||||
|
||||
|
||||
/**
|
||||
* @param OptionsManagerInterface $optionsManager
|
||||
* @param GlobalFunctionsHelper $globalFunctionsHelper
|
||||
@@ -42,8 +39,8 @@ class Reader extends ReaderAbstract
|
||||
OptionsManagerInterface $optionsManager,
|
||||
GlobalFunctionsHelper $globalFunctionsHelper,
|
||||
EntityFactoryInterface $entityFactory,
|
||||
ManagerFactory $managerFactory)
|
||||
{
|
||||
ManagerFactory $managerFactory
|
||||
) {
|
||||
parent::__construct($optionsManager, $globalFunctionsHelper, $entityFactory);
|
||||
$this->managerFactory = $managerFactory;
|
||||
}
|
||||
@@ -55,6 +52,7 @@ class Reader extends ReaderAbstract
|
||||
public function setTempFolder($tempFolder)
|
||||
{
|
||||
$this->optionsManager->setOption(Options::TEMP_FOLDER, $tempFolder);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -74,9 +72,9 @@ class Reader extends ReaderAbstract
|
||||
* and fetches all the available sheets.
|
||||
*
|
||||
* @param string $filePath Path of the file to be read
|
||||
* @return void
|
||||
* @throws \Box\Spout\Common\Exception\IOException If the file at the given path or its content cannot be read
|
||||
* @throws \Box\Spout\Reader\Exception\NoSheetsFoundException If there are no sheets in the file
|
||||
* @return void
|
||||
*/
|
||||
protected function openReader($filePath)
|
||||
{
|
||||
|
||||
@@ -3,20 +3,15 @@
|
||||
namespace Box\Spout\Reader\XLSX;
|
||||
|
||||
use Box\Spout\Common\Exception\IOException;
|
||||
use Box\Spout\Reader\Common\Entity\Options;
|
||||
use Box\Spout\Reader\Common\XMLProcessor;
|
||||
use Box\Spout\Reader\Exception\XMLProcessingException;
|
||||
use Box\Spout\Reader\IteratorInterface;
|
||||
use Box\Spout\Reader\Wrapper\XMLReader;
|
||||
use Box\Spout\Reader\XLSX\Creator\EntityFactory;
|
||||
use Box\Spout\Reader\XLSX\Creator\HelperFactory;
|
||||
use Box\Spout\Reader\XLSX\Helper\CellHelper;
|
||||
use Box\Spout\Reader\Common\XMLProcessor;
|
||||
use Box\Spout\Reader\XLSX\Helper\CellValueFormatter;
|
||||
|
||||
/**
|
||||
* Class RowIterator
|
||||
*
|
||||
* @package Box\Spout\Reader\XLSX
|
||||
*/
|
||||
class RowIterator implements IteratorInterface
|
||||
{
|
||||
@@ -57,7 +52,7 @@ class RowIterator implements IteratorInterface
|
||||
protected $currentlyProcessedRowData = [];
|
||||
|
||||
/** @var array|null Buffer used to store the row data, while checking if there are more rows to read */
|
||||
protected $rowDataBuffer = null;
|
||||
protected $rowDataBuffer;
|
||||
|
||||
/** @var bool Indicates whether all rows have been read */
|
||||
protected $hasReachedEndOfFile = false;
|
||||
@@ -116,10 +111,10 @@ class RowIterator implements IteratorInterface
|
||||
* Rewind the Iterator to the first element.
|
||||
* Initializes the XMLReader object that reads the associated sheet data.
|
||||
* The XMLReader is configured to be safe from billion laughs attack.
|
||||
* @link http://php.net/manual/en/iterator.rewind.php
|
||||
* @see http://php.net/manual/en/iterator.rewind.php
|
||||
*
|
||||
* @return void
|
||||
* @throws \Box\Spout\Common\Exception\IOException If the sheet data XML cannot be read
|
||||
* @return void
|
||||
*/
|
||||
public function rewind()
|
||||
{
|
||||
@@ -141,7 +136,7 @@ class RowIterator implements IteratorInterface
|
||||
|
||||
/**
|
||||
* Checks if current position is valid
|
||||
* @link http://php.net/manual/en/iterator.valid.php
|
||||
* @see http://php.net/manual/en/iterator.valid.php
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -152,11 +147,11 @@ class RowIterator implements IteratorInterface
|
||||
|
||||
/**
|
||||
* Move forward to next element. Reads data describing the next unprocessed row.
|
||||
* @link http://php.net/manual/en/iterator.next.php
|
||||
* @see http://php.net/manual/en/iterator.next.php
|
||||
*
|
||||
* @return void
|
||||
* @throws \Box\Spout\Reader\Exception\SharedStringNotFoundException If a shared string was not found
|
||||
* @throws \Box\Spout\Common\Exception\IOException If unable to read the sheet data XML
|
||||
* @return void
|
||||
*/
|
||||
public function next()
|
||||
{
|
||||
@@ -191,9 +186,9 @@ class RowIterator implements IteratorInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws \Box\Spout\Reader\Exception\SharedStringNotFoundException If a shared string was not found
|
||||
* @throws \Box\Spout\Common\Exception\IOException If unable to read the sheet data XML
|
||||
* @return void
|
||||
*/
|
||||
protected function readDataForNextRow()
|
||||
{
|
||||
@@ -240,7 +235,7 @@ class RowIterator implements IteratorInterface
|
||||
$spans = $xmlReader->getAttribute(self::XML_ATTRIBUTE_SPANS); // returns '1:5' for instance
|
||||
if ($spans) {
|
||||
list(, $numberOfColumnsForRow) = explode(':', $spans);
|
||||
$numberOfColumnsForRow = intval($numberOfColumnsForRow);
|
||||
$numberOfColumnsForRow = (int) $numberOfColumnsForRow;
|
||||
}
|
||||
|
||||
$this->currentlyProcessedRowData = ($numberOfColumnsForRow !== 0) ? array_fill(0, $numberOfColumnsForRow, '') : [];
|
||||
@@ -300,8 +295,8 @@ class RowIterator implements IteratorInterface
|
||||
|
||||
/**
|
||||
* @param \Box\Spout\Reader\Wrapper\XMLReader $xmlReader XMLReader object, positioned on a "<row>" node
|
||||
* @return int Row index
|
||||
* @throws \Box\Spout\Common\Exception\InvalidArgumentException When the given cell index is invalid
|
||||
* @return int Row index
|
||||
*/
|
||||
protected function getRowIndex($xmlReader)
|
||||
{
|
||||
@@ -309,14 +304,14 @@ class RowIterator implements IteratorInterface
|
||||
$currentRowIndex = $xmlReader->getAttribute(self::XML_ATTRIBUTE_ROW_INDEX);
|
||||
|
||||
return ($currentRowIndex !== null) ?
|
||||
intval($currentRowIndex) :
|
||||
(int) $currentRowIndex :
|
||||
$this->lastRowIndexProcessed + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Box\Spout\Reader\Wrapper\XMLReader $xmlReader XMLReader object, positioned on a "<c>" node
|
||||
* @return int Column index
|
||||
* @throws \Box\Spout\Common\Exception\InvalidArgumentException When the given cell index is invalid
|
||||
* @return int Column index
|
||||
*/
|
||||
protected function getColumnIndex($xmlReader)
|
||||
{
|
||||
@@ -350,7 +345,7 @@ class RowIterator implements IteratorInterface
|
||||
|
||||
/**
|
||||
* Return the current element, either an empty row or from the buffer.
|
||||
* @link http://php.net/manual/en/iterator.current.php
|
||||
* @see http://php.net/manual/en/iterator.current.php
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
@@ -375,7 +370,7 @@ class RowIterator implements IteratorInterface
|
||||
|
||||
/**
|
||||
* Return the key of the current element. Here, the row index.
|
||||
* @link http://php.net/manual/en/iterator.key.php
|
||||
* @see http://php.net/manual/en/iterator.key.php
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
@@ -389,7 +384,6 @@ class RowIterator implements IteratorInterface
|
||||
$this->numReadRows;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Cleans up what was created to iterate over the object.
|
||||
*
|
||||
|
||||
@@ -3,13 +3,10 @@
|
||||
namespace Box\Spout\Reader\XLSX;
|
||||
|
||||
use Box\Spout\Reader\SheetInterface;
|
||||
use Box\Spout\Reader\XLSX\Creator\EntityFactory;
|
||||
|
||||
/**
|
||||
* Class Sheet
|
||||
* Represents a sheet within a XLSX file
|
||||
*
|
||||
* @package Box\Spout\Reader\XLSX
|
||||
*/
|
||||
class Sheet implements SheetInterface
|
||||
{
|
||||
|
||||
@@ -2,15 +2,13 @@
|
||||
|
||||
namespace Box\Spout\Reader\XLSX;
|
||||
|
||||
use Box\Spout\Reader\Exception\NoSheetsFoundException;
|
||||
use Box\Spout\Reader\IteratorInterface;
|
||||
use Box\Spout\Reader\XLSX\Manager\SheetManager;
|
||||
use Box\Spout\Reader\Exception\NoSheetsFoundException;
|
||||
|
||||
/**
|
||||
* Class SheetIterator
|
||||
* Iterate over XLSX sheet.
|
||||
*
|
||||
* @package Box\Spout\Reader\XLSX
|
||||
*/
|
||||
class SheetIterator implements IteratorInterface
|
||||
{
|
||||
@@ -36,7 +34,7 @@ class SheetIterator implements IteratorInterface
|
||||
|
||||
/**
|
||||
* Rewind the Iterator to the first element
|
||||
* @link http://php.net/manual/en/iterator.rewind.php
|
||||
* @see http://php.net/manual/en/iterator.rewind.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@@ -47,7 +45,7 @@ class SheetIterator implements IteratorInterface
|
||||
|
||||
/**
|
||||
* Checks if current position is valid
|
||||
* @link http://php.net/manual/en/iterator.valid.php
|
||||
* @see http://php.net/manual/en/iterator.valid.php
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -58,7 +56,7 @@ class SheetIterator implements IteratorInterface
|
||||
|
||||
/**
|
||||
* Move forward to next element
|
||||
* @link http://php.net/manual/en/iterator.next.php
|
||||
* @see http://php.net/manual/en/iterator.next.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@@ -75,7 +73,7 @@ class SheetIterator implements IteratorInterface
|
||||
|
||||
/**
|
||||
* Return the current element
|
||||
* @link http://php.net/manual/en/iterator.current.php
|
||||
* @see http://php.net/manual/en/iterator.current.php
|
||||
*
|
||||
* @return \Box\Spout\Reader\XLSX\Sheet
|
||||
*/
|
||||
@@ -86,7 +84,7 @@ class SheetIterator implements IteratorInterface
|
||||
|
||||
/**
|
||||
* Return the key of the current element
|
||||
* @link http://php.net/manual/en/iterator.key.php
|
||||
* @see http://php.net/manual/en/iterator.key.php
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user