diff --git a/src/Spout/Common/Escaper/ODS.php b/src/Spout/Common/Escaper/ODS.php index 3e252a7..86caeb3 100644 --- a/src/Spout/Common/Escaper/ODS.php +++ b/src/Spout/Common/Escaper/ODS.php @@ -2,6 +2,8 @@ namespace Box\Spout\Common\Escaper; +use Box\Spout\Common\Singleton; + /** * Class ODS * Provides functions to escape and unescape data for ODS files @@ -10,6 +12,8 @@ namespace Box\Spout\Common\Escaper; */ class ODS implements EscaperInterface { + use Singleton; + /** * Escapes the given string to make it compatible with XLSX * diff --git a/src/Spout/Common/Escaper/XLSX.php b/src/Spout/Common/Escaper/XLSX.php index 6f5bd1f..b5719a0 100644 --- a/src/Spout/Common/Escaper/XLSX.php +++ b/src/Spout/Common/Escaper/XLSX.php @@ -2,6 +2,8 @@ namespace Box\Spout\Common\Escaper; +use Box\Spout\Common\Singleton; + /** * Class XLSX * Provides functions to escape and unescape data for XLSX files @@ -10,13 +12,15 @@ namespace Box\Spout\Common\Escaper; */ class XLSX implements EscaperInterface { + use Singleton; + /** @var string[] Control characters to be escaped */ protected $controlCharactersEscapingMap; /** - * + * Initializes the singleton instance */ - public function __construct() + protected function init() { $this->controlCharactersEscapingMap = $this->getControlCharactersEscapingMap(); } diff --git a/src/Spout/Common/Helper/EncodingHelper.php b/src/Spout/Common/Helper/EncodingHelper.php index 3edd7a1..3a30aaa 100644 --- a/src/Spout/Common/Helper/EncodingHelper.php +++ b/src/Spout/Common/Helper/EncodingHelper.php @@ -59,7 +59,7 @@ class EncodingHelper { $byteOffsetToSkipBom = 0; - if ($this->hasBom($filePointer, $encoding)) { + if ($this->hasBOM($filePointer, $encoding)) { $bomUsed = $this->supportedEncodingsWithBom[$encoding]; // we skip the N first bytes diff --git a/src/Spout/Common/Singleton.php b/src/Spout/Common/Singleton.php new file mode 100644 index 0000000..015ede8 --- /dev/null +++ b/src/Spout/Common/Singleton.php @@ -0,0 +1,41 @@ +init(); + } + + /** + * Initializes the singleton + * @return void + */ + protected function init() {} + + final private function __wakeup() {} + final private function __clone() {} +} diff --git a/src/Spout/Reader/CSV/RowIterator.php b/src/Spout/Reader/CSV/RowIterator.php index 95b2596..5189dfc 100644 --- a/src/Spout/Reader/CSV/RowIterator.php +++ b/src/Spout/Reader/CSV/RowIterator.php @@ -57,6 +57,7 @@ class RowIterator implements IteratorInterface * @param string $fieldDelimiter Character that delimits fields * @param string $fieldEnclosure Character that enclose fields * @param string $encoding Encoding of the CSV file to be read + * @param string $endOfLineDelimiter End of line delimiter * @param \Box\Spout\Common\Helper\GlobalFunctionsHelper $globalFunctionsHelper */ public function __construct($filePointer, $fieldDelimiter, $fieldEnclosure, $encoding, $endOfLineDelimiter, $globalFunctionsHelper) diff --git a/src/Spout/Reader/ODS/Helper/CellValueFormatter.php b/src/Spout/Reader/ODS/Helper/CellValueFormatter.php index b39af21..38c1c85 100644 --- a/src/Spout/Reader/ODS/Helper/CellValueFormatter.php +++ b/src/Spout/Reader/ODS/Helper/CellValueFormatter.php @@ -48,7 +48,7 @@ class CellValueFormatter $this->shouldFormatDates = $shouldFormatDates; /** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */ - $this->escaper = new \Box\Spout\Common\Escaper\ODS(); + $this->escaper = \Box\Spout\Common\Escaper\ODS::getInstance(); } /** diff --git a/src/Spout/Reader/ODS/SheetIterator.php b/src/Spout/Reader/ODS/SheetIterator.php index 4f2ec01..f6cfdbe 100644 --- a/src/Spout/Reader/ODS/SheetIterator.php +++ b/src/Spout/Reader/ODS/SheetIterator.php @@ -51,7 +51,7 @@ class SheetIterator implements IteratorInterface $this->xmlReader = new XMLReader(); /** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */ - $this->escaper = new \Box\Spout\Common\Escaper\ODS(); + $this->escaper = \Box\Spout\Common\Escaper\ODS::getInstance(); } /** diff --git a/src/Spout/Reader/XLSX/Helper/CellValueFormatter.php b/src/Spout/Reader/XLSX/Helper/CellValueFormatter.php index 286d348..a272a2e 100644 --- a/src/Spout/Reader/XLSX/Helper/CellValueFormatter.php +++ b/src/Spout/Reader/XLSX/Helper/CellValueFormatter.php @@ -62,7 +62,7 @@ class CellValueFormatter $this->shouldFormatDates = $shouldFormatDates; /** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */ - $this->escaper = new \Box\Spout\Common\Escaper\XLSX(); + $this->escaper = \Box\Spout\Common\Escaper\XLSX::getInstance(); } /** diff --git a/src/Spout/Reader/XLSX/Helper/SharedStringsHelper.php b/src/Spout/Reader/XLSX/Helper/SharedStringsHelper.php index 1ba4e6a..750c53e 100644 --- a/src/Spout/Reader/XLSX/Helper/SharedStringsHelper.php +++ b/src/Spout/Reader/XLSX/Helper/SharedStringsHelper.php @@ -80,7 +80,7 @@ class SharedStringsHelper $xmlReader = new XMLReader(); $sharedStringIndex = 0; /** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */ - $escaper = new \Box\Spout\Common\Escaper\XLSX(); + $escaper = \Box\Spout\Common\Escaper\XLSX::getInstance(); $sharedStringsFilePath = $this->getSharedStringsFilePath(); if ($xmlReader->open($sharedStringsFilePath) === false) { diff --git a/src/Spout/Reader/XLSX/Helper/SheetHelper.php b/src/Spout/Reader/XLSX/Helper/SheetHelper.php index 175de5b..a6ff909 100644 --- a/src/Spout/Reader/XLSX/Helper/SheetHelper.php +++ b/src/Spout/Reader/XLSX/Helper/SheetHelper.php @@ -87,7 +87,7 @@ class SheetHelper $escapedSheetName = $xmlReaderOnSheetNode->getAttribute('name'); /** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */ - $escaper = new \Box\Spout\Common\Escaper\XLSX(); + $escaper = \Box\Spout\Common\Escaper\XLSX::getInstance(); $sheetName = $escaper->unescape($escapedSheetName); $sheetDataXMLFilePath = $this->getSheetDataXMLFilePathForSheetId($sheetId); diff --git a/src/Spout/Writer/ODS/Internal/Worksheet.php b/src/Spout/Writer/ODS/Internal/Worksheet.php index 7a0df1a..cec30af 100644 --- a/src/Spout/Writer/ODS/Internal/Worksheet.php +++ b/src/Spout/Writer/ODS/Internal/Worksheet.php @@ -47,7 +47,7 @@ class Worksheet implements WorksheetInterface { $this->externalSheet = $externalSheet; /** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */ - $this->stringsEscaper = new \Box\Spout\Common\Escaper\ODS(); + $this->stringsEscaper = \Box\Spout\Common\Escaper\ODS::getInstance(); $this->worksheetFilePath = $worksheetFilesFolder . '/sheet' . $externalSheet->getIndex() . '.xml'; $this->stringHelper = new StringHelper(); diff --git a/src/Spout/Writer/XLSX/Helper/FileSystemHelper.php b/src/Spout/Writer/XLSX/Helper/FileSystemHelper.php index 59df98a..786e62e 100644 --- a/src/Spout/Writer/XLSX/Helper/FileSystemHelper.php +++ b/src/Spout/Writer/XLSX/Helper/FileSystemHelper.php @@ -284,7 +284,7 @@ EOD; EOD; /** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */ - $escaper = new \Box\Spout\Common\Escaper\XLSX(); + $escaper = \Box\Spout\Common\Escaper\XLSX::getInstance(); /** @var Worksheet $worksheet */ foreach ($worksheets as $worksheet) { diff --git a/src/Spout/Writer/XLSX/Helper/SharedStringsHelper.php b/src/Spout/Writer/XLSX/Helper/SharedStringsHelper.php index 9d9639d..292b663 100644 --- a/src/Spout/Writer/XLSX/Helper/SharedStringsHelper.php +++ b/src/Spout/Writer/XLSX/Helper/SharedStringsHelper.php @@ -49,7 +49,7 @@ EOD; fwrite($this->sharedStringsFilePointer, $header); /** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */ - $this->stringsEscaper = new \Box\Spout\Common\Escaper\XLSX(); + $this->stringsEscaper = \Box\Spout\Common\Escaper\XLSX::getInstance(); } /** diff --git a/src/Spout/Writer/XLSX/Internal/Worksheet.php b/src/Spout/Writer/XLSX/Internal/Worksheet.php index af3fbc4..354554a 100644 --- a/src/Spout/Writer/XLSX/Internal/Worksheet.php +++ b/src/Spout/Writer/XLSX/Internal/Worksheet.php @@ -56,7 +56,7 @@ EOD; $this->shouldUseInlineStrings = $shouldUseInlineStrings; /** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */ - $this->stringsEscaper = new \Box\Spout\Common\Escaper\XLSX(); + $this->stringsEscaper = \Box\Spout\Common\Escaper\XLSX::getInstance(); $this->worksheetFilePath = $worksheetFilesFolder . '/' . strtolower($this->externalSheet->getName()) . '.xml'; $this->startSheet(); diff --git a/tests/Spout/Common/Escaper/XLSXTest.php b/tests/Spout/Common/Escaper/XLSXTest.php index 7c0b2db..289e2a2 100644 --- a/tests/Spout/Common/Escaper/XLSXTest.php +++ b/tests/Spout/Common/Escaper/XLSXTest.php @@ -35,7 +35,7 @@ class XLSXTest extends \PHPUnit_Framework_TestCase public function testEscape($stringToEscape, $expectedEscapedString) { /** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */ - $escaper = new \Box\Spout\Common\Escaper\XLSX(); + $escaper = \Box\Spout\Common\Escaper\XLSX::getInstance(); $escapedString = $escaper->escape($stringToEscape); $this->assertEquals($expectedEscapedString, $escapedString, 'Incorrect escaped string'); @@ -67,7 +67,7 @@ class XLSXTest extends \PHPUnit_Framework_TestCase public function testUnescape($stringToUnescape, $expectedUnescapedString) { /** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */ - $escaper = new \Box\Spout\Common\Escaper\XLSX(); + $escaper = \Box\Spout\Common\Escaper\XLSX::getInstance(); $unescapedString = $escaper->unescape($stringToUnescape); $this->assertEquals($expectedUnescapedString, $unescapedString, 'Incorrect escaped string');