Introduce Managers for readers

Some helper classes were more managers than helpers...
This commit is contained in:
Adrien Loison committed 2017-08-27 03:56:17 +02:00
1 parent 61f2addefa
commit 668c10a30d
19 files changed
+376 -339

No files matched your search

@@ -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 {