PHPExcel_Shared
[ class tree: PHPExcel_Shared ] [ index: PHPExcel_Shared ] [ all elements ]

Source for file XMLWriter.php

Documentation is available at XMLWriter.php

  1. <?php
  2. /**
  3.  * PHPExcel
  4.  *
  5.  * Copyright (c) 2006 - 2010 PHPExcel
  6.  *
  7.  * This library is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU Lesser General Public
  9.  * License as published by the Free Software Foundation; either
  10.  * version 2.1 of the License, or (at your option) any later version.
  11.  *
  12.  * This library is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.  * Lesser General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU Lesser General Public
  18.  * License along with this library; if not, write to the Free Software
  19.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  20.  *
  21.  * @category   PHPExcel
  22.  * @package    PHPExcel_Shared
  23.  * @copyright  Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
  24.  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
  25.  * @version    1.7.4, 2010-08-26
  26.  */
  27.  
  28. if (!defined('DATE_W3C')) {
  29.   define('DATE_W3C''Y-m-d\TH:i:sP');
  30. }
  31.  
  32. if (!defined('DEBUGMODE_ENABLED')) {
  33.   define('DEBUGMODE_ENABLED'false);
  34. }
  35.  
  36.  
  37. /**
  38.  * PHPExcel_Shared_XMLWriter
  39.  *
  40.  * @category   PHPExcel
  41.  * @package    PHPExcel_Shared
  42.  * @copyright  Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
  43.  */
  44.     /** Temporary storage method */
  45.     const STORAGE_MEMORY    1;
  46.     const STORAGE_DISK        2;
  47.  
  48.     /**
  49.      * Internal XMLWriter
  50.      *
  51.      * @var XMLWriter 
  52.      */
  53.     private $_xmlWriter;
  54.  
  55.     /**
  56.      * Temporary filename
  57.      *
  58.      * @var string 
  59.      */
  60.     private $_tempFileName '';
  61.  
  62.     /**
  63.      * Create a new PHPExcel_Shared_XMLWriter instance
  64.      *
  65.      * @param int        $pTemporaryStorage            Temporary storage location
  66.      * @param string    $pTemporaryStorageFolder    Temporary storage folder
  67.      */
  68.     public function __construct($pTemporaryStorage self::STORAGE_MEMORY$pTemporaryStorageFolder './'{
  69.         // Create internal XMLWriter
  70.         $this->_xmlWriter new XMLWriter();
  71.  
  72.         // Open temporary storage
  73.         if ($pTemporaryStorage == self::STORAGE_MEMORY{
  74.             $this->_xmlWriter->openMemory();
  75.         else {
  76.             // Create temporary filename
  77.             $this->_tempFileName @tempnam($pTemporaryStorageFolder'xml');
  78.  
  79.             // Open storage
  80.             if ($this->_xmlWriter->openUri($this->_tempFileName=== false{
  81.                 // Fallback to memory...
  82.                 $this->_xmlWriter->openMemory();
  83.             }
  84.         }
  85.  
  86.         // Set default values
  87.         if (DEBUGMODE_ENABLED{
  88.             $this->_xmlWriter->setIndent(true);
  89.         }
  90.     }
  91.  
  92.     /**
  93.      * Destructor
  94.      */
  95.     public function __destruct({
  96.         // Desctruct XMLWriter
  97.         unset($this->_xmlWriter);
  98.  
  99.         // Unlink temporary files
  100.         if ($this->_tempFileName != ''{
  101.             @unlink($this->_tempFileName);
  102.         }
  103.     }
  104.  
  105.     /**
  106.      * Get written data
  107.      *
  108.      * @return $data 
  109.      */
  110.     public function getData({
  111.         if ($this->_tempFileName == ''{
  112.             return $this->_xmlWriter->outputMemory(true);
  113.         else {
  114.             $this->_xmlWriter->flush();
  115.             return file_get_contents($this->_tempFileName);
  116.         }
  117.     }
  118.  
  119.     /**
  120.      * Catch function calls (and pass them to internal XMLWriter)
  121.      *
  122.      * @param unknown_type $function 
  123.      * @param unknown_type $args 
  124.      */
  125.     public function __call($function$args{
  126.         try {
  127.             @call_user_func_array(array($this->_xmlWriter$function)$args);
  128.         catch (Exception $ex{
  129.             // Do nothing!
  130.         }
  131.     }
  132.  
  133.     /**
  134.      * Fallback method for writeRaw, introduced in PHP 5.2
  135.      *
  136.      * @param string $text 
  137.      * @return string 
  138.      */
  139.     public function writeRaw($text)
  140.     {
  141.         if (isset($this->_xmlWriter&& is_object($this->_xmlWriter&& (method_exists($this->_xmlWriter'writeRaw'))) {
  142.             return $this->_xmlWriter->writeRaw(htmlspecialchars($text));
  143.         }
  144.  
  145.         return $this->text($text);
  146.     }
  147. }

Documentation generated on Thu, 26 Aug 2010 17:47:06 +0200 by phpDocumentor 1.4.3