* [misc] Extend PHP 8 compatibility patches for iterator return types

- Complete box-spout PHP 8 compatibility by adding return type declarations for CSV, ODS iterator classes
- Extend phpspreadsheet iterator patch to include RowCellIterator, RowIterator, ColumnCellIterator, and ColumnIterator classes
- Add mixed return type for current() and key() methods to comply with PHP 8.1+ Iterator interface requirements
- Add void return type for rewind() and next() methods
- Add bool return type for valid() method

These patches ensure full PHP 8 compatibility for third-party spreadsheet libraries used in ZenTao PMS.
This commit is contained in:
liugang
2025-11-14 16:12:11 +08:00
parent 064a828d39
commit 89d59cdc6a
2 changed files with 384 additions and 0 deletions
@@ -114,6 +114,202 @@ index 81f481c3cdc..5b6315e9ac5 100644
* @return int
*/
- public function key()
+ public function key(): mixed
{
return $this->currentSheetIndex + 1;
}
diff --git a/vendor/box/spout/src/Spout/Reader/CSV/RowIterator.php b/vendor/box/spout/src/Spout/Reader/CSV/RowIterator.php
index 78e66501320..afef215101b 100644
--- a/vendor/box/spout/src/Spout/Reader/CSV/RowIterator.php
+++ b/vendor/box/spout/src/Spout/Reader/CSV/RowIterator.php
@@ -84,7 +84,7 @@ class RowIterator implements IteratorInterface
*
* @return void
*/
- public function rewind()
+ public function rewind(): void
{
$this->rewindAndSkipBom();
@@ -114,7 +114,7 @@ class RowIterator implements IteratorInterface
*
* @return bool
*/
- public function valid()
+ public function valid(): bool
{
return ($this->filePointer && !$this->hasReachedEndOfFile);
}
@@ -126,7 +126,7 @@ class RowIterator implements IteratorInterface
* @throws \Box\Spout\Common\Exception\EncodingConversionException If unable to convert data to UTF-8
* @return void
*/
- public function next()
+ public function next(): void
{
$this->hasReachedEndOfFile = $this->globalFunctionsHelper->feof($this->filePointer);
@@ -224,7 +224,7 @@ class RowIterator implements IteratorInterface
*
* @return Row|null
*/
- public function current()
+ public function current(): mixed
{
return $this->rowBuffer;
}
@@ -235,7 +235,7 @@ class RowIterator implements IteratorInterface
*
* @return int
*/
- public function key()
+ public function key(): mixed
{
return $this->numReadRows;
}
diff --git a/vendor/box/spout/src/Spout/Reader/CSV/SheetIterator.php b/vendor/box/spout/src/Spout/Reader/CSV/SheetIterator.php
index 69eb58a0ba9..31347ee6190 100644
--- a/vendor/box/spout/src/Spout/Reader/CSV/SheetIterator.php
+++ b/vendor/box/spout/src/Spout/Reader/CSV/SheetIterator.php
@@ -30,7 +30,7 @@ class SheetIterator implements IteratorInterface
*
* @return void
*/
- public function rewind()
+ public function rewind(): void
{
$this->hasReadUniqueSheet = false;
}
@@ -41,7 +41,7 @@ class SheetIterator implements IteratorInterface
*
* @return bool
*/
- public function valid()
+ public function valid(): bool
{
return (!$this->hasReadUniqueSheet);
}
@@ -52,7 +52,7 @@ class SheetIterator implements IteratorInterface
*
* @return void
*/
- public function next()
+ public function next(): void
{
$this->hasReadUniqueSheet = true;
}
@@ -63,7 +63,7 @@ class SheetIterator implements IteratorInterface
*
* @return \Box\Spout\Reader\CSV\Sheet
*/
- public function current()
+ public function current(): mixed
{
return $this->sheet;
}
@@ -74,7 +74,7 @@ class SheetIterator implements IteratorInterface
*
* @return int
*/
- public function key()
+ public function key(): mixed
{
return 1;
}
diff --git a/vendor/box/spout/src/Spout/Reader/ODS/RowIterator.php b/vendor/box/spout/src/Spout/Reader/ODS/RowIterator.php
index 81f0953d811..965275f0a19 100644
--- a/vendor/box/spout/src/Spout/Reader/ODS/RowIterator.php
+++ b/vendor/box/spout/src/Spout/Reader/ODS/RowIterator.php
@@ -118,7 +118,7 @@ class RowIterator implements IteratorInterface
* @throws \Box\Spout\Reader\Exception\IteratorNotRewindableException If the iterator is rewound more than once
* @return void
*/
- public function rewind()
+ public function rewind(): void
{
// Because sheet and row data is located in the file, we can't rewind both the
// sheet iterator and the row iterator, as XML file cannot be read backwards.
@@ -142,7 +142,7 @@ class RowIterator implements IteratorInterface
*
* @return bool
*/
- public function valid()
+ public function valid(): bool
{
return (!$this->hasReachedEndOfFile);
}
@@ -155,7 +155,7 @@ class RowIterator implements IteratorInterface
* @throws \Box\Spout\Common\Exception\IOException If unable to read the sheet data XML
* @return void
*/
- public function next()
+ public function next(): void
{
if ($this->doesNeedDataForNextRowToBeProcessed()) {
$this->readDataForNextRow();
@@ -356,7 +356,7 @@ class RowIterator implements IteratorInterface
*
* @return Row
*/
- public function current()
+ public function current(): mixed
{
return $this->rowBuffer;
}
@@ -367,7 +367,7 @@ class RowIterator implements IteratorInterface
*
* @return int
*/
- public function key()
+ public function key(): mixed
{
return $this->lastRowIndexProcessed;
}
diff --git a/vendor/box/spout/src/Spout/Reader/ODS/SheetIterator.php b/vendor/box/spout/src/Spout/Reader/ODS/SheetIterator.php
index c7b8cd9dcf8..5b3351fd1a9 100644
--- a/vendor/box/spout/src/Spout/Reader/ODS/SheetIterator.php
+++ b/vendor/box/spout/src/Spout/Reader/ODS/SheetIterator.php
@@ -79,7 +79,7 @@ class SheetIterator implements IteratorInterface
* @throws \Box\Spout\Common\Exception\IOException If unable to open the XML file containing sheets' data
* @return void
*/
- public function rewind()
+ public function rewind(): void
{
$this->xmlReader->close();
@@ -131,7 +131,7 @@ class SheetIterator implements IteratorInterface
*
* @return bool
*/
- public function valid()
+ public function valid(): bool
{
return $this->hasFoundSheet;
}
@@ -142,7 +142,7 @@ class SheetIterator implements IteratorInterface
*
* @return void
*/
- public function next()
+ public function next(): void
{
$this->hasFoundSheet = $this->xmlReader->readUntilNodeFound(self::XML_NODE_TABLE);
@@ -157,7 +157,7 @@ class SheetIterator implements IteratorInterface
*
* @return \Box\Spout\Reader\ODS\Sheet
*/
- public function current()
+ public function current(): mixed
{
$escapedSheetName = $this->xmlReader->getAttribute(self::XML_ATTRIBUTE_TABLE_NAME);
$sheetName = $this->escaper->unescape($escapedSheetName);
@@ -214,7 +214,7 @@ class SheetIterator implements IteratorInterface
*
* @return int
*/
- public function key()
+ public function key(): mixed
{
return $this->currentSheetIndex + 1;
@@ -45,3 +45,191 @@
{
return $this->position < $this->subject->getSheetCount() && $this->position >= 0;
}
--- a/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Worksheet/RowCellIterator.php
+++ b/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Worksheet/RowCellIterator.php
@@ -113,7 +113,7 @@ class RowCellIterator extends CellIterator
/**
* Rewind the iterator to the starting column.
*/
- public function rewind()
+ public function rewind(): void
{
$this->currentColumnIndex = $this->startColumnIndex;
}
@@ -123,7 +123,7 @@ class RowCellIterator extends CellIterator
*
* @return \PhpOffice\PhpSpreadsheet\Cell\Cell
*/
- public function current()
+ public function current(): mixed
{
return $this->worksheet->getCellByColumnAndRow($this->currentColumnIndex, $this->rowIndex);
}
@@ -133,7 +133,7 @@ class RowCellIterator extends CellIterator
*
* @return string
*/
- public function key()
+ public function key(): mixed
{
return Coordinate::stringFromColumnIndex($this->currentColumnIndex);
}
@@ -141,7 +141,7 @@ class RowCellIterator extends CellIterator
/**
* Set the iterator to its next value.
*/
- public function next()
+ public function next(): void
{
do {
++$this->currentColumnIndex;
@@ -165,7 +165,7 @@ class RowCellIterator extends CellIterator
*
* @return bool
*/
- public function valid()
+ public function valid(): bool
{
return $this->currentColumnIndex <= $this->endColumnIndex && $this->currentColumnIndex >= $this->startColumnIndex;
}
--- a/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Worksheet/RowIterator.php
+++ b/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Worksheet/RowIterator.php
@@ -117,7 +117,7 @@ class RowIterator implements \Iterator
/**
* Rewind the iterator to the starting row.
*/
- public function rewind()
+ public function rewind(): void
{
$this->position = $this->startRow;
}
@@ -127,7 +127,7 @@ class RowIterator implements \Iterator
*
* @return Row
*/
- public function current()
+ public function current(): mixed
{
return new Row($this->subject, $this->position);
}
@@ -137,7 +137,7 @@ class RowIterator implements \Iterator
*
* @return int
*/
- public function key()
+ public function key(): mixed
{
return $this->position;
}
@@ -145,7 +145,7 @@ class RowIterator implements \Iterator
/**
* Set the iterator to its next value.
*/
- public function next()
+ public function next(): void
{
++$this->position;
}
@@ -163,7 +163,7 @@ class RowIterator implements \Iterator
*
* @return bool
*/
- public function valid()
+ public function valid(): bool
{
return $this->position <= $this->endRow && $this->position >= $this->startRow;
}
--- a/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Worksheet/ColumnCellIterator.php
+++ b/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Worksheet/ColumnCellIterator.php
@@ -111,7 +111,7 @@ class ColumnCellIterator extends CellIterator
/**
* Rewind the iterator to the starting row.
*/
- public function rewind()
+ public function rewind(): void
{
$this->currentRow = $this->startRow;
}
@@ -121,7 +121,7 @@ class ColumnCellIterator extends CellIterator
*
* @return null|\PhpOffice\PhpSpreadsheet\Cell\Cell
*/
- public function current()
+ public function current(): mixed
{
return $this->worksheet->getCellByColumnAndRow($this->columnIndex, $this->currentRow);
}
@@ -131,7 +131,7 @@ class ColumnCellIterator extends CellIterator
*
* @return int
*/
- public function key()
+ public function key(): mixed
{
return $this->currentRow;
}
@@ -139,7 +139,7 @@ class ColumnCellIterator extends CellIterator
/**
* Set the iterator to its next value.
*/
- public function next()
+ public function next(): void
{
do {
++$this->currentRow;
@@ -165,7 +165,7 @@ class ColumnCellIterator extends CellIterator
*
* @return bool
*/
- public function valid()
+ public function valid(): bool
{
return $this->currentRow <= $this->endRow && $this->currentRow >= $this->startRow;
}
--- a/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Worksheet/ColumnIterator.php
+++ b/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Worksheet/ColumnIterator.php
@@ -122,7 +122,7 @@ class ColumnIterator implements \Iterator
/**
* Rewind the iterator to the starting column.
*/
- public function rewind()
+ public function rewind(): void
{
$this->currentColumnIndex = $this->startColumnIndex;
}
@@ -132,7 +132,7 @@ class ColumnIterator implements \Iterator
*
* @return Column
*/
- public function current()
+ public function current(): mixed
{
return new Column($this->worksheet, Coordinate::stringFromColumnIndex($this->currentColumnIndex));
}
@@ -142,7 +142,7 @@ class ColumnIterator implements \Iterator
*
* @return string
*/
- public function key()
+ public function key(): mixed
{
return Coordinate::stringFromColumnIndex($this->currentColumnIndex);
}
@@ -150,7 +150,7 @@ class ColumnIterator implements \Iterator
/**
* Set the iterator to its next value.
*/
- public function next()
+ public function next(): void
{
++$this->currentColumnIndex;
}
@@ -168,7 +168,7 @@ class ColumnIterator implements \Iterator
*
* @return bool
*/
- public function valid()
+ public function valid(): bool
{
return $this->currentColumnIndex <= $this->endColumnIndex && $this->currentColumnIndex >= $this->startColumnIndex;
}