From bda119cbedf4111d440e47d9c86be4450aec888b Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Fri, 29 Nov 2024 13:36:36 +0400 Subject: [PATCH] application des modifs nulib/spout pour v3.7.4 --- patches/v3.7.4.patch | 77 +++++++++++++++++++ .../Reader/XLSX/Helper/CellValueFormatter.php | 8 +- .../Reader/XLSX/Manager/OptionsManager.php | 2 +- upstream-3.x/src/Writer/WriterAbstract.php | 19 ++++- 4 files changed, 102 insertions(+), 4 deletions(-) create mode 100644 patches/v3.7.4.patch diff --git a/patches/v3.7.4.patch b/patches/v3.7.4.patch new file mode 100644 index 0000000..7597d3e --- /dev/null +++ b/patches/v3.7.4.patch @@ -0,0 +1,77 @@ +diff --git a/src/Writer/WriterAbstract.php b/src/Writer/WriterAbstract.php +index fd7c472..a2a5e37 100644 +--- a/src/Writer/WriterAbstract.php ++++ b/src/Writer/WriterAbstract.php +@@ -22,6 +22,9 @@ abstract class WriterAbstract implements WriterInterface + /** @var resource Pointer to the file/stream we will write to */ + protected $filePointer; + ++ /** @var bool faut-il garder ouvert le flux quand close() est appelé? */ ++ protected $dontCloseFilePointer = false; ++ + /** @var bool Indicates whether the writer has been opened or not */ + protected $isWriterOpened = false; + +@@ -57,6 +60,20 @@ abstract class WriterAbstract implements WriterInterface + return $this; + } + ++ public function writeToStream($filePointer) ++ { ++ $this->outputFilePath = null; ++ ++ $this->filePointer = $filePointer; ++ $this->dontCloseFilePointer = true; ++ $this->throwIfFilePointerIsNotAvailable(); ++ ++ $this->openWriter(); ++ $this->isWriterOpened = true; ++ ++ return $this; ++ } ++ + /** + * {@inheritdoc} + */ +@@ -177,7 +194,7 @@ abstract class WriterAbstract implements WriterInterface + + $this->closeWriter(); + +- if (\is_resource($this->filePointer)) { ++ if (!$this->dontCloseFilePointer && \is_resource($this->filePointer)) { + $this->globalFunctionsHelper->fclose($this->filePointer); + } + +diff --git a/src/Reader/XLSX/Helper/CellValueFormatter.php b/src/Reader/XLSX/Helper/CellValueFormatter.php +index 1734fb5..08e5282 100644 +--- a/src/Reader/XLSX/Helper/CellValueFormatter.php ++++ b/src/Reader/XLSX/Helper/CellValueFormatter.php +@@ -268,9 +268,13 @@ class CellValueFormatter + $dateObj->modify('+'.$secondsRemainder.'seconds'); + + if ($this->shouldFormatDates) { +- $styleNumberFormatCode = $this->styleManager->getNumberFormatCode($cellStyleId); +- $phpDateFormat = DateFormatHelper::toPHPDateFormat($styleNumberFormatCode); ++ //$styleNumberFormatCode = $this->styleManager->getNumberFormatCode($cellStyleId); ++ //$phpDateFormat = DateFormatHelper::toPHPDateFormat($styleNumberFormatCode); ++ // Toujours utiliser le format français complet ++ $phpDateFormat = "d/m/Y H:i:s"; + $cellValue = $dateObj->format($phpDateFormat); ++ // Enlever la composante heure si elle n'existe pas ++ $cellValue = preg_replace('/ 00:00:00$/', "", $cellValue); + } else { + $cellValue = $dateObj; + } +diff --git a/src/Reader/XLSX/Manager/OptionsManager.php b/src/Reader/XLSX/Manager/OptionsManager.php +index b04b92c..5749f65 100644 +--- a/src/Reader/XLSX/Manager/OptionsManager.php ++++ b/src/Reader/XLSX/Manager/OptionsManager.php +@@ -29,7 +29,7 @@ class OptionsManager extends OptionsManagerAbstract + protected function setDefaultOptions() + { + $this->setOption(Options::TEMP_FOLDER, sys_get_temp_dir()); +- $this->setOption(Options::SHOULD_FORMAT_DATES, false); ++ $this->setOption(Options::SHOULD_FORMAT_DATES, true); + $this->setOption(Options::SHOULD_PRESERVE_EMPTY_ROWS, false); + $this->setOption(Options::SHOULD_USE_1904_DATES, false); + } diff --git a/upstream-3.x/src/Reader/XLSX/Helper/CellValueFormatter.php b/upstream-3.x/src/Reader/XLSX/Helper/CellValueFormatter.php index 1734fb5..08e5282 100644 --- a/upstream-3.x/src/Reader/XLSX/Helper/CellValueFormatter.php +++ b/upstream-3.x/src/Reader/XLSX/Helper/CellValueFormatter.php @@ -268,9 +268,13 @@ class CellValueFormatter $dateObj->modify('+'.$secondsRemainder.'seconds'); if ($this->shouldFormatDates) { - $styleNumberFormatCode = $this->styleManager->getNumberFormatCode($cellStyleId); - $phpDateFormat = DateFormatHelper::toPHPDateFormat($styleNumberFormatCode); + //$styleNumberFormatCode = $this->styleManager->getNumberFormatCode($cellStyleId); + //$phpDateFormat = DateFormatHelper::toPHPDateFormat($styleNumberFormatCode); + // Toujours utiliser le format français complet + $phpDateFormat = "d/m/Y H:i:s"; $cellValue = $dateObj->format($phpDateFormat); + // Enlever la composante heure si elle n'existe pas + $cellValue = preg_replace('/ 00:00:00$/', "", $cellValue); } else { $cellValue = $dateObj; } diff --git a/upstream-3.x/src/Reader/XLSX/Manager/OptionsManager.php b/upstream-3.x/src/Reader/XLSX/Manager/OptionsManager.php index b04b92c..5749f65 100644 --- a/upstream-3.x/src/Reader/XLSX/Manager/OptionsManager.php +++ b/upstream-3.x/src/Reader/XLSX/Manager/OptionsManager.php @@ -29,7 +29,7 @@ class OptionsManager extends OptionsManagerAbstract protected function setDefaultOptions() { $this->setOption(Options::TEMP_FOLDER, sys_get_temp_dir()); - $this->setOption(Options::SHOULD_FORMAT_DATES, false); + $this->setOption(Options::SHOULD_FORMAT_DATES, true); $this->setOption(Options::SHOULD_PRESERVE_EMPTY_ROWS, false); $this->setOption(Options::SHOULD_USE_1904_DATES, false); } diff --git a/upstream-3.x/src/Writer/WriterAbstract.php b/upstream-3.x/src/Writer/WriterAbstract.php index fd7c472..a2a5e37 100644 --- a/upstream-3.x/src/Writer/WriterAbstract.php +++ b/upstream-3.x/src/Writer/WriterAbstract.php @@ -22,6 +22,9 @@ abstract class WriterAbstract implements WriterInterface /** @var resource Pointer to the file/stream we will write to */ protected $filePointer; + /** @var bool faut-il garder ouvert le flux quand close() est appelé? */ + protected $dontCloseFilePointer = false; + /** @var bool Indicates whether the writer has been opened or not */ protected $isWriterOpened = false; @@ -57,6 +60,20 @@ abstract class WriterAbstract implements WriterInterface return $this; } + public function writeToStream($filePointer) + { + $this->outputFilePath = null; + + $this->filePointer = $filePointer; + $this->dontCloseFilePointer = true; + $this->throwIfFilePointerIsNotAvailable(); + + $this->openWriter(); + $this->isWriterOpened = true; + + return $this; + } + /** * {@inheritdoc} */ @@ -177,7 +194,7 @@ abstract class WriterAbstract implements WriterInterface $this->closeWriter(); - if (\is_resource($this->filePointer)) { + if (!$this->dontCloseFilePointer && \is_resource($this->filePointer)) { $this->globalFunctionsHelper->fclose($this->filePointer); }