Fix issue with directory separators for zip:// on Windows

Replaced "/" by DIRECTORY_SEPARATOR every time it was used with zip://
This commit is contained in:
Adrien Loison committed 2015-05-12 20:51:57 -07:00
1 parent 69190cd855
commit fb0175d633
5 files changed
+38 -8

No files matched your search

@@ -93,7 +93,7 @@ class SharedStringsHelper
$this->tempFilePointer = null;
$escaper = new \Box\Spout\Common\Escaper\XLSX();
$sharedStringsFilePath = 'zip://' . $this->filePath . '#' . self::SHARED_STRINGS_XML_FILE_PATH;
$sharedStringsFilePath = $this->getSharedStringsFilePath();
if ($xmlReader->open($sharedStringsFilePath, null, LIBXML_NONET) === false) {
throw new IOException('Could not open "' . self::SHARED_STRINGS_XML_FILE_PATH . '".');
}
@@ -143,6 +143,15 @@ class SharedStringsHelper
$xmlReader->close();
}
/**
* @return string The path to the shared strings XML file, working cross-platforms
*/
protected function getSharedStringsFilePath()
{
$sharedStringsXmlFilePath = str_replace('/', DIRECTORY_SEPARATOR, self::SHARED_STRINGS_XML_FILE_PATH);
return 'zip://' . $this->filePath . '#' . $sharedStringsXmlFilePath;
}
/**
* Removes nodes that should not be read, like the pronunciation of the Kanji characters.
* By keeping them, their text content would be added to the read string.
@@ -186,7 +186,8 @@ class WorksheetHelper
*/
protected function getFileAsXMLElementWithNamespace($xmlFilePath, $mainNamespace)
{
$xmlContents = $this->globalFunctionsHelper->file_get_contents('zip://' . $this->filePath . '#' . $xmlFilePath);
$normalizedXmlFilePath = str_replace('/', DIRECTORY_SEPARATOR, $xmlFilePath);
$xmlContents = $this->globalFunctionsHelper->file_get_contents('zip://' . $this->filePath . '#' . $normalizedXmlFilePath);
$xmlElement = new \SimpleXMLElement($xmlContents);
$xmlElement->registerXPathNamespace('ns', $mainNamespace);
+4 -2
View File
@@ -32,11 +32,13 @@ class Worksheet
}
/**
* @return string Path of the XML file containing the worksheet data, without the leading slash
* @return string Path of the XML file containing the worksheet data,
* without the leading slash and working cross-platforms.
*/
public function getDataXmlFilePath()
{
return ltrim($this->dataXmlFilePath, '/');
$dataXmlFilePath = ltrim($this->dataXmlFilePath, '/');
return str_replace('/', DIRECTORY_SEPARATOR, $dataXmlFilePath);
}
/**