Fix coding style
This commit is contained in:
parent
abddc0b48f
commit
956056511a
@ -23,18 +23,18 @@ class GlobalFunctionsHelper
|
|||||||
return fopen($fileName, $mode);
|
return fopen($fileName, $mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper around global function fread()
|
* Wrapper around global function fread()
|
||||||
* @see fread()
|
* @see fread()
|
||||||
*
|
*
|
||||||
* @param resource $handle
|
* @param resource $handle
|
||||||
* @param int|null $length
|
* @param int|null $length
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function fread($handle, $length = null)
|
public function fread($handle, $length = null)
|
||||||
{
|
{
|
||||||
return fread($handle, $length);
|
return fread($handle, $length);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper around global function fgets()
|
* Wrapper around global function fgets()
|
||||||
@ -88,17 +88,17 @@ class GlobalFunctionsHelper
|
|||||||
return fseek($handle, $offset, $whence);
|
return fseek($handle, $offset, $whence);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper around global function ftell()
|
* Wrapper around global function ftell()
|
||||||
* @see fseek()
|
* @see fseek()
|
||||||
*
|
*
|
||||||
* @param resource $handle
|
* @param resource $handle
|
||||||
* @return bool|int
|
* @return bool|int
|
||||||
*/
|
*/
|
||||||
public function ftell($handle)
|
public function ftell($handle)
|
||||||
{
|
{
|
||||||
return ftell($handle);
|
return ftell($handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper around global function fgetcsv()
|
* Wrapper around global function fgetcsv()
|
||||||
|
@ -17,8 +17,8 @@ class FileBasedStrategy implements CachingStrategyInterface
|
|||||||
/** Value to use to escape the line feed character ("\n") */
|
/** Value to use to escape the line feed character ("\n") */
|
||||||
const ESCAPED_LINE_FEED_CHARACTER = '_x000A_';
|
const ESCAPED_LINE_FEED_CHARACTER = '_x000A_';
|
||||||
|
|
||||||
/** Index entry size uint32 for offset and uint16 for length */
|
/** Index entry size uint32 for offset and uint16 for length */
|
||||||
const INDEX_ENTRY_SIZE = 6;
|
const INDEX_ENTRY_SIZE = 6;
|
||||||
|
|
||||||
/** @var \Box\Spout\Common\Helper\GlobalFunctionsHelper Helper to work with global functions */
|
/** @var \Box\Spout\Common\Helper\GlobalFunctionsHelper Helper to work with global functions */
|
||||||
protected $globalFunctionsHelper;
|
protected $globalFunctionsHelper;
|
||||||
@ -54,26 +54,27 @@ class FileBasedStrategy implements CachingStrategyInterface
|
|||||||
$this->tempFilePointers = [];
|
$this->tempFilePointers = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open file with cache
|
* Open file with cache
|
||||||
*
|
*
|
||||||
* @param string $tempFilePath filename with shared strings
|
* @param string $tempFilePath filename with shared strings
|
||||||
*/
|
*/
|
||||||
private function openCache($tempFilePath) {
|
private function openCache($tempFilePath)
|
||||||
if (!array_key_exists($tempFilePath, $this->tempFilePointers)) {
|
{
|
||||||
// Open index file and seek to end
|
if (!array_key_exists($tempFilePath, $this->tempFilePointers)) {
|
||||||
$index = $this->globalFunctionsHelper->fopen($tempFilePath . '.index', 'c+');
|
// Open index file and seek to end
|
||||||
$this->globalFunctionsHelper->fseek($index, 0, SEEK_END);
|
$index = $this->globalFunctionsHelper->fopen($tempFilePath . '.index', 'c+');
|
||||||
|
$this->globalFunctionsHelper->fseek($index, 0, SEEK_END);
|
||||||
|
|
||||||
// Open data file and seek to end
|
// Open data file and seek to end
|
||||||
$data = $this->globalFunctionsHelper->fopen($tempFilePath, 'c+');
|
$data = $this->globalFunctionsHelper->fopen($tempFilePath, 'c+');
|
||||||
$this->globalFunctionsHelper->fseek($data, 0, SEEK_END);
|
$this->globalFunctionsHelper->fseek($data, 0, SEEK_END);
|
||||||
|
|
||||||
$this->tempFilePointers[$tempFilePath] = [$index, $data];
|
$this->tempFilePointers[$tempFilePath] = [$index, $data];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->tempFilePointers[$tempFilePath];
|
return $this->tempFilePointers[$tempFilePath];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the given string to the cache.
|
* Adds the given string to the cache.
|
||||||
@ -92,7 +93,7 @@ class FileBasedStrategy implements CachingStrategyInterface
|
|||||||
// Encoding the line feed character allows to preserve this assumption
|
// Encoding the line feed character allows to preserve this assumption
|
||||||
$lineFeedEncodedSharedString = $this->escapeLineFeed($sharedString);
|
$lineFeedEncodedSharedString = $this->escapeLineFeed($sharedString);
|
||||||
|
|
||||||
$this->globalFunctionsHelper->fwrite($index, pack('Nn', $this->globalFunctionsHelper->ftell($data), strlen($lineFeedEncodedSharedString) + strlen(PHP_EOL)));
|
$this->globalFunctionsHelper->fwrite($index, pack('Nn', $this->globalFunctionsHelper->ftell($data), strlen($lineFeedEncodedSharedString) + strlen(PHP_EOL)));
|
||||||
$this->globalFunctionsHelper->fwrite($data, $lineFeedEncodedSharedString . PHP_EOL);
|
$this->globalFunctionsHelper->fwrite($data, $lineFeedEncodedSharedString . PHP_EOL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,12 +120,12 @@ class FileBasedStrategy implements CachingStrategyInterface
|
|||||||
{
|
{
|
||||||
// close pointer to the last temp file that was written
|
// close pointer to the last temp file that was written
|
||||||
if (!empty($this->tempFilePointers)) {
|
if (!empty($this->tempFilePointers)) {
|
||||||
foreach ($this->tempFilePointers as $pointer) {
|
foreach ($this->tempFilePointers as $pointer) {
|
||||||
$this->globalFunctionsHelper->fclose($pointer[0]);
|
$this->globalFunctionsHelper->fclose($pointer[0]);
|
||||||
$this->globalFunctionsHelper->fclose($pointer[1]);
|
$this->globalFunctionsHelper->fclose($pointer[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->tempFilePointers = [];
|
$this->tempFilePointers = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -146,16 +147,16 @@ class FileBasedStrategy implements CachingStrategyInterface
|
|||||||
list($index, $data) = $this->openCache($tempFilePath);
|
list($index, $data) = $this->openCache($tempFilePath);
|
||||||
|
|
||||||
// Read index entry
|
// Read index entry
|
||||||
$this->globalFunctionsHelper->fseek($index, $indexInFile * self::INDEX_ENTRY_SIZE);
|
$this->globalFunctionsHelper->fseek($index, $indexInFile * self::INDEX_ENTRY_SIZE);
|
||||||
$indexEntryBytes = $this->globalFunctionsHelper->fread($index, self::INDEX_ENTRY_SIZE);
|
$indexEntryBytes = $this->globalFunctionsHelper->fread($index, self::INDEX_ENTRY_SIZE);
|
||||||
$indexEntry = unpack('Noffset/nlen', $indexEntryBytes);
|
$indexEntry = unpack('Noffset/nlen', $indexEntryBytes);
|
||||||
|
|
||||||
$sharedString = null;
|
$sharedString = null;
|
||||||
if ($indexEntry['offset'] + $indexEntry['len'] <= filesize($tempFilePath)) {
|
if ($indexEntry['offset'] + $indexEntry['len'] <= filesize($tempFilePath)) {
|
||||||
$this->globalFunctionsHelper->fseek($data, $indexEntry['offset']);
|
$this->globalFunctionsHelper->fseek($data, $indexEntry['offset']);
|
||||||
$escapedSharedString = $this->globalFunctionsHelper->fread($data, $indexEntry['len']);
|
$escapedSharedString = $this->globalFunctionsHelper->fread($data, $indexEntry['len']);
|
||||||
$sharedString = $this->unescapeLineFeed($escapedSharedString);
|
$sharedString = $this->unescapeLineFeed($escapedSharedString);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($sharedString === null) {
|
if ($sharedString === null) {
|
||||||
throw new SharedStringNotFoundException("Shared string not found for index: $sharedStringIndex");
|
throw new SharedStringNotFoundException("Shared string not found for index: $sharedStringIndex");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user