Fix tests on PHP 5.6

This commit is contained in:
Adrien Crivelli 2018-05-12 22:00:29 +09:00
parent 275c35c877
commit d7751afbec
No known key found for this signature in database
GPG Key ID: B182FD79DC6DE92E
5 changed files with 33 additions and 26 deletions

View File

@ -298,13 +298,14 @@ class Xlsx extends BaseWriter
// Add unparsedLoadedData // Add unparsedLoadedData
$sheetCodeName = $this->spreadSheet->getSheet($i)->getCodeName(); $sheetCodeName = $this->spreadSheet->getSheet($i)->getCodeName();
if (isset($this->spreadSheet->getUnparsedLoadedData()['sheets'][$sheetCodeName]['ctrlProps'])) { $unparsedLoadedData = $this->spreadSheet->getUnparsedLoadedData();
foreach ($this->spreadSheet->getUnparsedLoadedData()['sheets'][$sheetCodeName]['ctrlProps'] as $ctrlProp) { if (isset($unparsedLoadedData['sheets'][$sheetCodeName]['ctrlProps'])) {
foreach ($unparsedLoadedData['sheets'][$sheetCodeName]['ctrlProps'] as $ctrlProp) {
$zip->addFromString($ctrlProp['filePath'], $ctrlProp['content']); $zip->addFromString($ctrlProp['filePath'], $ctrlProp['content']);
} }
} }
if (isset($this->spreadSheet->getUnparsedLoadedData()['sheets'][$sheetCodeName]['printerSettings'])) { if (isset($unparsedLoadedData['sheets'][$sheetCodeName]['printerSettings'])) {
foreach ($this->spreadSheet->getUnparsedLoadedData()['sheets'][$sheetCodeName]['printerSettings'] as $ctrlProp) { foreach ($unparsedLoadedData['sheets'][$sheetCodeName]['printerSettings'] as $ctrlProp) {
$zip->addFromString($ctrlProp['filePath'], $ctrlProp['content']); $zip->addFromString($ctrlProp['filePath'], $ctrlProp['content']);
} }
} }
@ -322,7 +323,7 @@ class Xlsx extends BaseWriter
// Drawings // Drawings
$zip->addFromString('xl/drawings/drawing' . ($i + 1) . '.xml', $this->getWriterPart('Drawing')->writeDrawings($this->spreadSheet->getSheet($i), $this->includeCharts)); $zip->addFromString('xl/drawings/drawing' . ($i + 1) . '.xml', $this->getWriterPart('Drawing')->writeDrawings($this->spreadSheet->getSheet($i), $this->includeCharts));
} elseif (isset($this->spreadSheet->getUnparsedLoadedData()['sheets'][$sheetCodeName]['drawingAlternateContents'])) { } elseif (isset($unparsedLoadedData['sheets'][$sheetCodeName]['drawingAlternateContents'])) {
// Drawings // Drawings
$zip->addFromString('xl/drawings/drawing' . ($i + 1) . '.xml', $this->getWriterPart('Drawing')->writeDrawings($this->spreadSheet->getSheet($i), $this->includeCharts)); $zip->addFromString('xl/drawings/drawing' . ($i + 1) . '.xml', $this->getWriterPart('Drawing')->writeDrawings($this->spreadSheet->getSheet($i), $this->includeCharts));
} }
@ -337,8 +338,8 @@ class Xlsx extends BaseWriter
} }
// Add unparsed relationship parts // Add unparsed relationship parts
if (isset($this->spreadSheet->getUnparsedLoadedData()['sheets'][$this->spreadSheet->getSheet($i)->getCodeName()]['vmlDrawings'])) { if (isset($unparsedLoadedData['sheets'][$this->spreadSheet->getSheet($i)->getCodeName()]['vmlDrawings'])) {
foreach ($this->spreadSheet->getUnparsedLoadedData()['sheets'][$this->spreadSheet->getSheet($i)->getCodeName()]['vmlDrawings'] as $vmlDrawing) { foreach ($unparsedLoadedData['sheets'][$this->spreadSheet->getSheet($i)->getCodeName()]['vmlDrawings'] as $vmlDrawing) {
$zip->addFromString($vmlDrawing['filePath'], $vmlDrawing['content']); $zip->addFromString($vmlDrawing['filePath'], $vmlDrawing['content']);
} }
} }

View File

@ -89,12 +89,13 @@ class ContentTypes extends WriterPart
$this->writeOverrideContentType($objWriter, '/xl/sharedStrings.xml', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml'); $this->writeOverrideContentType($objWriter, '/xl/sharedStrings.xml', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml');
// Add worksheet relationship content types // Add worksheet relationship content types
$unparsedLoadedData = $spreadsheet->getUnparsedLoadedData();
$chart = 1; $chart = 1;
for ($i = 0; $i < $sheetCount; ++$i) { for ($i = 0; $i < $sheetCount; ++$i) {
$drawings = $spreadsheet->getSheet($i)->getDrawingCollection(); $drawings = $spreadsheet->getSheet($i)->getDrawingCollection();
$drawingCount = count($drawings); $drawingCount = count($drawings);
$chartCount = ($includeCharts) ? $spreadsheet->getSheet($i)->getChartCount() : 0; $chartCount = ($includeCharts) ? $spreadsheet->getSheet($i)->getChartCount() : 0;
$hasUnparsedDrawing = isset($spreadsheet->getUnparsedLoadedData()['sheets'][$spreadsheet->getSheet($i)->getCodeName()]['drawingOriginalIds']); $hasUnparsedDrawing = isset($unparsedLoadedData['sheets'][$spreadsheet->getSheet($i)->getCodeName()]['drawingOriginalIds']);
// We need a drawing relationship for the worksheet if we have either drawings or charts // We need a drawing relationship for the worksheet if we have either drawings or charts
if (($drawingCount > 0) || ($chartCount > 0) || $hasUnparsedDrawing) { if (($drawingCount > 0) || ($chartCount > 0) || $hasUnparsedDrawing) {
@ -163,15 +164,15 @@ class ContentTypes extends WriterPart
} }
// unparsed defaults // unparsed defaults
if (isset($spreadsheet->getUnparsedLoadedData()['default_content_types'])) { if (isset($unparsedLoadedData['default_content_types'])) {
foreach ($spreadsheet->getUnparsedLoadedData()['default_content_types'] as $extName => $contentType) { foreach ($unparsedLoadedData['default_content_types'] as $extName => $contentType) {
$this->writeDefaultContentType($objWriter, $extName, $contentType); $this->writeDefaultContentType($objWriter, $extName, $contentType);
} }
} }
// unparsed overrides // unparsed overrides
if (isset($spreadsheet->getUnparsedLoadedData()['override_content_types'])) { if (isset($unparsedLoadedData['override_content_types'])) {
foreach ($spreadsheet->getUnparsedLoadedData()['override_content_types'] as $partName => $overrideType) { foreach ($unparsedLoadedData['override_content_types'] as $partName => $overrideType) {
$this->writeOverrideContentType($objWriter, $partName, $overrideType); $this->writeOverrideContentType($objWriter, $partName, $overrideType);
} }
} }

View File

@ -60,8 +60,9 @@ class Drawing extends WriterPart
} }
// unparsed AlternateContent // unparsed AlternateContent
if (isset($pWorksheet->getParent()->getUnparsedLoadedData()['sheets'][$pWorksheet->getCodeName()]['drawingAlternateContents'])) { $unparsedLoadedData = $pWorksheet->getParent()->getUnparsedLoadedData();
foreach ($pWorksheet->getParent()->getUnparsedLoadedData()['sheets'][$pWorksheet->getCodeName()]['drawingAlternateContents'] as $drawingAlternateContent) { if (isset($unparsedLoadedData['sheets'][$pWorksheet->getCodeName()]['drawingAlternateContents'])) {
foreach ($unparsedLoadedData['sheets'][$pWorksheet->getCodeName()]['drawingAlternateContents'] as $drawingAlternateContent) {
$objWriter->writeRaw($drawingAlternateContent); $objWriter->writeRaw($drawingAlternateContent);
} }
} }

View File

@ -196,8 +196,9 @@ class Rels extends WriterPart
// Write drawing relationships? // Write drawing relationships?
$d = 0; $d = 0;
$drawingOriginalIds = []; $drawingOriginalIds = [];
if (isset($pWorksheet->getParent()->getUnparsedLoadedData()['sheets'][$pWorksheet->getCodeName()]['drawingOriginalIds'])) { $unparsedLoadedData = $pWorksheet->getParent()->getUnparsedLoadedData();
$drawingOriginalIds = $pWorksheet->getParent()->getUnparsedLoadedData()['sheets'][$pWorksheet->getCodeName()]['drawingOriginalIds']; if (isset($unparsedLoadedData['sheets'][$pWorksheet->getCodeName()]['drawingOriginalIds'])) {
$drawingOriginalIds = $unparsedLoadedData['sheets'][$pWorksheet->getCodeName()]['drawingOriginalIds'];
} }
if ($includeCharts) { if ($includeCharts) {
@ -278,11 +279,12 @@ class Rels extends WriterPart
private function writeUnparsedRelationship(\PhpOffice\PhpSpreadsheet\Worksheet\Worksheet $pWorksheet, XMLWriter $objWriter, $relationship, $type) private function writeUnparsedRelationship(\PhpOffice\PhpSpreadsheet\Worksheet\Worksheet $pWorksheet, XMLWriter $objWriter, $relationship, $type)
{ {
if (!isset($pWorksheet->getParent()->getUnparsedLoadedData()['sheets'][$pWorksheet->getCodeName()][$relationship])) { $unparsedLoadedData = $pWorksheet->getParent()->getUnparsedLoadedData();
if (!isset($unparsedLoadedData['sheets'][$pWorksheet->getCodeName()][$relationship])) {
return; return;
} }
foreach ($pWorksheet->getParent()->getUnparsedLoadedData()['sheets'][$pWorksheet->getCodeName()][$relationship] as $rId => $value) { foreach ($unparsedLoadedData['sheets'][$pWorksheet->getCodeName()][$relationship] as $rId => $value) {
$this->writeRelationship( $this->writeRelationship(
$objWriter, $objWriter,
$rId, $rId,

View File

@ -852,8 +852,9 @@ class Worksheet extends WriterPart
$objWriter->writeAttribute('useFirstPageNumber', '1'); $objWriter->writeAttribute('useFirstPageNumber', '1');
} }
if (isset($pSheet->getParent()->getUnparsedLoadedData()['sheets'][$pSheet->getCodeName()]['pageSetupRelId'])) { $getUnparsedLoadedData = $pSheet->getParent()->getUnparsedLoadedData();
$objWriter->writeAttribute('r:id', $pSheet->getParent()->getUnparsedLoadedData()['sheets'][$pSheet->getCodeName()]['pageSetupRelId']); if (isset($getUnparsedLoadedData['sheets'][$pSheet->getCodeName()]['pageSetupRelId'])) {
$objWriter->writeAttribute('r:id', $getUnparsedLoadedData['sheets'][$pSheet->getCodeName()]['pageSetupRelId']);
} }
$objWriter->endElement(); $objWriter->endElement();
@ -1157,7 +1158,8 @@ class Worksheet extends WriterPart
*/ */
private function writeDrawings(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet, $includeCharts = false) private function writeDrawings(XMLWriter $objWriter, PhpspreadsheetWorksheet $pSheet, $includeCharts = false)
{ {
$hasUnparsedDrawing = isset($pSheet->getParent()->getUnparsedLoadedData()['sheets'][$pSheet->getCodeName()]['drawingOriginalIds']); $unparsedLoadedData = $pSheet->getParent()->getUnparsedLoadedData();
$hasUnparsedDrawing = isset($unparsedLoadedData['sheets'][$pSheet->getCodeName()]['drawingOriginalIds']);
$chartCount = ($includeCharts) ? $pSheet->getChartCollection()->count() : 0; $chartCount = ($includeCharts) ? $pSheet->getChartCollection()->count() : 0;
if ($chartCount == 0 && $pSheet->getDrawingCollection()->count() == 0 && !$hasUnparsedDrawing) { if ($chartCount == 0 && $pSheet->getDrawingCollection()->count() == 0 && !$hasUnparsedDrawing) {
return; return;
@ -1167,8 +1169,8 @@ class Worksheet extends WriterPart
$objWriter->startElement('drawing'); $objWriter->startElement('drawing');
$rId = 'rId1'; $rId = 'rId1';
if (isset($pSheet->getParent()->getUnparsedLoadedData()['sheets'][$pSheet->getCodeName()]['drawingOriginalIds'])) { if (isset($unparsedLoadedData['sheets'][$pSheet->getCodeName()]['drawingOriginalIds'])) {
$drawingOriginalIds = $pSheet->getParent()->getUnparsedLoadedData()['sheets'][$pSheet->getCodeName()]['drawingOriginalIds']; $drawingOriginalIds = $unparsedLoadedData['sheets'][$pSheet->getCodeName()]['drawingOriginalIds'];
// take first. In future can be overriten // take first. In future can be overriten
$rId = reset($drawingOriginalIds); $rId = reset($drawingOriginalIds);
} }