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
|
@ -19,10 +19,10 @@
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*
|
*
|
||||||
* @category PHPExcel
|
* @category PHPExcel
|
||||||
* @package PHPExcel_Shared
|
* @package PHPExcel_Shared
|
||||||
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
|
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
* @version ##VERSION##, ##DATE##
|
* @version ##VERSION##, ##DATE##
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('DATE_W3C')) {
|
if (!defined('DATE_W3C')) {
|
||||||
|
@ -38,21 +38,14 @@ if (!defined('DEBUGMODE_ENABLED')) {
|
||||||
* PHPExcel_Shared_XMLWriter
|
* PHPExcel_Shared_XMLWriter
|
||||||
*
|
*
|
||||||
* @category PHPExcel
|
* @category PHPExcel
|
||||||
* @package PHPExcel_Shared
|
* @package PHPExcel_Shared
|
||||||
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
|
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||||
*/
|
*/
|
||||||
class PHPExcel_Shared_XMLWriter {
|
class PHPExcel_Shared_XMLWriter extends XMLWriter {
|
||||||
/** Temporary storage method */
|
/** Temporary storage method */
|
||||||
const STORAGE_MEMORY = 1;
|
const STORAGE_MEMORY = 1;
|
||||||
const STORAGE_DISK = 2;
|
const STORAGE_DISK = 2;
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal XMLWriter
|
|
||||||
*
|
|
||||||
* @var XMLWriter
|
|
||||||
*/
|
|
||||||
private $_xmlWriter;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Temporary filename
|
* Temporary filename
|
||||||
*
|
*
|
||||||
|
@ -66,83 +59,63 @@ class PHPExcel_Shared_XMLWriter {
|
||||||
* @param int $pTemporaryStorage Temporary storage location
|
* @param int $pTemporaryStorage Temporary storage location
|
||||||
* @param string $pTemporaryStorageFolder Temporary storage folder
|
* @param string $pTemporaryStorageFolder Temporary storage folder
|
||||||
*/
|
*/
|
||||||
public function __construct($pTemporaryStorage = self::STORAGE_MEMORY, $pTemporaryStorageFolder = './') {
|
public function __construct($pTemporaryStorage = self::STORAGE_MEMORY, $pTemporaryStorageFolder = './') {
|
||||||
// Create internal XMLWriter
|
// Open temporary storage
|
||||||
$this->_xmlWriter = new XMLWriter();
|
if ($pTemporaryStorage == self::STORAGE_MEMORY) {
|
||||||
|
$this->openMemory();
|
||||||
|
} else {
|
||||||
|
// Create temporary filename
|
||||||
|
$this->_tempFileName = @tempnam($pTemporaryStorageFolder, 'xml');
|
||||||
|
|
||||||
// Open temporary storage
|
// Open storage
|
||||||
if ($pTemporaryStorage == self::STORAGE_MEMORY) {
|
if ($this->openUri($this->_tempFileName) === false) {
|
||||||
$this->_xmlWriter->openMemory();
|
// Fallback to memory...
|
||||||
} else {
|
$this->openMemory();
|
||||||
// Create temporary filename
|
}
|
||||||
$this->_tempFileName = @tempnam($pTemporaryStorageFolder, 'xml');
|
}
|
||||||
|
|
||||||
// Open storage
|
// Set default values
|
||||||
if ($this->_xmlWriter->openUri($this->_tempFileName) === false) {
|
|
||||||
// Fallback to memory...
|
|
||||||
$this->_xmlWriter->openMemory();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set default values
|
|
||||||
if (DEBUGMODE_ENABLED) {
|
if (DEBUGMODE_ENABLED) {
|
||||||
$this->_xmlWriter->setIndent(true);
|
$this->setIndent(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destructor
|
* Destructor
|
||||||
*/
|
*/
|
||||||
public function __destruct() {
|
public function __destruct() {
|
||||||
// Desctruct XMLWriter
|
// Unlink temporary files
|
||||||
unset($this->_xmlWriter);
|
if ($this->_tempFileName != '') {
|
||||||
|
@unlink($this->_tempFileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Unlink temporary files
|
/**
|
||||||
if ($this->_tempFileName != '') {
|
* Get written data
|
||||||
@unlink($this->_tempFileName);
|
*
|
||||||
}
|
* @return $data
|
||||||
}
|
*/
|
||||||
|
public function getData() {
|
||||||
|
if ($this->_tempFileName == '') {
|
||||||
|
return $this->outputMemory(true);
|
||||||
|
} else {
|
||||||
|
$this->flush();
|
||||||
|
return file_get_contents($this->_tempFileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get written data
|
* Fallback method for writeRaw, introduced in PHP 5.2
|
||||||
*
|
*
|
||||||
* @return $data
|
* @param string $text
|
||||||
*/
|
* @return string
|
||||||
public function getData() {
|
*/
|
||||||
if ($this->_tempFileName == '') {
|
public function writeRawData($text)
|
||||||
return $this->_xmlWriter->outputMemory(true);
|
{
|
||||||
} else {
|
if (method_exists($this, 'writeRaw')) {
|
||||||
$this->_xmlWriter->flush();
|
return $this->writeRaw(htmlspecialchars($text));
|
||||||
return file_get_contents($this->_tempFileName);
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
return $this->text($text);
|
||||||
* 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)
|
|
||||||
{
|
|
||||||
if (isset($this->_xmlWriter) && is_object($this->_xmlWriter) && (method_exists($this->_xmlWriter, 'writeRaw'))) {
|
|
||||||
return $this->_xmlWriter->writeRaw(htmlspecialchars($text));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->text($text);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -169,13 +169,13 @@ class PHPExcel_Writer_Excel2007_DocProps extends PHPExcel_Writer_Excel2007_Write
|
||||||
// dcterms:created
|
// dcterms:created
|
||||||
$objWriter->startElement('dcterms:created');
|
$objWriter->startElement('dcterms:created');
|
||||||
$objWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF');
|
$objWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF');
|
||||||
$objWriter->writeRaw(date(DATE_W3C, $pPHPExcel->getProperties()->getCreated()));
|
$objWriter->writeRawData(date(DATE_W3C, $pPHPExcel->getProperties()->getCreated()));
|
||||||
$objWriter->endElement();
|
$objWriter->endElement();
|
||||||
|
|
||||||
// dcterms:modified
|
// dcterms:modified
|
||||||
$objWriter->startElement('dcterms:modified');
|
$objWriter->startElement('dcterms:modified');
|
||||||
$objWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF');
|
$objWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF');
|
||||||
$objWriter->writeRaw(date(DATE_W3C, $pPHPExcel->getProperties()->getModified()));
|
$objWriter->writeRawData(date(DATE_W3C, $pPHPExcel->getProperties()->getModified()));
|
||||||
$objWriter->endElement();
|
$objWriter->endElement();
|
||||||
|
|
||||||
// dc:title
|
// dc:title
|
||||||
|
@ -251,7 +251,7 @@ class PHPExcel_Writer_Excel2007_DocProps extends PHPExcel_Writer_Excel2007_Write
|
||||||
break;
|
break;
|
||||||
case 'd' :
|
case 'd' :
|
||||||
$objWriter->startElement('vt:filetime');
|
$objWriter->startElement('vt:filetime');
|
||||||
$objWriter->writeRaw(date(DATE_W3C, $propertyValue));
|
$objWriter->writeRawData(date(DATE_W3C, $propertyValue));
|
||||||
$objWriter->endElement();
|
$objWriter->endElement();
|
||||||
break;
|
break;
|
||||||
default :
|
default :
|
||||||
|
|
|
@ -123,7 +123,7 @@ class PHPExcel_Writer_Excel2007_StringTable extends PHPExcel_Writer_Excel2007_Wr
|
||||||
if ($textToWrite !== trim($textToWrite)) {
|
if ($textToWrite !== trim($textToWrite)) {
|
||||||
$objWriter->writeAttribute('xml:space', 'preserve');
|
$objWriter->writeAttribute('xml:space', 'preserve');
|
||||||
}
|
}
|
||||||
$objWriter->writeRaw($textToWrite);
|
$objWriter->writeRawData($textToWrite);
|
||||||
$objWriter->endElement();
|
$objWriter->endElement();
|
||||||
} else if ($textElement instanceof PHPExcel_RichText) {
|
} else if ($textElement instanceof PHPExcel_RichText) {
|
||||||
$this->writeRichText($objWriter, $textElement);
|
$this->writeRichText($objWriter, $textElement);
|
||||||
|
@ -213,7 +213,7 @@ class PHPExcel_Writer_Excel2007_StringTable extends PHPExcel_Writer_Excel2007_Wr
|
||||||
// t
|
// t
|
||||||
$objWriter->startElement('t');
|
$objWriter->startElement('t');
|
||||||
$objWriter->writeAttribute('xml:space', 'preserve');
|
$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();
|
||||||
|
|
||||||
$objWriter->endElement();
|
$objWriter->endElement();
|
||||||
|
|
|
@ -328,7 +328,7 @@ class PHPExcel_Writer_Excel2007_Workbook extends PHPExcel_Writer_Excel2007_Write
|
||||||
}
|
}
|
||||||
$range = PHPExcel_Cell::buildRange($range);
|
$range = PHPExcel_Cell::buildRange($range);
|
||||||
|
|
||||||
$objWriter->writeRaw($range);
|
$objWriter->writeRawData($range);
|
||||||
|
|
||||||
$objWriter->endElement();
|
$objWriter->endElement();
|
||||||
}
|
}
|
||||||
|
@ -357,7 +357,7 @@ class PHPExcel_Writer_Excel2007_Workbook extends PHPExcel_Writer_Excel2007_Write
|
||||||
$range[1] = PHPExcel_Cell::absoluteCoordinate($range[1]);
|
$range[1] = PHPExcel_Cell::absoluteCoordinate($range[1]);
|
||||||
$range = implode(':', $range);
|
$range = implode(':', $range);
|
||||||
|
|
||||||
$objWriter->writeRaw('\'' . str_replace("'", "''", $pSheet->getTitle()) . '\'!' . $range);
|
$objWriter->writeRawData('\'' . str_replace("'", "''", $pSheet->getTitle()) . '\'!' . $range);
|
||||||
|
|
||||||
$objWriter->endElement();
|
$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];
|
$settingString .= '\'' . str_replace("'", "''", $pSheet->getTitle()) . '\'!$' . $repeat[0] . ':$' . $repeat[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
$objWriter->writeRaw($settingString);
|
$objWriter->writeRawData($settingString);
|
||||||
|
|
||||||
$objWriter->endElement();
|
$objWriter->endElement();
|
||||||
}
|
}
|
||||||
|
@ -435,7 +435,7 @@ class PHPExcel_Writer_Excel2007_Workbook extends PHPExcel_Writer_Excel2007_Write
|
||||||
$chunks[] = '\'' . str_replace("'", "''", $pSheet->getTitle()) . '\'!' . implode(':', $printAreaRect);
|
$chunks[] = '\'' . str_replace("'", "''", $pSheet->getTitle()) . '\'!' . implode(':', $printAreaRect);
|
||||||
}
|
}
|
||||||
|
|
||||||
$objWriter->writeRaw(implode(',', $chunks));
|
$objWriter->writeRawData(implode(',', $chunks));
|
||||||
|
|
||||||
$objWriter->endElement();
|
$objWriter->endElement();
|
||||||
}
|
}
|
||||||
|
|
|
@ -965,10 +965,8 @@ class PHPExcel_Writer_Excel2007_Worksheet extends PHPExcel_Writer_Excel2007_Writ
|
||||||
case 'f': // Formula
|
case 'f': // Formula
|
||||||
$calculatedValue = null;
|
$calculatedValue = null;
|
||||||
if ($this->getParentWriter()->getPreCalculateFormulas()) {
|
if ($this->getParentWriter()->getPreCalculateFormulas()) {
|
||||||
$pCell->attach($pSheet);
|
|
||||||
$calculatedValue = $pCell->getCalculatedValue();
|
$calculatedValue = $pCell->getCalculatedValue();
|
||||||
} else {
|
} else {
|
||||||
$pCell->attach($pSheet);
|
|
||||||
$calculatedValue = $pCell->getValue();
|
$calculatedValue = $pCell->getValue();
|
||||||
}
|
}
|
||||||
if (is_string($calculatedValue)) {
|
if (is_string($calculatedValue)) {
|
||||||
|
|
Loading…
Reference in New Issue