Introduce Managers for readers
Some helper classes were more managers than helpers...
This commit is contained in:
1 parent
61f2addefa
commit
668c10a30d
19 files changed
+376
-339
No files matched your search
@@ -4,9 +4,8 @@ namespace Box\Spout\Reader;
|
||||
|
||||
use Box\Spout\Common\Creator\HelperFactory;
|
||||
use Box\Spout\Common\Exception\UnsupportedTypeException;
|
||||
use Box\Spout\Common\Helper\GlobalFunctionsHelper;
|
||||
use Box\Spout\Common\Type;
|
||||
use Box\Spout\Reader\XLSX\Helper\SharedStringsCaching\CachingStrategyFactory;
|
||||
use Box\Spout\Reader\XLSX\Manager\SharedStringsCaching\CachingStrategyFactory;
|
||||
|
||||
/**
|
||||
* Class ReaderFactory
|
||||
@@ -56,12 +55,12 @@ class ReaderFactory
|
||||
private static function getXLSXReader()
|
||||
{
|
||||
$optionsManager = new XLSX\Manager\OptionsManager();
|
||||
$cachingStrategyFactory = new CachingStrategyFactory();
|
||||
$helperFactory = new XLSX\Creator\HelperFactory($cachingStrategyFactory);
|
||||
$entityFactory = new XLSX\Creator\EntityFactory($helperFactory);
|
||||
$helperFactory = new XLSX\Creator\HelperFactory();
|
||||
$managerFactory = new XLSX\Creator\ManagerFactory($helperFactory, new CachingStrategyFactory());
|
||||
$entityFactory = new XLSX\Creator\EntityFactory($managerFactory, $helperFactory);
|
||||
$globalFunctionsHelper = $helperFactory->createGlobalFunctionsHelper();
|
||||
|
||||
return new XLSX\Reader($optionsManager, $globalFunctionsHelper, $entityFactory, $helperFactory);
|
||||
return new XLSX\Reader($optionsManager, $globalFunctionsHelper, $entityFactory, $managerFactory);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,11 +5,12 @@ 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\XLSX\Helper\SharedStringsHelper;
|
||||
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
|
||||
@@ -22,24 +23,29 @@ class EntityFactory implements EntityFactoryInterface
|
||||
/** @var HelperFactory */
|
||||
private $helperFactory;
|
||||
|
||||
/** @var ManagerFactory */
|
||||
private $managerFactory;
|
||||
|
||||
/**
|
||||
* @param ManagerFactory $managerFactory
|
||||
* @param HelperFactory $helperFactory
|
||||
*/
|
||||
public function __construct(HelperFactory $helperFactory)
|
||||
public function __construct(ManagerFactory $managerFactory, HelperFactory $helperFactory)
|
||||
{
|
||||
$this->managerFactory = $managerFactory;
|
||||
$this->helperFactory = $helperFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $filePath Path of the file to be read
|
||||
* @param \Box\Spout\Common\Manager\OptionsManagerInterface $optionsManager Reader's options manager
|
||||
* @param SharedStringsHelper $sharedStringsHelper Helper to work with shared strings
|
||||
* @param SharedStringsManager $sharedStringsManager Manages shared strings
|
||||
* @return SheetIterator
|
||||
*/
|
||||
public function createSheetIterator($filePath, $optionsManager, $sharedStringsHelper)
|
||||
public function createSheetIterator($filePath, $optionsManager, $sharedStringsManager)
|
||||
{
|
||||
$sheetHelper = $this->helperFactory->createSheetHelper($filePath, $optionsManager, $sharedStringsHelper, $this);
|
||||
return new SheetIterator($sheetHelper);
|
||||
$sheetManager = $this->managerFactory->createSheetManager($filePath, $optionsManager, $sharedStringsManager, $this);
|
||||
return new SheetIterator($sheetManager);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,7 +55,7 @@ class EntityFactory implements EntityFactoryInterface
|
||||
* @param string $sheetName Name of the sheet
|
||||
* @param bool $isSheetActive Whether the sheet was defined as active
|
||||
* @param \Box\Spout\Common\Manager\OptionsManagerInterface $optionsManager Reader's options manager
|
||||
* @param SharedStringsHelper $sharedStringsHelper Helper to work with shared strings
|
||||
* @param SharedStringsManager $sharedStringsManager Manages shared strings
|
||||
* @return Sheet
|
||||
*/
|
||||
public function createSheet(
|
||||
@@ -59,9 +65,9 @@ class EntityFactory implements EntityFactoryInterface
|
||||
$sheetName,
|
||||
$isSheetActive,
|
||||
$optionsManager,
|
||||
$sharedStringsHelper)
|
||||
$sharedStringsManager)
|
||||
{
|
||||
$rowIterator = $this->createRowIterator($filePath, $sheetDataXMLFilePath, $optionsManager, $sharedStringsHelper);
|
||||
$rowIterator = $this->createRowIterator($filePath, $sheetDataXMLFilePath, $optionsManager, $sharedStringsManager);
|
||||
return new Sheet($rowIterator, $sheetIndex, $sheetName, $isSheetActive);
|
||||
}
|
||||
|
||||
@@ -69,17 +75,17 @@ class EntityFactory implements EntityFactoryInterface
|
||||
* @param string $filePath Path of the XLSX file being read
|
||||
* @param string $sheetDataXMLFilePath Path of the sheet data XML file as in [Content_Types].xml
|
||||
* @param \Box\Spout\Common\Manager\OptionsManagerInterface $optionsManager Reader's options manager
|
||||
* @param SharedStringsHelper $sharedStringsHelper Helper to work with shared strings
|
||||
* @param SharedStringsManager $sharedStringsManager Manages shared strings
|
||||
* @return RowIterator
|
||||
*/
|
||||
private function createRowIterator($filePath, $sheetDataXMLFilePath, $optionsManager, $sharedStringsHelper)
|
||||
private function createRowIterator($filePath, $sheetDataXMLFilePath, $optionsManager, $sharedStringsManager)
|
||||
{
|
||||
$xmlReader = $this->createXMLReader();
|
||||
$xmlProcessor = $this->createXMLProcessor($xmlReader);
|
||||
|
||||
$styleHelper = $this->helperFactory->createStyleHelper($filePath, $this);
|
||||
$styleManager = $this->managerFactory->createStyleManager($filePath, $this);
|
||||
$shouldFormatDates = $optionsManager->getOption(Options::SHOULD_FORMAT_DATES);
|
||||
$cellValueFormatter = $this->helperFactory->createCellValueFormatter($sharedStringsHelper, $styleHelper, $shouldFormatDates);
|
||||
$cellValueFormatter = $this->helperFactory->createCellValueFormatter($sharedStringsManager, $styleManager, $shouldFormatDates);
|
||||
|
||||
$shouldPreserveEmptyRows = $optionsManager->getOption(Options::SHOULD_PRESERVE_EMPTY_ROWS);
|
||||
|
||||
|
||||
@@ -4,75 +4,30 @@ namespace Box\Spout\Reader\XLSX\Creator;
|
||||
|
||||
use Box\Spout\Common\Helper\Escaper;
|
||||
use Box\Spout\Reader\XLSX\Helper\CellValueFormatter;
|
||||
use Box\Spout\Reader\XLSX\Helper\SharedStringsCaching\CachingStrategyFactory;
|
||||
use Box\Spout\Reader\XLSX\Helper\SharedStringsHelper;
|
||||
use Box\Spout\Reader\XLSX\Helper\SheetHelper;
|
||||
use Box\Spout\Reader\XLSX\Helper\StyleHelper;
|
||||
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 EntityFactory
|
||||
* Class HelperFactory
|
||||
* Factory to create helpers
|
||||
*
|
||||
* @package Box\Spout\Reader\XLSX\Creator
|
||||
*/
|
||||
class HelperFactory extends \Box\Spout\Common\Creator\HelperFactory
|
||||
{
|
||||
/** @var CachingStrategyFactory */
|
||||
private $cachingStrategyFactory;
|
||||
|
||||
/**
|
||||
* @param CachingStrategyFactory $cachingStrategyFactory Factory to create shared strings caching strategies
|
||||
*/
|
||||
public function __construct(CachingStrategyFactory $cachingStrategyFactory)
|
||||
{
|
||||
$this->cachingStrategyFactory = $cachingStrategyFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $filePath Path of the XLSX file being read
|
||||
* @param string $tempFolder Temporary folder where the temporary files to store shared strings will be stored
|
||||
* @param EntityFactory $entityFactory Factory to create entities
|
||||
* @return SharedStringsHelper
|
||||
*/
|
||||
public function createSharedStringsHelper($filePath, $tempFolder, $entityFactory)
|
||||
{
|
||||
return new SharedStringsHelper($filePath, $tempFolder, $entityFactory, $this, $this->cachingStrategyFactory);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $filePath Path of the XLSX file being read
|
||||
* @param \Box\Spout\Common\Manager\OptionsManagerInterface $optionsManager Reader's options manager
|
||||
* @param \Box\Spout\Reader\XLSX\Helper\SharedStringsHelper Helper to work with shared strings
|
||||
* @param EntityFactory $entityFactory Factory to create entities
|
||||
* @return SheetHelper
|
||||
*/
|
||||
public function createSheetHelper($filePath, $optionsManager, $sharedStringsHelper, $entityFactory)
|
||||
{
|
||||
$escaper = $this->createStringsEscaper();
|
||||
return new SheetHelper($filePath, $optionsManager, $sharedStringsHelper, $escaper, $entityFactory);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $filePath Path of the XLSX file being read
|
||||
* @param EntityFactory $entityFactory Factory to create entities
|
||||
* @return StyleHelper
|
||||
*/
|
||||
public function createStyleHelper($filePath, $entityFactory)
|
||||
{
|
||||
return new StyleHelper($filePath, $entityFactory);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SharedStringsHelper $sharedStringsHelper Helper to work with shared strings
|
||||
* @param StyleHelper $styleHelper Helper to work with styles
|
||||
* @param SharedStringsManager $sharedStringsManager Manages shared strings
|
||||
* @param StyleManager $styleManager Manages styles
|
||||
* @param bool $shouldFormatDates Whether date/time values should be returned as PHP objects or be formatted as strings
|
||||
* @return CellValueFormatter
|
||||
*/
|
||||
public function createCellValueFormatter($sharedStringsHelper, $styleHelper, $shouldFormatDates)
|
||||
public function createCellValueFormatter($sharedStringsManager, $styleManager, $shouldFormatDates)
|
||||
{
|
||||
$escaper = $this->createStringsEscaper();
|
||||
return new CellValueFormatter($sharedStringsHelper, $styleHelper, $shouldFormatDates, $escaper);
|
||||
return new CellValueFormatter($sharedStringsManager, $styleManager, $shouldFormatDates, $escaper);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace Box\Spout\Reader\XLSX\Creator;
|
||||
|
||||
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 ManagerFactory
|
||||
* Factory to create managers
|
||||
*
|
||||
* @package Box\Spout\Reader\XLSX\Creator
|
||||
*/
|
||||
class ManagerFactory
|
||||
{
|
||||
/** @var HelperFactory */
|
||||
private $helperFactory;
|
||||
|
||||
/** @var CachingStrategyFactory */
|
||||
private $cachingStrategyFactory;
|
||||
|
||||
/**
|
||||
* @param HelperFactory $helperFactory Factory to create helpers
|
||||
* @param CachingStrategyFactory $cachingStrategyFactory Factory to create shared strings caching strategies
|
||||
*/
|
||||
public function __construct(HelperFactory $helperFactory, CachingStrategyFactory $cachingStrategyFactory)
|
||||
{
|
||||
$this->helperFactory = $helperFactory;
|
||||
$this->cachingStrategyFactory = $cachingStrategyFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $filePath Path of the XLSX file being read
|
||||
* @param string $tempFolder Temporary folder where the temporary files to store shared strings will be stored
|
||||
* @param EntityFactory $entityFactory Factory to create entities
|
||||
* @return SharedStringsManager
|
||||
*/
|
||||
public function createSharedStringsManager($filePath, $tempFolder, $entityFactory)
|
||||
{
|
||||
return new SharedStringsManager($filePath, $tempFolder, $entityFactory, $this->helperFactory, $this->cachingStrategyFactory);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $filePath Path of the XLSX file being read
|
||||
* @param \Box\Spout\Common\Manager\OptionsManagerInterface $optionsManager Reader's options manager
|
||||
* @param \Box\Spout\Reader\XLSX\Manager\SharedStringsManager $sharedStringsManager Manages shared strings
|
||||
* @param EntityFactory $entityFactory Factory to create entities
|
||||
* @return SheetManager
|
||||
*/
|
||||
public function createSheetManager($filePath, $optionsManager, $sharedStringsManager, $entityFactory)
|
||||
{
|
||||
$escaper = $this->helperFactory->createStringsEscaper();
|
||||
return new SheetManager($filePath, $optionsManager, $sharedStringsManager, $escaper, $entityFactory);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $filePath Path of the XLSX file being read
|
||||
* @param EntityFactory $entityFactory Factory to create entities
|
||||
* @return StyleManager
|
||||
*/
|
||||
public function createStyleManager($filePath, $entityFactory)
|
||||
{
|
||||
return new StyleManager($filePath, $entityFactory);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,9 @@
|
||||
|
||||
namespace Box\Spout\Reader\XLSX\Helper;
|
||||
|
||||
use Box\Spout\Reader\XLSX\Manager\SharedStringsManager;
|
||||
use Box\Spout\Reader\XLSX\Manager\StyleManager;
|
||||
|
||||
/**
|
||||
* Class CellValueFormatter
|
||||
* This class provides helper functions to format cell values
|
||||
@@ -38,11 +41,11 @@ class CellValueFormatter
|
||||
*/
|
||||
const ERRONEOUS_EXCEL_LEAP_YEAR_DAY = 60;
|
||||
|
||||
/** @var SharedStringsHelper Helper to work with shared strings */
|
||||
protected $sharedStringsHelper;
|
||||
/** @var SharedStringsManager Manages shared strings */
|
||||
protected $sharedStringsManager;
|
||||
|
||||
/** @var StyleHelper Helper to work with styles */
|
||||
protected $styleHelper;
|
||||
/** @var StyleManager Manages styles */
|
||||
protected $styleManager;
|
||||
|
||||
/** @var bool Whether date/time values should be returned as PHP objects or be formatted as strings */
|
||||
protected $shouldFormatDates;
|
||||
@@ -51,15 +54,15 @@ class CellValueFormatter
|
||||
protected $escaper;
|
||||
|
||||
/**
|
||||
* @param SharedStringsHelper $sharedStringsHelper Helper to work with shared strings
|
||||
* @param StyleHelper $styleHelper Helper to work with styles
|
||||
* @param SharedStringsManager $sharedStringsManager Manages shared strings
|
||||
* @param StyleManager $styleManager Manages styles
|
||||
* @param bool $shouldFormatDates Whether date/time values should be returned as PHP objects or be formatted as strings
|
||||
* @param \Box\Spout\Common\Helper\Escaper\XLSX $escaper Used to unescape XML data
|
||||
*/
|
||||
public function __construct($sharedStringsHelper, $styleHelper, $shouldFormatDates, $escaper)
|
||||
public function __construct($sharedStringsManager, $styleManager, $shouldFormatDates, $escaper)
|
||||
{
|
||||
$this->sharedStringsHelper = $sharedStringsHelper;
|
||||
$this->styleHelper = $styleHelper;
|
||||
$this->sharedStringsManager = $sharedStringsManager;
|
||||
$this->styleManager = $styleManager;
|
||||
$this->shouldFormatDates = $shouldFormatDates;
|
||||
$this->escaper = $escaper;
|
||||
}
|
||||
@@ -139,7 +142,7 @@ class CellValueFormatter
|
||||
// shared strings are formatted this way:
|
||||
// <c r="A1" t="s"><v>[SHARED_STRING_INDEX]</v></c>
|
||||
$sharedStringIndex = intval($nodeValue);
|
||||
$escapedCellValue = $this->sharedStringsHelper->getStringAtIndex($sharedStringIndex);
|
||||
$escapedCellValue = $this->sharedStringsManager->getStringAtIndex($sharedStringIndex);
|
||||
$cellValue = $this->escaper->unescape($escapedCellValue);
|
||||
return $cellValue;
|
||||
}
|
||||
@@ -169,7 +172,7 @@ class CellValueFormatter
|
||||
{
|
||||
// Numeric values can represent numbers as well as timestamps.
|
||||
// We need to look at the style of the cell to determine whether it is one or the other.
|
||||
$shouldFormatAsDate = $this->styleHelper->shouldFormatNumericValueAsDate($cellStyleId);
|
||||
$shouldFormatAsDate = $this->styleManager->shouldFormatNumericValueAsDate($cellStyleId);
|
||||
|
||||
if ($shouldFormatAsDate) {
|
||||
return $this->formatExcelTimestampValue(floatval($nodeValue), $cellStyleId);
|
||||
@@ -227,7 +230,7 @@ class CellValueFormatter
|
||||
$dateObj->setTime($hours, $minutes, $seconds);
|
||||
|
||||
if ($this->shouldFormatDates) {
|
||||
$styleNumberFormatCode = $this->styleHelper->getNumberFormatCode($cellStyleId);
|
||||
$styleNumberFormatCode = $this->styleManager->getNumberFormatCode($cellStyleId);
|
||||
$phpDateFormat = DateFormatHelper::toPHPDateFormat($styleNumberFormatCode);
|
||||
return $dateObj->format($phpDateFormat);
|
||||
} else {
|
||||
@@ -256,7 +259,7 @@ class CellValueFormatter
|
||||
$dateObj->modify('+' . $secondsRemainder . 'seconds');
|
||||
|
||||
if ($this->shouldFormatDates) {
|
||||
$styleNumberFormatCode = $this->styleHelper->getNumberFormatCode($cellStyleId);
|
||||
$styleNumberFormatCode = $this->styleManager->getNumberFormatCode($cellStyleId);
|
||||
$phpDateFormat = DateFormatHelper::toPHPDateFormat($styleNumberFormatCode);
|
||||
return $dateObj->format($phpDateFormat);
|
||||
} else {
|
||||
|
||||
+3
-2
@@ -1,12 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Box\Spout\Reader\XLSX\Helper\SharedStringsCaching;
|
||||
namespace Box\Spout\Reader\XLSX\Manager\SharedStringsCaching;
|
||||
|
||||
use Box\Spout\Reader\XLSX\Creator\HelperFactory;
|
||||
|
||||
/**
|
||||
* Class CachingStrategyFactory
|
||||
*
|
||||
* @package Box\Spout\Reader\XLSX\Helper\SharedStringsCaching
|
||||
* @package Box\Spout\Reader\XLSX\Manager\SharedStringsCaching
|
||||
*/
|
||||
class CachingStrategyFactory
|
||||
{
|
||||
+2
-2
@@ -1,11 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Box\Spout\Reader\XLSX\Helper\SharedStringsCaching;
|
||||
namespace Box\Spout\Reader\XLSX\Manager\SharedStringsCaching;
|
||||
|
||||
/**
|
||||
* Interface CachingStrategyInterface
|
||||
*
|
||||
* @package Box\Spout\Reader\XLSX\Helper\SharedStringsCaching
|
||||
* @package Box\Spout\Reader\XLSX\Manager\SharedStringsCaching
|
||||
*/
|
||||
interface CachingStrategyInterface
|
||||
{
|
||||
+2
-4
@@ -1,9 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Box\Spout\Reader\XLSX\Helper\SharedStringsCaching;
|
||||
namespace Box\Spout\Reader\XLSX\Manager\SharedStringsCaching;
|
||||
|
||||
use Box\Spout\Common\Helper\FileSystemHelper;
|
||||
use Box\Spout\Common\Helper\GlobalFunctionsHelper;
|
||||
use Box\Spout\Reader\Exception\SharedStringNotFoundException;
|
||||
use Box\Spout\Reader\XLSX\Creator\HelperFactory;
|
||||
|
||||
@@ -14,7 +12,7 @@ use Box\Spout\Reader\XLSX\Creator\HelperFactory;
|
||||
* 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\Helper\SharedStringsCaching
|
||||
* @package Box\Spout\Reader\XLSX\Manager\SharedStringsCaching
|
||||
*/
|
||||
class FileBasedStrategy implements CachingStrategyInterface
|
||||
{
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Box\Spout\Reader\XLSX\Helper\SharedStringsCaching;
|
||||
namespace Box\Spout\Reader\XLSX\Manager\SharedStringsCaching;
|
||||
|
||||
use Box\Spout\Reader\Exception\SharedStringNotFoundException;
|
||||
|
||||
@@ -10,7 +10,7 @@ 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\Helper\SharedStringsCaching
|
||||
* @package Box\Spout\Reader\XLSX\Manager\SharedStringsCaching
|
||||
*/
|
||||
class InMemoryStrategy implements CachingStrategyInterface
|
||||
{
|
||||
+7
-7
@@ -1,22 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Box\Spout\Reader\XLSX\Helper;
|
||||
namespace Box\Spout\Reader\XLSX\Manager;
|
||||
|
||||
use Box\Spout\Common\Exception\IOException;
|
||||
use Box\Spout\Reader\Exception\XMLProcessingException;
|
||||
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\SharedStringsCaching\CachingStrategyFactory;
|
||||
use Box\Spout\Reader\XLSX\Helper\SharedStringsCaching\CachingStrategyInterface;
|
||||
use Box\Spout\Reader\XLSX\Manager\SharedStringsCaching\CachingStrategyFactory;
|
||||
use Box\Spout\Reader\XLSX\Manager\SharedStringsCaching\CachingStrategyInterface;
|
||||
|
||||
/**
|
||||
* Class SharedStringsHelper
|
||||
* This class provides helper functions for reading sharedStrings XML file
|
||||
* Class SharedStringsManager
|
||||
* This class manages the shared strings defined in the associated XML file
|
||||
*
|
||||
* @package Box\Spout\Reader\XLSX\Helper
|
||||
* @package Box\Spout\Reader\XLSX\Manager
|
||||
*/
|
||||
class SharedStringsHelper
|
||||
class SharedStringsManager
|
||||
{
|
||||
/** Path of sharedStrings XML file inside the XLSX file */
|
||||
const SHARED_STRINGS_XML_FILE_PATH = 'xl/sharedStrings.xml';
|
||||
+11
-11
@@ -1,18 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Box\Spout\Reader\XLSX\Helper;
|
||||
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 SheetHelper
|
||||
* This class provides helper functions related to XLSX sheets
|
||||
* Class SheetManager
|
||||
* This class manages XLSX sheets
|
||||
*
|
||||
* @package Box\Spout\Reader\XLSX\Helper
|
||||
* @package Box\Spout\Reader\XLSX\Manager
|
||||
*/
|
||||
class SheetHelper
|
||||
class SheetManager
|
||||
{
|
||||
/** Paths of XML files relative to the XLSX file root */
|
||||
const WORKBOOK_XML_RELS_FILE_PATH = 'xl/_rels/workbook.xml.rels';
|
||||
@@ -37,8 +37,8 @@ class SheetHelper
|
||||
/** @var \Box\Spout\Common\Manager\OptionsManagerInterface Reader's options manager */
|
||||
protected $optionsManager;
|
||||
|
||||
/** @var \Box\Spout\Reader\XLSX\Helper\SharedStringsHelper Helper to work with shared strings */
|
||||
protected $sharedStringsHelper;
|
||||
/** @var \Box\Spout\Reader\XLSX\Manager\SharedStringsManager Manages shared strings */
|
||||
protected $sharedStringsManager;
|
||||
|
||||
/** @var \Box\Spout\Common\Helper\GlobalFunctionsHelper Helper to work with global functions */
|
||||
protected $globalFunctionsHelper;
|
||||
@@ -52,15 +52,15 @@ class SheetHelper
|
||||
/**
|
||||
* @param string $filePath Path of the XLSX file being read
|
||||
* @param \Box\Spout\Common\Manager\OptionsManagerInterface $optionsManager Reader's options manager
|
||||
* @param \Box\Spout\Reader\XLSX\Helper\SharedStringsHelper Helper to work with shared strings
|
||||
* @param \Box\Spout\Reader\XLSX\Manager\SharedStringsManager Manages shared strings
|
||||
* @param \Box\Spout\Common\Helper\Escaper\XLSX $escaper Used to unescape XML data
|
||||
* @param EntityFactory $entityFactory Factory to create entities
|
||||
*/
|
||||
public function __construct($filePath, $optionsManager, $sharedStringsHelper, $escaper, $entityFactory)
|
||||
public function __construct($filePath, $optionsManager, $sharedStringsManager, $escaper, $entityFactory)
|
||||
{
|
||||
$this->filePath = $filePath;
|
||||
$this->optionsManager = $optionsManager;
|
||||
$this->sharedStringsHelper = $sharedStringsHelper;
|
||||
$this->sharedStringsManager = $sharedStringsManager;
|
||||
$this->escaper = $escaper;
|
||||
$this->entityFactory = $entityFactory;
|
||||
}
|
||||
@@ -126,7 +126,7 @@ class SheetHelper
|
||||
$sheetName,
|
||||
$isSheetActive,
|
||||
$this->optionsManager,
|
||||
$this->sharedStringsHelper
|
||||
$this->sharedStringsManager
|
||||
);
|
||||
}
|
||||
|
||||
+5
-5
@@ -1,16 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Box\Spout\Reader\XLSX\Helper;
|
||||
namespace Box\Spout\Reader\XLSX\Manager;
|
||||
|
||||
use Box\Spout\Reader\XLSX\Creator\EntityFactory;
|
||||
|
||||
/**
|
||||
* Class StyleHelper
|
||||
* This class provides helper functions related to XLSX styles
|
||||
* Class StyleManager
|
||||
* This class manages XLSX styles
|
||||
*
|
||||
* @package Box\Spout\Reader\XLSX\Helper
|
||||
* @package Box\Spout\Reader\XLSX\Manager
|
||||
*/
|
||||
class StyleHelper
|
||||
class StyleManager
|
||||
{
|
||||
/** Paths of XML files relative to the XLSX file root */
|
||||
const STYLES_XML_FILE_PATH = 'xl/styles.xml';
|
||||
@@ -9,7 +9,7 @@ use Box\Spout\Reader\Common\Creator\EntityFactoryInterface;
|
||||
use Box\Spout\Reader\Common\Entity\Options;
|
||||
use Box\Spout\Reader\ReaderAbstract;
|
||||
use Box\Spout\Reader\XLSX\Creator\EntityFactory;
|
||||
use Box\Spout\Reader\XLSX\Creator\HelperFactory;
|
||||
use Box\Spout\Reader\XLSX\Creator\ManagerFactory;
|
||||
|
||||
/**
|
||||
* Class Reader
|
||||
@@ -19,14 +19,14 @@ use Box\Spout\Reader\XLSX\Creator\HelperFactory;
|
||||
*/
|
||||
class Reader extends ReaderAbstract
|
||||
{
|
||||
/** @var HelperFactory */
|
||||
protected $helperFactory;
|
||||
/** @var ManagerFactory */
|
||||
protected $managerFactory;
|
||||
|
||||
/** @var \ZipArchive */
|
||||
protected $zip;
|
||||
|
||||
/** @var \Box\Spout\Reader\XLSX\Helper\SharedStringsHelper Helper to work with shared strings */
|
||||
protected $sharedStringsHelper;
|
||||
/** @var \Box\Spout\Reader\XLSX\Manager\SharedStringsManager Manages shared strings */
|
||||
protected $sharedStringsManager;
|
||||
|
||||
/** @var SheetIterator To iterator over the XLSX sheets */
|
||||
protected $sheetIterator;
|
||||
@@ -36,16 +36,16 @@ class Reader extends ReaderAbstract
|
||||
* @param OptionsManagerInterface $optionsManager
|
||||
* @param GlobalFunctionsHelper $globalFunctionsHelper
|
||||
* @param EntityFactoryInterface $entityFactory
|
||||
* @param HelperFactory $helperFactory
|
||||
* @param ManagerFactory $managerFactory
|
||||
*/
|
||||
public function __construct(
|
||||
OptionsManagerInterface $optionsManager,
|
||||
GlobalFunctionsHelper $globalFunctionsHelper,
|
||||
EntityFactoryInterface $entityFactory,
|
||||
HelperFactory $helperFactory)
|
||||
ManagerFactory $managerFactory)
|
||||
{
|
||||
parent::__construct($optionsManager, $globalFunctionsHelper, $entityFactory);
|
||||
$this->helperFactory = $helperFactory;
|
||||
$this->managerFactory = $managerFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,14 +87,14 @@ class Reader extends ReaderAbstract
|
||||
|
||||
if ($this->zip->open($filePath) === true) {
|
||||
$tempFolder = $this->optionsManager->getOption(Options::TEMP_FOLDER);
|
||||
$this->sharedStringsHelper = $this->helperFactory->createSharedStringsHelper($filePath, $tempFolder, $entityFactory);
|
||||
$this->sharedStringsManager = $this->managerFactory->createSharedStringsManager($filePath, $tempFolder, $entityFactory);
|
||||
|
||||
if ($this->sharedStringsHelper->hasSharedStrings()) {
|
||||
if ($this->sharedStringsManager->hasSharedStrings()) {
|
||||
// Extracts all the strings from the sheets for easy access in the future
|
||||
$this->sharedStringsHelper->extractSharedStrings();
|
||||
$this->sharedStringsManager->extractSharedStrings();
|
||||
}
|
||||
|
||||
$this->sheetIterator = $entityFactory->createSheetIterator($filePath, $this->optionsManager, $this->sharedStringsHelper, $this->globalFunctionsHelper);
|
||||
$this->sheetIterator = $entityFactory->createSheetIterator($filePath, $this->optionsManager, $this->sharedStringsManager, $this->globalFunctionsHelper);
|
||||
} else {
|
||||
throw new IOException("Could not open $filePath for reading.");
|
||||
}
|
||||
@@ -121,8 +121,8 @@ class Reader extends ReaderAbstract
|
||||
$this->zip->close();
|
||||
}
|
||||
|
||||
if ($this->sharedStringsHelper) {
|
||||
$this->sharedStringsHelper->cleanup();
|
||||
if ($this->sharedStringsManager) {
|
||||
$this->sharedStringsManager->cleanup();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,9 +3,7 @@
|
||||
namespace Box\Spout\Reader\XLSX;
|
||||
|
||||
use Box\Spout\Reader\IteratorInterface;
|
||||
use Box\Spout\Reader\XLSX\Creator\EntityFactory;
|
||||
use Box\Spout\Reader\XLSX\Creator\HelperFactory;
|
||||
use Box\Spout\Reader\XLSX\Helper\SheetHelper;
|
||||
use Box\Spout\Reader\XLSX\Manager\SheetManager;
|
||||
use Box\Spout\Reader\Exception\NoSheetsFoundException;
|
||||
|
||||
/**
|
||||
@@ -23,13 +21,13 @@ class SheetIterator implements IteratorInterface
|
||||
protected $currentSheetIndex;
|
||||
|
||||
/**
|
||||
* @param SheetHelper $sheetHelper Helper to work with sheets
|
||||
* @param SheetManager $sheetManager Manages sheets
|
||||
* @throws \Box\Spout\Reader\Exception\NoSheetsFoundException If there are no sheets in the file
|
||||
*/
|
||||
public function __construct($sheetHelper)
|
||||
public function __construct($sheetManager)
|
||||
{
|
||||
// Fetch all available sheets
|
||||
$this->sheets = $sheetHelper->getSheets();
|
||||
$this->sheets = $sheetManager->getSheets();
|
||||
|
||||
if (count($this->sheets) === 0) {
|
||||
throw new NoSheetsFoundException('The file must contain at least one sheet.');
|
||||
|
||||
Reference in new issue
Block a user