From dd3cc5bf47463e1807aab18f87e1b725b6beba28 Mon Sep 17 00:00:00 2001 From: Adrien Loison Date: Tue, 1 Sep 2015 11:04:15 -0700 Subject: [PATCH] Remove XML indentation --- .../Writer/ODS/Helper/FileSystemHelper.php | 17 +--- src/Spout/Writer/ODS/Helper/StyleHelper.php | 80 +++++++++--------- src/Spout/Writer/ODS/Internal/Worksheet.php | 30 +++---- .../Writer/XLSX/Helper/FileSystemHelper.php | 9 +-- .../XLSX/Helper/SharedStringsHelper.php | 4 +- src/Spout/Writer/XLSX/Helper/StyleHelper.php | 81 +++++++++---------- src/Spout/Writer/XLSX/Internal/Worksheet.php | 22 ++--- 7 files changed, 110 insertions(+), 133 deletions(-) diff --git a/src/Spout/Writer/ODS/Helper/FileSystemHelper.php b/src/Spout/Writer/ODS/Helper/FileSystemHelper.php index 1bb1674..09f068b 100644 --- a/src/Spout/Writer/ODS/Helper/FileSystemHelper.php +++ b/src/Spout/Writer/ODS/Helper/FileSystemHelper.php @@ -183,17 +183,12 @@ EOD; $contentXmlFileContents = << - EOD; $contentXmlFileContents .= $styleHelper->getContentXmlFontFaceSectionContent(); $contentXmlFileContents .= $styleHelper->getContentXmlAutomaticStylesSectionContent(count($worksheets)); - $contentXmlFileContents .= << - - -EOD; + $contentXmlFileContents .= ''; $this->createFileWithContents($this->rootFolder, self::CONTENT_XML_FILE_NAME, $contentXmlFileContents); @@ -203,19 +198,15 @@ EOD; foreach ($worksheets as $worksheet) { // write the "" node, with the final sheet's name - fwrite($contentXmlHandle, $worksheet->getTableElementStartAsString() . PHP_EOL); + fwrite($contentXmlHandle, $worksheet->getTableElementStartAsString()); $worksheetFilePath = $worksheet->getWorksheetFilePath(); $this->copyFileContentsToTarget($worksheetFilePath, $contentXmlHandle); - fwrite($contentXmlHandle, '' . PHP_EOL); + fwrite($contentXmlHandle, ''); } - $contentXmlFileContents = << - - -EOD; + $contentXmlFileContents = ''; fwrite($contentXmlHandle, $contentXmlFileContents); fclose($contentXmlHandle); diff --git a/src/Spout/Writer/ODS/Helper/StyleHelper.php b/src/Spout/Writer/ODS/Helper/StyleHelper.php index f5f9de8..f8b0c4d 100644 --- a/src/Spout/Writer/ODS/Helper/StyleHelper.php +++ b/src/Spout/Writer/ODS/Helper/StyleHelper.php @@ -47,7 +47,6 @@ class StyleHelper extends AbstractStyleHelper $content = << - EOD; $content .= $this->getFontFaceSectionContent(); @@ -69,11 +68,11 @@ EOD; */ protected function getFontFaceSectionContent() { - $content = '' . PHP_EOL; + $content = ''; foreach ($this->getUsedFonts() as $fontName) { - $content .= ' ' . PHP_EOL; + $content .= ''; } - $content .= '' . PHP_EOL; + $content .= ''; return $content; } @@ -99,7 +98,6 @@ EOD; style:font-name="{$defaultStyle->getFontName()}" style:font-name-asian="{$defaultStyle->getFontName()}" style:font-name-complex="{$defaultStyle->getFontName()}"/> - EOD; } @@ -111,20 +109,19 @@ EOD; */ protected function getAutomaticStylesSectionContent($numWorksheets) { - $content = '' . PHP_EOL; + $content = ''; for ($i = 1; $i <= $numWorksheets; $i++) { $content .= << - - - - - + + + + + EOD; } - $content .= '' . PHP_EOL; + $content .= ''; return $content; } @@ -137,21 +134,20 @@ EOD; */ protected function getMasterStylesSectionContent($numWorksheets) { - $content = '' . PHP_EOL; + $content = ''; for ($i = 1; $i <= $numWorksheets; $i++) { $content .= << - - - - - - + + + + + + EOD; } - $content .= '' . PHP_EOL; + $content .= ''; return $content; } @@ -164,11 +160,11 @@ EOD; */ public function getContentXmlFontFaceSectionContent() { - $content = '' . PHP_EOL; + $content = ''; foreach ($this->getUsedFonts() as $fontName) { - $content .= ' ' . PHP_EOL; + $content .= ''; } - $content .= '' . PHP_EOL; + $content .= ''; return $content; } @@ -181,32 +177,30 @@ EOD; */ public function getContentXmlAutomaticStylesSectionContent($numWorksheets) { - $content = '' . PHP_EOL; + $content = ''; foreach ($this->getRegisteredStyles() as $style) { $content .= $this->getStyleSectionContent($style); } $content .= << - - - - - - + + + + + + EOD; for ($i = 1; $i <= $numWorksheets; $i++) { $content .= << - - - + + + EOD; } - $content .= '' . PHP_EOL; + $content .= ''; return $content; } @@ -222,10 +216,10 @@ EOD; $defaultStyle = $this->getDefaultStyle(); $styleIndex = $style->getId() + 1; // 1-based - $content = ' ' . PHP_EOL; + $content = ''; if ($style->shouldApplyFont()) { - $content .= ' getFontColor(); if ($fontColor !== $defaultStyle->getFontColor()) { @@ -255,14 +249,14 @@ EOD; $content .= ' style:text-line-through-style="solid"'; } - $content .= '/>' . PHP_EOL; + $content .= '/>'; } if ($style->shouldWrapText()) { - $content .= ' ' . PHP_EOL; + $content .= ''; } - $content .= ' ' . PHP_EOL; + $content .= ''; return $content; } diff --git a/src/Spout/Writer/ODS/Internal/Worksheet.php b/src/Spout/Writer/ODS/Internal/Worksheet.php index 9390030..a3d5d76 100644 --- a/src/Spout/Writer/ODS/Internal/Worksheet.php +++ b/src/Spout/Writer/ODS/Internal/Worksheet.php @@ -100,8 +100,8 @@ class Worksheet implements WorksheetInterface $escapedSheetName = $this->stringsEscaper->escape($this->externalSheet->getName()); $tableStyleName = 'ta' . ($this->externalSheet->getIndex() + 1); - $tableElement = '' . PHP_EOL; - $tableElement .= ' '; + $tableElement = ''; + $tableElement .= ''; return $tableElement; } @@ -138,7 +138,7 @@ class Worksheet implements WorksheetInterface $cellsCount = count($dataRow); $this->maxNumColumns = max($this->maxNumColumns, $cellsCount); - $data = ' ' . PHP_EOL; + $data = ''; $currentCellIndex = 0; $nextCellIndex = 1; @@ -156,7 +156,7 @@ class Worksheet implements WorksheetInterface $nextCellIndex++; } - $data .= ' ' . PHP_EOL; + $data .= ''; $wasWriteSuccessful = fwrite($this->sheetFilePointer, $data); if ($wasWriteSuccessful === false) { @@ -178,31 +178,31 @@ class Worksheet implements WorksheetInterface */ protected function getCellContent($cellValue, $styleIndex, $numTimesValueRepeated) { - $data = ' stringsEscaper->escape($cellValueLine) . '' . PHP_EOL; + $data .= '' . $this->stringsEscaper->escape($cellValueLine) . ''; } - $data .= ' ' . PHP_EOL; + $data .= ''; } else if (CellHelper::isBoolean($cellValue)) { - $data .= ' office:value-type="boolean" calcext:value-type="boolean" office:value="' . $cellValue . '">' . PHP_EOL; - $data .= ' ' . $cellValue . '' . PHP_EOL; - $data .= ' ' . PHP_EOL; + $data .= ' office:value-type="boolean" calcext:value-type="boolean" office:value="' . $cellValue . '">'; + $data .= '' . $cellValue . ''; + $data .= ''; } else if (CellHelper::isNumeric($cellValue)) { - $data .= ' office:value-type="float" calcext:value-type="float" office:value="' . $cellValue . '">' . PHP_EOL; - $data .= ' ' . $cellValue . '' . PHP_EOL; - $data .= ' ' . PHP_EOL; + $data .= ' office:value-type="float" calcext:value-type="float" office:value="' . $cellValue . '">'; + $data .= '' . $cellValue . ''; + $data .= ''; } else if (empty($cellValue)) { - $data .= '/>' . PHP_EOL; + $data .= '/>'; } else { throw new InvalidArgumentException('Trying to add a value with an unsupported type: ' . gettype($cellValue)); } diff --git a/src/Spout/Writer/XLSX/Helper/FileSystemHelper.php b/src/Spout/Writer/XLSX/Helper/FileSystemHelper.php index e84b68e..bf9e350 100644 --- a/src/Spout/Writer/XLSX/Helper/FileSystemHelper.php +++ b/src/Spout/Writer/XLSX/Helper/FileSystemHelper.php @@ -249,12 +249,11 @@ EOD; - EOD; /** @var Worksheet $worksheet */ foreach ($worksheets as $worksheet) { - $contentTypesXmlFileContents .= ' ' . PHP_EOL; + $contentTypesXmlFileContents .= ''; } $contentTypesXmlFileContents .= << - EOD; /** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */ @@ -292,7 +290,7 @@ EOD; foreach ($worksheets as $worksheet) { $worksheetName = $worksheet->getExternalSheet()->getName(); $worksheetId = $worksheet->getId(); - $workbookXmlFileContents .= ' ' . PHP_EOL; + $workbookXmlFileContents .= ''; } $workbookXmlFileContents .= << - EOD; /** @var Worksheet $worksheet */ foreach ($worksheets as $worksheet) { $worksheetId = $worksheet->getId(); - $workbookRelsXmlFileContents .= ' ' . PHP_EOL; + $workbookRelsXmlFileContents .= ''; } $workbookRelsXmlFileContents .= ''; diff --git a/src/Spout/Writer/XLSX/Helper/SharedStringsHelper.php b/src/Spout/Writer/XLSX/Helper/SharedStringsHelper.php index cc9573f..a17493a 100644 --- a/src/Spout/Writer/XLSX/Helper/SharedStringsHelper.php +++ b/src/Spout/Writer/XLSX/Helper/SharedStringsHelper.php @@ -45,7 +45,7 @@ EOD; $this->throwIfSharedStringsFilePointerIsNotAvailable(); // the headers is split into different parts so that we can fseek and put in the correct count and uniqueCount later - $header = self::SHARED_STRINGS_XML_FILE_FIRST_PART_HEADER . ' ' . self::DEFAULT_STRINGS_COUNT_PART . '>' . PHP_EOL; + $header = self::SHARED_STRINGS_XML_FILE_FIRST_PART_HEADER . ' ' . self::DEFAULT_STRINGS_COUNT_PART . '>'; fwrite($this->sharedStringsFilePointer, $header); /** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */ @@ -74,7 +74,7 @@ EOD; */ public function writeString($string) { - fwrite($this->sharedStringsFilePointer, ' ' . $this->stringsEscaper->escape($string) . '' . PHP_EOL); + fwrite($this->sharedStringsFilePointer, '' . $this->stringsEscaper->escape($string) . ''); $this->numSharedStrings++; // Shared string ID is zero-based diff --git a/src/Spout/Writer/XLSX/Helper/StyleHelper.php b/src/Spout/Writer/XLSX/Helper/StyleHelper.php index 06bbfc3..f3da2b5 100644 --- a/src/Spout/Writer/XLSX/Helper/StyleHelper.php +++ b/src/Spout/Writer/XLSX/Helper/StyleHelper.php @@ -23,7 +23,6 @@ class StyleHelper extends AbstractStyleHelper $content = << - EOD; $content .= $this->getFontsSectionContent(); @@ -47,33 +46,33 @@ EOD; */ protected function getFontsSectionContent() { - $content = ' ' . PHP_EOL; + $content = ''; /** @var \Box\Spout\Writer\Style\Style $style */ foreach ($this->getRegisteredStyles() as $style) { - $content .= ' ' . PHP_EOL; + $content .= ''; - $content .= ' ' . PHP_EOL; - $content .= ' ' . PHP_EOL; - $content .= ' ' . PHP_EOL; + $content .= ''; + $content .= ''; + $content .= ''; if ($style->isFontBold()) { - $content .= ' ' . PHP_EOL; + $content .= ''; } if ($style->isFontItalic()) { - $content .= ' ' . PHP_EOL; + $content .= ''; } if ($style->isFontUnderline()) { - $content .= ' ' . PHP_EOL; + $content .= ''; } if ($style->isFontStrikethrough()) { - $content .= ' ' . PHP_EOL; + $content .= ''; } - $content .= ' ' . PHP_EOL; + $content .= ''; } - $content .= ' ' . PHP_EOL; + $content .= ''; return $content; } @@ -86,12 +85,11 @@ EOD; protected function getFillsSectionContent() { return << - - - - - + + + + + EOD; } @@ -103,16 +101,15 @@ EOD; protected function getBordersSectionContent() { return << - - - - - - - - - + + + + + + + + + EOD; } @@ -124,10 +121,9 @@ EOD; protected function getCellStyleXfsSectionContent() { return << - - - + + + EOD; } @@ -140,25 +136,25 @@ EOD; { $registeredStyles = $this->getRegisteredStyles(); - $content = ' ' . PHP_EOL; + $content = ''; foreach ($registeredStyles as $style) { - $content .= ' getId() . '" fillId="0" borderId="0" xfId="0"'; if ($style->shouldApplyFont()) { $content .= ' applyFont="1"'; } if ($style->shouldWrapText()) { - $content .= ' applyAlignment="1">' . PHP_EOL; - $content .= ' ' . PHP_EOL; - $content .= ' ' . PHP_EOL; + $content .= ' applyAlignment="1">'; + $content .= ''; + $content .= ''; } else { - $content .= '/>' . PHP_EOL; + $content .= '/>'; } } - $content .= ' ' . PHP_EOL; + $content .= ''; return $content; } @@ -171,10 +167,9 @@ EOD; protected function getCellStylesSectionContent() { return << - - - + + + EOD; } } diff --git a/src/Spout/Writer/XLSX/Internal/Worksheet.php b/src/Spout/Writer/XLSX/Internal/Worksheet.php index d9346c1..be67e19 100644 --- a/src/Spout/Writer/XLSX/Internal/Worksheet.php +++ b/src/Spout/Writer/XLSX/Internal/Worksheet.php @@ -73,8 +73,8 @@ EOD; $this->sheetFilePointer = fopen($this->worksheetFilePath, 'w'); $this->throwIfSheetFilePointerIsNotAvailable(); - fwrite($this->sheetFilePointer, self::SHEET_XML_FILE_HEADER . PHP_EOL); - fwrite($this->sheetFilePointer, ' ' . PHP_EOL); + fwrite($this->sheetFilePointer, self::SHEET_XML_FILE_HEADER); + fwrite($this->sheetFilePointer, ''); } /** @@ -131,26 +131,26 @@ EOD; $rowIndex = $this->lastWrittenRowIndex + 1; $numCells = count($dataRow); - $data = ' ' . PHP_EOL; + $data = ''; foreach($dataRow as $cellValue) { $columnIndex = CellHelper::getCellIndexFromColumnIndex($cellNumber); - $data .= ' getId() . '"'; if (CellHelper::isNonEmptyString($cellValue)) { if ($this->shouldUseInlineStrings) { - $data .= ' t="inlineStr">' . $this->stringsEscaper->escape($cellValue) . '' . PHP_EOL; + $data .= ' t="inlineStr">' . $this->stringsEscaper->escape($cellValue) . ''; } else { $sharedStringId = $this->sharedStringsHelper->writeString($cellValue); - $data .= ' t="s">' . $sharedStringId . '' . PHP_EOL; + $data .= ' t="s">' . $sharedStringId . ''; } } else if (CellHelper::isBoolean($cellValue)) { - $data .= ' t="b">' . $cellValue . '' . PHP_EOL; + $data .= ' t="b">' . $cellValue . ''; } else if (CellHelper::isNumeric($cellValue)) { - $data .= '>' . $cellValue . '' . PHP_EOL; + $data .= '>' . $cellValue . ''; } else if (empty($cellValue)) { - $data .= '/>' . PHP_EOL; + $data .= '/>'; } else { throw new InvalidArgumentException('Trying to add a value with an unsupported type: ' . gettype($cellValue)); } @@ -158,7 +158,7 @@ EOD; $cellNumber++; } - $data .= ' ' . PHP_EOL; + $data .= ''; $wasWriteSuccessful = fwrite($this->sheetFilePointer, $data); if ($wasWriteSuccessful === false) { @@ -176,7 +176,7 @@ EOD; */ public function close() { - fwrite($this->sheetFilePointer, ' ' . PHP_EOL); + fwrite($this->sheetFilePointer, ''); fwrite($this->sheetFilePointer, ''); fclose($this->sheetFilePointer); }