Skip to content

Commit aeb3775

Browse files
committed
A Little Less Hideous, A Little More Flexible
1 parent 8fe8bd5 commit aeb3775

2 files changed

Lines changed: 19 additions & 11 deletions

File tree

src/PhpSpreadsheet/Reader/Xlsx.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -901,10 +901,13 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet
901901
$dir,
902902
$richData,
903903
$docSheet,
904-
"$dir/$fileWorksheet",
905-
$mainNS,
906904
$sharedStrings,
907-
$styles
905+
$styles,
906+
[
907+
// this array can be expanded with additional entries to make it easier to extend
908+
'mainNS' => $mainNS,
909+
'fileWorksheetPath' => "$dir/$fileWorksheet",
910+
],
908911
);
909912

910913
$docSheet->setSelectedCells($holdSelectedCells);
@@ -1893,21 +1896,19 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet
18931896
/**
18941897
* @param string[][] $richData
18951898
* @param Worksheet $docSheet the worksheet to populate
1896-
* @param string $fileWorksheetPath path to worksheet XML within the zip
1897-
* @param string $mainNS the main spreadsheetml namespace
18981899
* @param array<int, mixed> $sharedStrings shared string table
18991900
* @param object[] $styles style objects array
1901+
* @param mixed[] $extraParameters maybe make it a little easier to extend
19001902
*/
19011903
protected function loadSheetData(
19021904
?SimpleXMLElement $xmlSheetNS,
19031905
string $filename,
19041906
string $dir,
19051907
array $richData,
19061908
Worksheet $docSheet,
1907-
string $fileWorksheetPath,
1908-
string $mainNS,
19091909
array $sharedStrings,
19101910
array $styles,
1911+
array $extraParameters = [],
19111912
): void {
19121913
if (!($xmlSheetNS && $xmlSheetNS->sheetData && $xmlSheetNS->sheetData->row)) {
19131914
return; // @codeCoverageIgnore

tests/Benchmark/XlsxStreamingReadClass.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,29 @@ class XlsxStreamingReadClass extends Xlsx
1919
*
2020
* @param string[][] $richData
2121
* @param Worksheet $docSheet the worksheet to populate
22-
* @param string $fileWorksheetPath path to worksheet XML within the zip
23-
* @param string $mainNS the main spreadsheetml namespace
2422
* @param array<int, mixed> $sharedStrings shared string table
2523
* @param object[] $styles style objects array
24+
* @param mixed[] $extraParameters maybe make it a little easier to extend
2625
*/
2726
protected function loadSheetData(
2827
?SimpleXMLElement $xmlSheetNS,
2928
string $filename,
3029
string $dir,
3130
array $richData,
3231
Worksheet $docSheet,
33-
string $fileWorksheetPath,
34-
string $mainNS,
3532
array $sharedStrings,
3633
array $styles,
34+
array $extraParameters = [],
3735
): void {
36+
if (!isset($extraParameters['mainNS'], $extraParameters['fileWorksheetPath'])) {
37+
parent::loadSheetData($xmlSheetNS, $filename, $dir, $richData, $docSheet, $sharedStrings, $styles); // @codeCoverageIgnore
38+
39+
return; // @codeCoverageIgnore
40+
}
41+
/** @var string */
42+
$fileWorksheetPath = $extraParameters['fileWorksheetPath']; // path to worksheet Xml within zip
43+
/** @var string */
44+
$mainNS = $extraParameters['mainNS']; // main spreadsheet namespace
3845
$xmlContent = $this->getFromZipArchive($this->zip, $fileWorksheetPath);
3946
if ($xmlContent === '') {
4047
return; // @codeCoverageIgnore

0 commit comments

Comments
 (0)