Shared strings table without uniqueCount and count should work
Use file based strategy in this case
This commit is contained in:
parent
ffea8871a6
commit
f73db4b95c
@ -78,7 +78,7 @@ class CachingStrategyFactory
|
|||||||
* Returns the best caching strategy, given the number of unique shared strings
|
* Returns the best caching strategy, given the number of unique shared strings
|
||||||
* and the amount of memory available.
|
* and the amount of memory available.
|
||||||
*
|
*
|
||||||
* @param int $sharedStringsUniqueCount Number of unique shared strings
|
* @param int|null $sharedStringsUniqueCount Number of unique shared strings (NULL if unknown)
|
||||||
* @param string|void $tempFolder Temporary folder where the temporary files to store shared strings will be stored
|
* @param string|void $tempFolder Temporary folder where the temporary files to store shared strings will be stored
|
||||||
* @return CachingStrategyInterface The best caching strategy
|
* @return CachingStrategyInterface The best caching strategy
|
||||||
*/
|
*/
|
||||||
@ -95,11 +95,16 @@ class CachingStrategyFactory
|
|||||||
* Returns whether it is safe to use in-memory caching, given the number of unique shared strings
|
* Returns whether it is safe to use in-memory caching, given the number of unique shared strings
|
||||||
* and the amount of memory available.
|
* and the amount of memory available.
|
||||||
*
|
*
|
||||||
* @param int $sharedStringsUniqueCount Number of unique shared strings
|
* @param int|null $sharedStringsUniqueCount Number of unique shared strings (NULL if unknown)
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function isInMemoryStrategyUsageSafe($sharedStringsUniqueCount)
|
protected function isInMemoryStrategyUsageSafe($sharedStringsUniqueCount)
|
||||||
{
|
{
|
||||||
|
// if the number of shared strings in unknown, do not use "in memory" strategy
|
||||||
|
if ($sharedStringsUniqueCount === null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$memoryAvailable = $this->getMemoryLimitInKB();
|
$memoryAvailable = $this->getMemoryLimitInKB();
|
||||||
|
|
||||||
if ($memoryAvailable === -1) {
|
if ($memoryAvailable === -1) {
|
||||||
|
@ -147,7 +147,7 @@ class SharedStringsHelper
|
|||||||
* Returns the shared strings unique count, as specified in <sst> tag.
|
* Returns the shared strings unique count, as specified in <sst> tag.
|
||||||
*
|
*
|
||||||
* @param \Box\Spout\Reader\Wrapper\XMLReader $xmlReader XMLReader instance
|
* @param \Box\Spout\Reader\Wrapper\XMLReader $xmlReader XMLReader instance
|
||||||
* @return int Number of unique shared strings in the sharedStrings.xml file
|
* @return int|null Number of unique shared strings in the sharedStrings.xml file
|
||||||
* @throws \Box\Spout\Common\Exception\IOException If sharedStrings.xml is invalid and can't be read
|
* @throws \Box\Spout\Common\Exception\IOException If sharedStrings.xml is invalid and can't be read
|
||||||
*/
|
*/
|
||||||
protected function getSharedStringsUniqueCount($xmlReader)
|
protected function getSharedStringsUniqueCount($xmlReader)
|
||||||
@ -167,13 +167,13 @@ class SharedStringsHelper
|
|||||||
$uniqueCount = $xmlReader->getAttribute('count');
|
$uniqueCount = $xmlReader->getAttribute('count');
|
||||||
}
|
}
|
||||||
|
|
||||||
return intval($uniqueCount);
|
return ($uniqueCount !== null) ? intval($uniqueCount) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the best shared strings caching strategy.
|
* Returns the best shared strings caching strategy.
|
||||||
*
|
*
|
||||||
* @param int $sharedStringsUniqueCount
|
* @param int|null $sharedStringsUniqueCount Number of unique shared strings (NULL if unknown)
|
||||||
* @return CachingStrategyInterface
|
* @return CachingStrategyInterface
|
||||||
*/
|
*/
|
||||||
protected function getBestSharedStringsCachingStrategy($sharedStringsUniqueCount)
|
protected function getBestSharedStringsCachingStrategy($sharedStringsUniqueCount)
|
||||||
|
@ -15,6 +15,7 @@ class CachingStrategyFactoryTest extends \PHPUnit_Framework_TestCase
|
|||||||
public function dataProviderForTestGetBestCachingStrategy()
|
public function dataProviderForTestGetBestCachingStrategy()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
[null, -1, 'FileBasedStrategy'],
|
||||||
[CachingStrategyFactory::MAX_NUM_STRINGS_PER_TEMP_FILE, -1, 'FileBasedStrategy'],
|
[CachingStrategyFactory::MAX_NUM_STRINGS_PER_TEMP_FILE, -1, 'FileBasedStrategy'],
|
||||||
[CachingStrategyFactory::MAX_NUM_STRINGS_PER_TEMP_FILE + 10, -1, 'FileBasedStrategy'],
|
[CachingStrategyFactory::MAX_NUM_STRINGS_PER_TEMP_FILE + 10, -1, 'FileBasedStrategy'],
|
||||||
[CachingStrategyFactory::MAX_NUM_STRINGS_PER_TEMP_FILE - 10, -1, 'InMemoryStrategy'],
|
[CachingStrategyFactory::MAX_NUM_STRINGS_PER_TEMP_FILE - 10, -1, 'InMemoryStrategy'],
|
||||||
@ -27,7 +28,7 @@ class CachingStrategyFactoryTest extends \PHPUnit_Framework_TestCase
|
|||||||
/**
|
/**
|
||||||
* @dataProvider dataProviderForTestGetBestCachingStrategy
|
* @dataProvider dataProviderForTestGetBestCachingStrategy
|
||||||
*
|
*
|
||||||
* @param int $sharedStringsUniqueCount
|
* @param int|null $sharedStringsUniqueCount
|
||||||
* @param int $memoryLimitInKB
|
* @param int $memoryLimitInKB
|
||||||
* @param string $expectedStrategyClassName
|
* @param string $expectedStrategyClassName
|
||||||
* @return void
|
* @return void
|
||||||
|
@ -126,6 +126,20 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($expectedRows, $allRows);
|
$this->assertEquals($expectedRows, $allRows);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testReadShouldSupportSheetWithSharedStringsMissingUniqueCountAndCountAttributes()
|
||||||
|
{
|
||||||
|
$allRows = $this->getAllRowsForFile('one_sheet_with_shared_strings_missing_unique_count_and_count.xlsx');
|
||||||
|
|
||||||
|
$expectedRows = [
|
||||||
|
['s1--A1', 's1--B1'],
|
||||||
|
['s1--A2', 's1--B2'],
|
||||||
|
];
|
||||||
|
$this->assertEquals($expectedRows, $allRows);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user