From 37ce992b3e2ac6a5fc8356ee4d6b5aaf86dfd313 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Fri, 29 Nov 2024 17:28:19 +0400 Subject: [PATCH] application des modifs nulib/spout pour v4.27.0 --- patches/v4.27.0.patch | 91 +++++++++++++++++++ .../Reader/XLSX/Helper/CellValueFormatter.php | 8 +- upstream-4.x/src/Reader/XLSX/Options.php | 2 +- upstream-4.x/src/Writer/AbstractWriter.php | 26 +++++- 4 files changed, 122 insertions(+), 5 deletions(-) create mode 100644 patches/v4.27.0.patch diff --git a/patches/v4.27.0.patch b/patches/v4.27.0.patch new file mode 100644 index 0000000..1be50ce --- /dev/null +++ b/patches/v4.27.0.patch @@ -0,0 +1,91 @@ +diff --git a/src/Reader/XLSX/Helper/CellValueFormatter.php b/src/Reader/XLSX/Helper/CellValueFormatter.php +index 776de0a..bc7a5c4 100644 +--- a/src/Reader/XLSX/Helper/CellValueFormatter.php ++++ b/src/Reader/XLSX/Helper/CellValueFormatter.php +@@ -284,9 +284,13 @@ final class CellValueFormatter + \assert(false !== $dateObj); + + 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/Options.php b/src/Reader/XLSX/Options.php +index 636d2a4..e8609b5 100644 +--- a/src/Reader/XLSX/Options.php ++++ b/src/Reader/XLSX/Options.php +@@ -10,7 +10,7 @@ final class Options + { + use TempFolderOptionTrait; + +- public bool $SHOULD_FORMAT_DATES = false; ++ public bool $SHOULD_FORMAT_DATES = true; + public bool $SHOULD_PRESERVE_EMPTY_ROWS = false; + public bool $SHOULD_USE_1904_DATES = false; + public bool $SHOULD_LOAD_MERGE_CELLS = false; +diff --git a/src/Writer/AbstractWriter.php b/src/Writer/AbstractWriter.php +index eef34fb..a22e90f 100644 +--- a/src/Writer/AbstractWriter.php ++++ b/src/Writer/AbstractWriter.php +@@ -13,6 +13,12 @@ abstract class AbstractWriter implements WriterInterface + /** @var resource Pointer to the file/stream we will write to */ + protected $filePointer; + ++ /** ++ * @var bool faut-il garder ouvert le flux quand {@link self::close()} est ++ * appelé? ++ */ ++ protected bool $dontCloseFilePointer = false; ++ + /** @var string document creator */ + protected string $creator = 'OpenSpout'; + +@@ -20,7 +26,7 @@ abstract class AbstractWriter implements WriterInterface + protected static string $headerContentType; + + /** @var string Path to the output file */ +- private string $outputFilePath; ++ private ?string $outputFilePath; + + /** @var bool Indicates whether the writer has been opened or not */ + private bool $isWriterOpened = false; +@@ -51,6 +57,20 @@ abstract class AbstractWriter implements WriterInterface + $this->isWriterOpened = true; + } + ++ final public function writeToStream($filePointer): void ++ { ++ if (!is_resource($filePointer)) { ++ throw new IOException("filePointer is not a resource"); ++ } ++ $this->outputFilePath = null; ++ ++ $this->filePointer = $filePointer; ++ $this->dontCloseFilePointer = true; ++ ++ $this->openWriter(); ++ $this->isWriterOpened = true; ++ } ++ + /** + * @codeCoverageIgnore + * +@@ -140,7 +160,9 @@ abstract class AbstractWriter implements WriterInterface + + $this->closeWriter(); + +- fclose($this->filePointer); ++ if (!$this->dontCloseFilePointer) { ++ fclose($this->filePointer); ++ } + + $this->isWriterOpened = false; + } diff --git a/upstream-4.x/src/Reader/XLSX/Helper/CellValueFormatter.php b/upstream-4.x/src/Reader/XLSX/Helper/CellValueFormatter.php index 596e4f6..e10eaf0 100644 --- a/upstream-4.x/src/Reader/XLSX/Helper/CellValueFormatter.php +++ b/upstream-4.x/src/Reader/XLSX/Helper/CellValueFormatter.php @@ -284,9 +284,13 @@ final readonly class CellValueFormatter \assert(false !== $dateObj); 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-4.x/src/Reader/XLSX/Options.php b/upstream-4.x/src/Reader/XLSX/Options.php index 636d2a4..e8609b5 100644 --- a/upstream-4.x/src/Reader/XLSX/Options.php +++ b/upstream-4.x/src/Reader/XLSX/Options.php @@ -10,7 +10,7 @@ final class Options { use TempFolderOptionTrait; - public bool $SHOULD_FORMAT_DATES = false; + public bool $SHOULD_FORMAT_DATES = true; public bool $SHOULD_PRESERVE_EMPTY_ROWS = false; public bool $SHOULD_USE_1904_DATES = false; public bool $SHOULD_LOAD_MERGE_CELLS = false; diff --git a/upstream-4.x/src/Writer/AbstractWriter.php b/upstream-4.x/src/Writer/AbstractWriter.php index eef34fb..a22e90f 100644 --- a/upstream-4.x/src/Writer/AbstractWriter.php +++ b/upstream-4.x/src/Writer/AbstractWriter.php @@ -13,6 +13,12 @@ abstract class AbstractWriter implements WriterInterface /** @var resource Pointer to the file/stream we will write to */ protected $filePointer; + /** + * @var bool faut-il garder ouvert le flux quand {@link self::close()} est + * appelé? + */ + protected bool $dontCloseFilePointer = false; + /** @var string document creator */ protected string $creator = 'OpenSpout'; @@ -20,7 +26,7 @@ abstract class AbstractWriter implements WriterInterface protected static string $headerContentType; /** @var string Path to the output file */ - private string $outputFilePath; + private ?string $outputFilePath; /** @var bool Indicates whether the writer has been opened or not */ private bool $isWriterOpened = false; @@ -51,6 +57,20 @@ abstract class AbstractWriter implements WriterInterface $this->isWriterOpened = true; } + final public function writeToStream($filePointer): void + { + if (!is_resource($filePointer)) { + throw new IOException("filePointer is not a resource"); + } + $this->outputFilePath = null; + + $this->filePointer = $filePointer; + $this->dontCloseFilePointer = true; + + $this->openWriter(); + $this->isWriterOpened = true; + } + /** * @codeCoverageIgnore * @@ -140,7 +160,9 @@ abstract class AbstractWriter implements WriterInterface $this->closeWriter(); - fclose($this->filePointer); + if (!$this->dontCloseFilePointer) { + fclose($this->filePointer); + } $this->isWriterOpened = false; }