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.3c, 2010-06-01
  26.  */
  27.  
  28. if (!defined('DATE_W3C')) {
  29.   define('DATE_W3C''Y-m-d\TH:i:sP');
  30. }
  31.  
  32. /**
  33.  * PHPExcel_Shared_XMLWriter
  34.  *
  35.  * @category   PHPExcel
  36.  * @package    PHPExcel_Shared
  37.  * @copyright  Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
  38.  */
  39.     /** Temporary storage method */
  40.     const STORAGE_MEMORY    1;
  41.     const STORAGE_DISK        2;
  42.  
  43.     /**
  44.      * Internal XMLWriter
  45.      *
  46.      * @var XMLWriter 
  47.      */
  48.     private $_xmlWriter;
  49.  
  50.     /**
  51.      * Temporary filename
  52.      *
  53.      * @var string 
  54.      */
  55.     private $_tempFileName '';
  56.  
  57.     /**
  58.      * Create a new PHPExcel_Shared_XMLWriter instance
  59.      *
  60.      * @param int        $pTemporaryStorage            Temporary storage location
  61.      * @param string    $pTemporaryStorageFolder    Temporary storage folder
  62.      */
  63.     public function __construct($pTemporaryStorage self::STORAGE_MEMORY$pTemporaryStorageFolder './'{
  64.         // Create internal XMLWriter
  65.         $this->_xmlWriter new XMLWriter();
  66.  
  67.         // Open temporary storage
  68.         if ($pTemporaryStorage == self::STORAGE_MEMORY{
  69.             $this->_xmlWriter->openMemory();
  70.         else {
  71.             // Create temporary filename
  72.             $this->_tempFileName @tempnam($pTemporaryStorageFolder'xml');
  73.  
  74.             // Open storage
  75.             if ($this->_xmlWriter->openUri($this->_tempFileName=== false{
  76.                 // Fallback to memory...
  77.                 $this->_xmlWriter->openMemory();
  78.             }
  79.         }
  80.  
  81.         // Set default values
  82.         $this->_xmlWriter->setIndent(true);
  83.     }
  84.  
  85.     /**
  86.      * Destructor
  87.      */
  88.     public function __destruct({
  89.         // Desctruct XMLWriter
  90.         unset($this->_xmlWriter);
  91.  
  92.         // Unlink temporary files
  93.         if ($this->_tempFileName != ''{
  94.             @unlink($this->_tempFileName);
  95.         }
  96.     }
  97.  
  98.     /**
  99.      * Get written data
  100.      *
  101.      * @return $data 
  102.      */
  103.     public function getData({
  104.         if ($this->_tempFileName == ''{
  105.             return $this->_xmlWriter->outputMemory(true);
  106.         else {
  107.             $this->_xmlWriter->flush();
  108.             return file_get_contents($this->_tempFileName);
  109.         }
  110.     }
  111.  
  112.     /**
  113.      * Catch function calls (and pass them to internal XMLWriter)
  114.      *
  115.      * @param unknown_type $function 
  116.      * @param unknown_type $args 
  117.      */
  118.     public function __call($function$args{
  119.         try {
  120.             @call_user_func_array(array($this->_xmlWriter$function)$args);
  121.         catch (Exception $ex{
  122.             // Do nothing!
  123.         }
  124.     }
  125.  
  126.     /**
  127.      * Fallback method for writeRaw, introduced in PHP 5.2
  128.      *
  129.      * @param string $text 
  130.      * @return string 
  131.      */
  132.     public function writeRaw($text)
  133.     {
  134.         if (isset($this->_xmlWriter&& is_object($this->_xmlWriter&& (method_exists($this->_xmlWriter'writeRaw'))) {
  135.             return $this->_xmlWriter->writeRaw(htmlspecialchars($text));
  136.         }
  137.  
  138.         return $this->text($text);
  139.     }
  140. }

Documentation generated on Tue, 01 Jun 2010 17:08:43 +0200 by phpDocumentor 1.4.3