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 - 2009 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 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
  24.  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
  25.  * @version    1.6.5, 2009-01-05
  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 - 2009 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.      */
  62.     public function __construct($pTemporaryStorage self::STORAGE_MEMORY{
  63.         // Create internal XMLWriter
  64.         $this->_xmlWriter = new XMLWriter();
  65.  
  66.         // Open temporary storage
  67.         if ($pTemporaryStorage == self::STORAGE_MEMORY{
  68.             $this->_xmlWriter->openMemory();
  69.         else {
  70.             // Create temporary filename
  71.             $this->_tempFileName = @tempnam('./''xml');
  72.  
  73.             // Open storage
  74.             if ($this->_xmlWriter->openUri($this->_tempFileName=== false{
  75.                 // Fallback to memory...
  76.                 $this->_xmlWriter->openMemory();
  77.             }
  78.         }
  79.  
  80.         // Set default values
  81.         $this->_xmlWriter->setIndent(true);
  82.     }
  83.  
  84.     /**
  85.      * Destructor
  86.      */
  87.     public function __destruct({
  88.         // Desctruct XMLWriter
  89.         unset($this->_xmlWriter);
  90.  
  91.         // Unlink temporary files
  92.         if ($this->_tempFileName != ''{
  93.             @unlink($this->_tempFileName);
  94.         }
  95.     }
  96.  
  97.     /**
  98.      * Get written data
  99.      *
  100.      * @return $data 
  101.      */
  102.     public function getData({
  103.         if ($this->_tempFileName == ''{
  104.             return $this->_xmlWriter->outputMemory(true);
  105.         else {
  106.             $this->_xmlWriter->flush();
  107.             return file_get_contents($this->_tempFileName);
  108.         }
  109.     }
  110.  
  111.     /**
  112.      * Catch function calls (and pass them to internal XMLWriter)
  113.      *
  114.      * @param unknown_type $function 
  115.      * @param unknown_type $args 
  116.      */
  117.     public function __call($function$args{
  118.         try {
  119.             @call_user_func_array(array($this->_xmlWriter$function)$args);
  120.         catch (Exception $ex{
  121.             // Do nothing!
  122.         }
  123.     }
  124.  
  125.     /**
  126.      * Fallback method for writeRaw, introduced in PHP 5.2
  127.      *
  128.      * @param string $text 
  129.      * @return string 
  130.      */
  131.     public function writeRaw($text)
  132.     {
  133.         if (isset($this->_xmlWriter&& is_object($this->_xmlWriter&& (method_exists($this->_xmlWriter'writeRaw'))) {
  134.             return $this->_xmlWriter->writeRaw($text);
  135.         }
  136.  
  137.         return $this->text($text);
  138.     }
  139. }

Documentation generated on Mon, 05 Jan 2009 20:39:01 +0100 by phpDocumentor 1.4.1