MDL-78247 libraries: upgrade to version 4.15.0 of OpenSpout.

This commit is contained in:
Paul Holden 2023-06-05 17:22:37 +01:00
parent 3cd84747cb
commit 8a842b9cbd
No known key found for this signature in database
GPG Key ID: A81A96D6045F6164
26 changed files with 79 additions and 85 deletions

View File

@ -3,7 +3,7 @@
[![Latest Stable Version](https://poser.pugx.org/openspout/openspout/v/stable)](https://packagist.org/packages/openspout/openspout)
[![Total Downloads](https://poser.pugx.org/openspout/openspout/downloads)](https://packagist.org/packages/openspout/openspout)
[![Build Status](https://github.com/openspout/openspout/actions/workflows/ci.yml/badge.svg)](https://github.com/openspout/openspout/actions/workflows/ci.yml)
[![Infection MSI](https://badge.stryker-mutator.io/github.com/openspout/openspout/4.x)](https://dashboard.stryker-mutator.io/reports/github.com/openspout/openspout/4.x)
[![Infection MSI](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fopenspout%2Fopenspout%2F4.x)](https://dashboard.stryker-mutator.io/reports/github.com/openspout/openspout/4.x)
OpenSpout is a community driven fork of `box/spout`, a PHP library to read and write spreadsheet files
(CSV, XLSX and ODS), in a fast and scalable way. Unlike other file readers or writers, it is capable of processing

View File

@ -183,7 +183,7 @@ final class EncodingHelper
$convertedString = false;
}
} else {
throw new EncodingConversionException("The conversion from {$sourceEncoding} to {$targetEncoding} is not supported. Please install \"iconv\" or \"PHP Intl\".");
throw new EncodingConversionException("The conversion from {$sourceEncoding} to {$targetEncoding} is not supported. Please install \"iconv\" or \"mbstring\".");
}
if (false === $convertedString) {

View File

@ -33,8 +33,7 @@ final class StringHelper
{
return $this->hasMbstringSupport
? mb_strlen($string)
: \strlen($string) // @codeCoverageIgnore
;
: \strlen($string); // @codeCoverageIgnore
}
/**
@ -53,8 +52,7 @@ final class StringHelper
{
$position = $this->hasMbstringSupport
? mb_strpos($string, $char)
: strpos($string, $char) // @codeCoverageIgnore
;
: strpos($string, $char); // @codeCoverageIgnore
return (false !== $position) ? $position : -1;
}
@ -75,8 +73,7 @@ final class StringHelper
{
$position = $this->hasMbstringSupport
? mb_strrpos($string, $char)
: strrpos($string, $char) // @codeCoverageIgnore
;
: strrpos($string, $char); // @codeCoverageIgnore
return (false !== $position) ? $position : -1;
}

View File

@ -158,8 +158,7 @@ final class RowIterator implements RowIteratorInterface
return
(!$hasSuccessfullyFetchedRowData && !$hasNowReachedEndOfFile)
|| (!$this->options->SHOULD_PRESERVE_EMPTY_ROWS && $isEmptyLine)
;
|| (!$this->options->SHOULD_PRESERVE_EMPTY_ROWS && $isEmptyLine);
}
/**

View File

@ -172,8 +172,7 @@ final class RowIterator implements RowIteratorInterface
return
!$hasReadAtLeastOneRow
|| $this->lastRowIndexProcessed === $this->nextRowIndexToBeProcessed - 1
;
|| $this->lastRowIndexProcessed === $this->nextRowIndexToBeProcessed - 1;
}
/**
@ -337,7 +336,6 @@ final class RowIterator implements RowIteratorInterface
{
return
$currentRow->isEmpty()
&& (null === $lastReadCell || $lastReadCell instanceof Cell\EmptyCell)
;
&& (null === $lastReadCell || $lastReadCell instanceof Cell\EmptyCell);
}
}

View File

@ -210,8 +210,7 @@ final class SheetIterator implements SheetIteratorInterface
// or if no information about the active sheet was found, it defaults to the first sheet.
return
(null === $activeSheetName && 0 === $sheetIndex)
|| ($activeSheetName === $sheetName)
;
|| ($activeSheetName === $sheetName);
}
/**

View File

@ -226,8 +226,7 @@ final class CellValueFormatter
// @NOTE: some versions of Excel don't support negative dates (e.g. Excel for Mac 2011)
return
$this->shouldUse1904Dates && $timestampValue >= -695055 && $timestampValue <= 2957003.9999884
|| !$this->shouldUse1904Dates && $timestampValue >= -693593 && $timestampValue <= 2958465.9999884
;
|| !$this->shouldUse1904Dates && $timestampValue >= -693593 && $timestampValue <= 2958465.9999884;
}
/**

View File

@ -7,7 +7,7 @@ namespace OpenSpout\Reader\XLSX\Manager\SharedStringsCaching;
/**
* @internal
*/
final class CachingStrategyFactory
final class CachingStrategyFactory implements CachingStrategyFactoryInterface
{
/**
* The memory amount needed to store a string was obtained empirically from this data:.

View File

@ -0,0 +1,19 @@
<?php
declare(strict_types=1);
namespace OpenSpout\Reader\XLSX\Manager\SharedStringsCaching;
interface CachingStrategyFactoryInterface
{
/**
* Returns the best caching strategy, given the number of unique shared strings
* and the amount of memory available.
*
* @param null|int $sharedStringsUniqueCount Number of unique shared strings (NULL if unknown)
* @param string $tempFolder Temporary folder where the temporary files to store shared strings will be stored
*
* @return CachingStrategyInterface The best caching strategy
*/
public function createBestCachingStrategy(?int $sharedStringsUniqueCount, string $tempFolder): CachingStrategyInterface;
}

View File

@ -164,7 +164,7 @@ final class FileBasedStrategy implements CachingStrategyInterface
{
$numTempFile = (int) ($sharedStringIndex / $this->maxNumStringsPerTempFile);
return $this->tempFolder.'/sharedstrings'.$numTempFile;
return $this->tempFolder.\DIRECTORY_SEPARATOR.'sharedstrings'.$numTempFile;
}
/**

View File

@ -8,7 +8,7 @@ use DOMElement;
use OpenSpout\Common\Exception\IOException;
use OpenSpout\Reader\Exception\XMLProcessingException;
use OpenSpout\Reader\Wrapper\XMLReader;
use OpenSpout\Reader\XLSX\Manager\SharedStringsCaching\CachingStrategyFactory;
use OpenSpout\Reader\XLSX\Manager\SharedStringsCaching\CachingStrategyFactoryInterface;
use OpenSpout\Reader\XLSX\Manager\SharedStringsCaching\CachingStrategyInterface;
use OpenSpout\Reader\XLSX\Options;
@ -41,8 +41,8 @@ final class SharedStringsManager
/** @var WorkbookRelationshipsManager Helps retrieving workbook relationships */
private WorkbookRelationshipsManager $workbookRelationshipsManager;
/** @var CachingStrategyFactory Factory to create shared strings caching strategies */
private CachingStrategyFactory $cachingStrategyFactory;
/** @var CachingStrategyFactoryInterface Factory to create shared strings caching strategies */
private CachingStrategyFactoryInterface $cachingStrategyFactory;
/** @var CachingStrategyInterface The best caching strategy for storing shared strings */
private CachingStrategyInterface $cachingStrategy;
@ -51,7 +51,7 @@ final class SharedStringsManager
string $filePath,
Options $options,
WorkbookRelationshipsManager $workbookRelationshipsManager,
CachingStrategyFactory $cachingStrategyFactory
CachingStrategyFactoryInterface $cachingStrategyFactory
) {
$this->filePath = $filePath;
$this->options = $options;
@ -199,8 +199,7 @@ final class SharedStringsManager
$sharedStringValue .= $shouldPreserveWhitespace
? $textNodeValue
: trim($textNodeValue)
;
: trim($textNodeValue);
}
}

View File

@ -8,6 +8,7 @@ use OpenSpout\Common\Exception\IOException;
use OpenSpout\Common\Helper\Escaper\XLSX;
use OpenSpout\Reader\AbstractReader;
use OpenSpout\Reader\XLSX\Manager\SharedStringsCaching\CachingStrategyFactory;
use OpenSpout\Reader\XLSX\Manager\SharedStringsCaching\CachingStrategyFactoryInterface;
use OpenSpout\Reader\XLSX\Manager\SharedStringsCaching\MemoryLimit;
use OpenSpout\Reader\XLSX\Manager\SharedStringsManager;
use OpenSpout\Reader\XLSX\Manager\SheetManager;
@ -28,18 +29,16 @@ final class Reader extends AbstractReader
private SheetIterator $sheetIterator;
private Options $options;
private CachingStrategyFactory $cachingStrategyFactory;
private CachingStrategyFactoryInterface $cachingStrategyFactory;
public function __construct(
?Options $options = null,
?CachingStrategyFactory $cachingStrategyFactory = null
?CachingStrategyFactoryInterface $cachingStrategyFactory = null
) {
$this->options = $options ?? new Options();
if (null === $cachingStrategyFactory) {
$memoryLimit = \ini_get('memory_limit');
\assert(false !== $memoryLimit);
$cachingStrategyFactory = new CachingStrategyFactory(new MemoryLimit($memoryLimit));
}
$this->cachingStrategyFactory = $cachingStrategyFactory;

View File

@ -247,8 +247,7 @@ final class RowIterator implements RowIteratorInterface
return
!$hasReadAtLeastOneRow
|| !$this->shouldPreserveEmptyRows
|| $this->lastRowIndexProcessed < $this->nextRowIndexToBeProcessed
;
|| $this->lastRowIndexProcessed < $this->nextRowIndexToBeProcessed;
}
/**
@ -297,7 +296,7 @@ final class RowIterator implements RowIteratorInterface
// Read spans info if present
$numberOfColumnsForRow = $this->numColumns;
$spans = $xmlReader->getAttribute(self::XML_ATTRIBUTE_SPANS); // returns '1:5' for instance
if (null !== $spans) {
if (null !== $spans && '' !== $spans) {
[, $numberOfColumnsForRow] = explode(':', $spans);
$numberOfColumnsForRow = (int) $numberOfColumnsForRow;
}
@ -367,7 +366,7 @@ final class RowIterator implements RowIteratorInterface
*
* @return int Row index
*
*@throws \OpenSpout\Common\Exception\InvalidArgumentException When the given cell index is invalid
* @throws \OpenSpout\Common\Exception\InvalidArgumentException When the given cell index is invalid
*/
private function getRowIndex(XMLReader $xmlReader): int
{
@ -384,7 +383,7 @@ final class RowIterator implements RowIteratorInterface
*
* @return int Column index
*
*@throws \OpenSpout\Common\Exception\InvalidArgumentException When the given cell index is invalid
* @throws \OpenSpout\Common\Exception\InvalidArgumentException When the given cell index is invalid
*/
private function getColumnIndex(XMLReader $xmlReader): int
{

View File

@ -13,6 +13,9 @@ abstract class AbstractWriter implements WriterInterface
/** @var resource Pointer to the file/stream we will write to */
protected $filePointer;
/** @var string document creator */
protected string $creator = 'OpenSpout';
/** @var string Content-Type value for the header - to be defined by child class */
protected static string $headerContentType;
@ -25,9 +28,6 @@ abstract class AbstractWriter implements WriterInterface
/** @var 0|positive-int */
private int $writtenRowCount = 0;
/**
* {@inheritdoc}
*/
final public function openToFile($outputFilePath): void
{
$this->outputFilePath = $outputFilePath;
@ -53,7 +53,8 @@ abstract class AbstractWriter implements WriterInterface
/**
* @codeCoverageIgnore
* {@inheritdoc}
*
* @param mixed $outputFileName
*/
final public function openToBrowser($outputFileName): void
{
@ -104,9 +105,6 @@ abstract class AbstractWriter implements WriterInterface
$this->isWriterOpened = true;
}
/**
* {@inheritdoc}
*/
final public function addRow(Row $row): void
{
if (!$this->isWriterOpened) {
@ -117,9 +115,6 @@ abstract class AbstractWriter implements WriterInterface
++$this->writtenRowCount;
}
/**
* {@inheritdoc}
*/
final public function addRows(array $rows): void
{
foreach ($rows as $row) {
@ -127,17 +122,16 @@ abstract class AbstractWriter implements WriterInterface
}
}
/**
* {@inheritdoc}
*/
final public function setCreator(string $creator): void
{
$this->creator = $creator;
}
final public function getWrittenRowCount(): int
{
return $this->writtenRowCount;
}
/**
* {@inheritdoc}
*/
final public function close(): void
{
if (!$this->isWriterOpened) {

View File

@ -83,9 +83,6 @@ abstract class AbstractWriterMultiSheets extends AbstractWriter
abstract protected function createWorkbookManager(): WorkbookManagerInterface;
/**
* {@inheritdoc}
*/
protected function openWriter(): void
{
if (!isset($this->workbookManager)) {
@ -95,8 +92,6 @@ abstract class AbstractWriterMultiSheets extends AbstractWriter
}
/**
* {@inheritdoc}
*
* @throws Exception\WriterException
*/
protected function addRowToWriter(Row $row): void
@ -105,9 +100,6 @@ abstract class AbstractWriterMultiSheets extends AbstractWriter
$this->workbookManager->addRowToCurrentWorksheet($row);
}
/**
* {@inheritdoc}
*/
protected function closeWriter(): void
{
if (isset($this->workbookManager)) {

View File

@ -7,7 +7,6 @@ namespace OpenSpout\Writer\Common\Manager;
use OpenSpout\Common\Entity\Row;
use OpenSpout\Common\Exception\IOException;
use OpenSpout\Writer\Common\Entity\Sheet;
use OpenSpout\Writer\Common\Entity\Workbook;
use OpenSpout\Writer\Common\Entity\Worksheet;
use OpenSpout\Writer\Exception\SheetNotFoundException;
use OpenSpout\Writer\Exception\WriterException;

View File

@ -17,7 +17,6 @@ use OpenSpout\Writer\ODS\Manager\WorksheetManager;
*/
final class FileSystemHelper implements FileSystemWithRootFolderHelperInterface
{
public const APP_NAME = 'OpenSpout';
public const MIMETYPE = 'application/vnd.oasis.opendocument.spreadsheet';
public const META_INF_FOLDER_NAME = 'META-INF';
@ -29,6 +28,9 @@ final class FileSystemHelper implements FileSystemWithRootFolderHelperInterface
public const STYLES_XML_FILE_NAME = 'styles.xml';
private string $baseFolderRealPath;
/** @var string document creator */
private string $creator;
private CommonFileSystemHelper $baseFileSystemHelper;
/** @var string Path to the root folder inside the temp folder where the files to create the ODS will be stored */
@ -46,12 +48,14 @@ final class FileSystemHelper implements FileSystemWithRootFolderHelperInterface
/**
* @param string $baseFolderPath The path of the base folder where all the I/O can occur
* @param ZipHelper $zipHelper Helper to perform tasks with Zip archive
* @param string $creator document creator
*/
public function __construct(string $baseFolderPath, ZipHelper $zipHelper)
public function __construct(string $baseFolderPath, ZipHelper $zipHelper, string $creator)
{
$this->baseFileSystemHelper = new CommonFileSystemHelper($baseFolderPath);
$this->baseFolderRealPath = $this->baseFileSystemHelper->getBaseFolderRealPath();
$this->zipHelper = $zipHelper;
$this->creator = $creator;
}
public function createFolder(string $parentFolderPath, string $folderName): string
@ -275,14 +279,13 @@ final class FileSystemHelper implements FileSystemWithRootFolderHelperInterface
*/
private function createMetaFile(): self
{
$appName = self::APP_NAME;
$createdDate = (new DateTimeImmutable())->format(DateTimeImmutable::W3C);
$metaXmlFileContents = <<<EOD
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<office:document-meta office:version="1.2" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:xlink="http://www.w3.org/1999/xlink">
<office:meta>
<dc:creator>{$appName}</dc:creator>
<dc:creator>{$this->creator}</dc:creator>
<meta:creation-date>{$createdDate}</meta:creation-date>
<dc:date>{$createdDate}</dc:date>
</office:meta>

View File

@ -4,7 +4,6 @@ declare(strict_types=1);
namespace OpenSpout\Writer\ODS\Manager;
use OpenSpout\Writer\Common\Entity\Sheet;
use OpenSpout\Writer\Common\Entity\Workbook;
use OpenSpout\Writer\Common\Manager\AbstractWorkbookManager;
use OpenSpout\Writer\Common\Manager\Style\StyleMerger;

View File

@ -35,7 +35,7 @@ final class Writer extends AbstractWriterMultiSheets
{
$workbook = new Workbook();
$fileSystemHelper = new FileSystemHelper($this->options->getTempFolder(), new ZipHelper());
$fileSystemHelper = new FileSystemHelper($this->options->getTempFolder(), new ZipHelper(), $this->creator);
$fileSystemHelper->createBaseFilesAndFolders();
$styleMerger = new StyleMerger();

View File

@ -49,6 +49,13 @@ interface WriterInterface
*/
public function addRows(array $rows): void;
/**
* Set document creator.
*
* @param string $creator document creator
*/
public function setCreator(string $creator): void;
/**
* @return 0|positive-int
*/

View File

@ -48,8 +48,7 @@ final class DateHelper
+ $day
+ 1721119
- $myexcelBaseDate
+ $excel1900isLeapYear
;
+ $excel1900isLeapYear;
$excelTime = (($hours * 3600) + ($minutes * 60) + $seconds) / 86400;

View File

@ -21,8 +21,6 @@ use OpenSpout\Writer\XLSX\Options;
*/
final class FileSystemHelper implements FileSystemWithRootFolderHelperInterface
{
public const APP_NAME = 'OpenSpout';
public const RELS_FOLDER_NAME = '_rels';
public const DRAWINGS_FOLDER_NAME = 'drawings';
public const DOC_PROPS_FOLDER_NAME = 'docProps';
@ -48,6 +46,9 @@ final class FileSystemHelper implements FileSystemWithRootFolderHelperInterface
/** @var ZipHelper Helper to perform tasks with Zip archive */
private ZipHelper $zipHelper;
/** @var string document creator */
private string $creator;
/** @var XLSX Used to escape XML data */
private XLSX $escaper;
@ -76,13 +77,15 @@ final class FileSystemHelper implements FileSystemWithRootFolderHelperInterface
* @param string $baseFolderPath The path of the base folder where all the I/O can occur
* @param ZipHelper $zipHelper Helper to perform tasks with Zip archive
* @param XLSX $escaper Used to escape XML data
* @param string $creator document creator
*/
public function __construct(string $baseFolderPath, ZipHelper $zipHelper, XLSX $escaper)
public function __construct(string $baseFolderPath, ZipHelper $zipHelper, XLSX $escaper, string $creator)
{
$this->baseFileSystemHelper = new CommonFileSystemHelper($baseFolderPath);
$this->baseFolderRealPath = $this->baseFileSystemHelper->getBaseFolderRealPath();
$this->zipHelper = $zipHelper;
$this->escaper = $escaper;
$this->creator = $creator;
}
public function createFolder(string $parentFolderPath, string $folderName): string
@ -516,11 +519,10 @@ final class FileSystemHelper implements FileSystemWithRootFolderHelperInterface
*/
private function createAppXmlFile(): self
{
$appName = self::APP_NAME;
$appXmlFileContents = <<<EOD
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties">
<Application>{$appName}</Application>
<Application>{$this->creator}</Application>
<TotalTime>0</TotalTime>
</Properties>
EOD;

View File

@ -4,7 +4,6 @@ declare(strict_types=1);
namespace OpenSpout\Writer\XLSX\Manager;
use OpenSpout\Writer\Common\Entity\Sheet;
use OpenSpout\Writer\Common\Entity\Workbook;
use OpenSpout\Writer\Common\Manager\AbstractWorkbookManager;
use OpenSpout\Writer\Common\Manager\Style\StyleMerger;

View File

@ -80,9 +80,6 @@ final class WorksheetManager implements WorksheetManagerInterface
return $this->sharedStringsManager;
}
/**
* {@inheritdoc}
*/
public function startSheet(Worksheet $worksheet): void
{
$sheetFilePointer = fopen($worksheet->getFilePath(), 'w');
@ -92,9 +89,6 @@ final class WorksheetManager implements WorksheetManagerInterface
$this->commentsManager->createWorksheetCommentFiles($worksheet);
}
/**
* {@inheritdoc}
*/
public function addRow(Worksheet $worksheet, Row $row): void
{
if (!$row->isEmpty()) {
@ -105,9 +99,6 @@ final class WorksheetManager implements WorksheetManagerInterface
$worksheet->setLastWrittenRowIndex($worksheet->getLastWrittenRowIndex() + 1);
}
/**
* {@inheritdoc}
*/
public function close(Worksheet $worksheet): void
{
$this->commentsManager->closeWorksheetCommentFiles($worksheet);

View File

@ -42,7 +42,8 @@ final class Writer extends AbstractWriterMultiSheets
$fileSystemHelper = new FileSystemHelper(
$this->options->getTempFolder(),
new ZipHelper(),
new XLSX()
new XLSX(),
$this->creator
);
$fileSystemHelper->createBaseFilesAndFolders();

View File

@ -377,7 +377,7 @@ All rights reserved.</copyright>
<location>openspout</location>
<name>OpenSpout</name>
<description>Library to read and write spreadsheet files (CSV, XLSX and ODS).</description>
<version>4.13.0</version>
<version>4.15.0</version>
<license>MIT</license>
<repository>https://github.com/openspout/openspout</repository>
<copyrights>