Minor performance tweaks: changing PHPExcel_Shared_XMLWriter to extend the XMLWriter class rather than providing a wrapper for an instance of XMLWriter, with slight modifications to the writeRaw() method
git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@63534 2327b42d-5241-43d6-9e2a-de5ac946f064
This commit is contained in:
parent
d7583efe44
commit
c0ae3911b6
|
@ -41,18 +41,11 @@ if (!defined('DEBUGMODE_ENABLED')) {
|
|||
* @package PHPExcel_Shared
|
||||
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class PHPExcel_Shared_XMLWriter {
|
||||
class PHPExcel_Shared_XMLWriter extends XMLWriter {
|
||||
/** Temporary storage method */
|
||||
const STORAGE_MEMORY = 1;
|
||||
const STORAGE_DISK = 2;
|
||||
|
||||
/**
|
||||
* Internal XMLWriter
|
||||
*
|
||||
* @var XMLWriter
|
||||
*/
|
||||
private $_xmlWriter;
|
||||
|
||||
/**
|
||||
* Temporary filename
|
||||
*
|
||||
|
@ -67,26 +60,23 @@ class PHPExcel_Shared_XMLWriter {
|
|||
* @param string $pTemporaryStorageFolder Temporary storage folder
|
||||
*/
|
||||
public function __construct($pTemporaryStorage = self::STORAGE_MEMORY, $pTemporaryStorageFolder = './') {
|
||||
// Create internal XMLWriter
|
||||
$this->_xmlWriter = new XMLWriter();
|
||||
|
||||
// Open temporary storage
|
||||
if ($pTemporaryStorage == self::STORAGE_MEMORY) {
|
||||
$this->_xmlWriter->openMemory();
|
||||
$this->openMemory();
|
||||
} else {
|
||||
// Create temporary filename
|
||||
$this->_tempFileName = @tempnam($pTemporaryStorageFolder, 'xml');
|
||||
|
||||
// Open storage
|
||||
if ($this->_xmlWriter->openUri($this->_tempFileName) === false) {
|
||||
if ($this->openUri($this->_tempFileName) === false) {
|
||||
// Fallback to memory...
|
||||
$this->_xmlWriter->openMemory();
|
||||
$this->openMemory();
|
||||
}
|
||||
}
|
||||
|
||||
// Set default values
|
||||
if (DEBUGMODE_ENABLED) {
|
||||
$this->_xmlWriter->setIndent(true);
|
||||
$this->setIndent(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -94,9 +84,6 @@ class PHPExcel_Shared_XMLWriter {
|
|||
* Destructor
|
||||
*/
|
||||
public function __destruct() {
|
||||
// Desctruct XMLWriter
|
||||
unset($this->_xmlWriter);
|
||||
|
||||
// Unlink temporary files
|
||||
if ($this->_tempFileName != '') {
|
||||
@unlink($this->_tempFileName);
|
||||
|
@ -110,37 +97,23 @@ class PHPExcel_Shared_XMLWriter {
|
|||
*/
|
||||
public function getData() {
|
||||
if ($this->_tempFileName == '') {
|
||||
return $this->_xmlWriter->outputMemory(true);
|
||||
return $this->outputMemory(true);
|
||||
} else {
|
||||
$this->_xmlWriter->flush();
|
||||
$this->flush();
|
||||
return file_get_contents($this->_tempFileName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Catch function calls (and pass them to internal XMLWriter)
|
||||
*
|
||||
* @param unknown_type $function
|
||||
* @param unknown_type $args
|
||||
*/
|
||||
public function __call($function, $args) {
|
||||
try {
|
||||
@call_user_func_array(array($this->_xmlWriter, $function), $args);
|
||||
} catch (Exception $ex) {
|
||||
// Do nothing!
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fallback method for writeRaw, introduced in PHP 5.2
|
||||
*
|
||||
* @param string $text
|
||||
* @return string
|
||||
*/
|
||||
public function writeRaw($text)
|
||||
public function writeRawData($text)
|
||||
{
|
||||
if (isset($this->_xmlWriter) && is_object($this->_xmlWriter) && (method_exists($this->_xmlWriter, 'writeRaw'))) {
|
||||
return $this->_xmlWriter->writeRaw(htmlspecialchars($text));
|
||||
if (method_exists($this, 'writeRaw')) {
|
||||
return $this->writeRaw(htmlspecialchars($text));
|
||||
}
|
||||
|
||||
return $this->text($text);
|
||||
|
|
|
@ -169,13 +169,13 @@ class PHPExcel_Writer_Excel2007_DocProps extends PHPExcel_Writer_Excel2007_Write
|
|||
// dcterms:created
|
||||
$objWriter->startElement('dcterms:created');
|
||||
$objWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF');
|
||||
$objWriter->writeRaw(date(DATE_W3C, $pPHPExcel->getProperties()->getCreated()));
|
||||
$objWriter->writeRawData(date(DATE_W3C, $pPHPExcel->getProperties()->getCreated()));
|
||||
$objWriter->endElement();
|
||||
|
||||
// dcterms:modified
|
||||
$objWriter->startElement('dcterms:modified');
|
||||
$objWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF');
|
||||
$objWriter->writeRaw(date(DATE_W3C, $pPHPExcel->getProperties()->getModified()));
|
||||
$objWriter->writeRawData(date(DATE_W3C, $pPHPExcel->getProperties()->getModified()));
|
||||
$objWriter->endElement();
|
||||
|
||||
// dc:title
|
||||
|
@ -251,7 +251,7 @@ class PHPExcel_Writer_Excel2007_DocProps extends PHPExcel_Writer_Excel2007_Write
|
|||
break;
|
||||
case 'd' :
|
||||
$objWriter->startElement('vt:filetime');
|
||||
$objWriter->writeRaw(date(DATE_W3C, $propertyValue));
|
||||
$objWriter->writeRawData(date(DATE_W3C, $propertyValue));
|
||||
$objWriter->endElement();
|
||||
break;
|
||||
default :
|
||||
|
|
|
@ -123,7 +123,7 @@ class PHPExcel_Writer_Excel2007_StringTable extends PHPExcel_Writer_Excel2007_Wr
|
|||
if ($textToWrite !== trim($textToWrite)) {
|
||||
$objWriter->writeAttribute('xml:space', 'preserve');
|
||||
}
|
||||
$objWriter->writeRaw($textToWrite);
|
||||
$objWriter->writeRawData($textToWrite);
|
||||
$objWriter->endElement();
|
||||
} else if ($textElement instanceof PHPExcel_RichText) {
|
||||
$this->writeRichText($objWriter, $textElement);
|
||||
|
@ -213,7 +213,7 @@ class PHPExcel_Writer_Excel2007_StringTable extends PHPExcel_Writer_Excel2007_Wr
|
|||
// t
|
||||
$objWriter->startElement('t');
|
||||
$objWriter->writeAttribute('xml:space', 'preserve');
|
||||
$objWriter->writeRaw(PHPExcel_Shared_String::ControlCharacterPHP2OOXML( $element->getText() ));
|
||||
$objWriter->writeRawData(PHPExcel_Shared_String::ControlCharacterPHP2OOXML( $element->getText() ));
|
||||
$objWriter->endElement();
|
||||
|
||||
$objWriter->endElement();
|
||||
|
|
|
@ -328,7 +328,7 @@ class PHPExcel_Writer_Excel2007_Workbook extends PHPExcel_Writer_Excel2007_Write
|
|||
}
|
||||
$range = PHPExcel_Cell::buildRange($range);
|
||||
|
||||
$objWriter->writeRaw($range);
|
||||
$objWriter->writeRawData($range);
|
||||
|
||||
$objWriter->endElement();
|
||||
}
|
||||
|
@ -357,7 +357,7 @@ class PHPExcel_Writer_Excel2007_Workbook extends PHPExcel_Writer_Excel2007_Write
|
|||
$range[1] = PHPExcel_Cell::absoluteCoordinate($range[1]);
|
||||
$range = implode(':', $range);
|
||||
|
||||
$objWriter->writeRaw('\'' . str_replace("'", "''", $pSheet->getTitle()) . '\'!' . $range);
|
||||
$objWriter->writeRawData('\'' . str_replace("'", "''", $pSheet->getTitle()) . '\'!' . $range);
|
||||
|
||||
$objWriter->endElement();
|
||||
}
|
||||
|
@ -400,7 +400,7 @@ class PHPExcel_Writer_Excel2007_Workbook extends PHPExcel_Writer_Excel2007_Write
|
|||
$settingString .= '\'' . str_replace("'", "''", $pSheet->getTitle()) . '\'!$' . $repeat[0] . ':$' . $repeat[1];
|
||||
}
|
||||
|
||||
$objWriter->writeRaw($settingString);
|
||||
$objWriter->writeRawData($settingString);
|
||||
|
||||
$objWriter->endElement();
|
||||
}
|
||||
|
@ -435,7 +435,7 @@ class PHPExcel_Writer_Excel2007_Workbook extends PHPExcel_Writer_Excel2007_Write
|
|||
$chunks[] = '\'' . str_replace("'", "''", $pSheet->getTitle()) . '\'!' . implode(':', $printAreaRect);
|
||||
}
|
||||
|
||||
$objWriter->writeRaw(implode(',', $chunks));
|
||||
$objWriter->writeRawData(implode(',', $chunks));
|
||||
|
||||
$objWriter->endElement();
|
||||
}
|
||||
|
|
|
@ -965,10 +965,8 @@ class PHPExcel_Writer_Excel2007_Worksheet extends PHPExcel_Writer_Excel2007_Writ
|
|||
case 'f': // Formula
|
||||
$calculatedValue = null;
|
||||
if ($this->getParentWriter()->getPreCalculateFormulas()) {
|
||||
$pCell->attach($pSheet);
|
||||
$calculatedValue = $pCell->getCalculatedValue();
|
||||
} else {
|
||||
$pCell->attach($pSheet);
|
||||
$calculatedValue = $pCell->getValue();
|
||||
}
|
||||
if (is_string($calculatedValue)) {
|
||||
|
|
Loading…
Reference in New Issue