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 - 2008 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 - 2008 PHPExcel (http://www.codeplex.com/PHPExcel)
  24.  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
  25.  * @version    1.6.3, 2008-08-25
  26.  */
  27.  
  28.  
  29. /**
  30.  * PHPExcel_Shared_XMLWriter
  31.  *
  32.  * @category   PHPExcel
  33.  * @package    PHPExcel_Shared
  34.  * @copyright  Copyright (c) 2006 - 2008 PHPExcel (http://www.codeplex.com/PHPExcel)
  35.  */
  36.     /** Temporary storage method */
  37.     const STORAGE_MEMORY    = 1;
  38.     const STORAGE_DISK        = 2;
  39.     
  40.     /**
  41.      * Internal XMLWriter
  42.      *
  43.      * @var XMLWriter 
  44.      */
  45.     private $_xmlWriter;
  46.     
  47.     /**
  48.      * Temporary filename
  49.      *
  50.      * @var string 
  51.      */
  52.     private $_tempFileName = '';
  53.     
  54.     /**
  55.      * Create a new PHPExcel_Shared_XMLWriter instance
  56.      *
  57.      * @param int    $pTemporaryStorage    Temporary storage location
  58.      */
  59.     public function __construct($pTemporaryStorage = self::STORAGE_MEMORY) {
  60.         // Create internal XMLWriter
  61.         $this->_xmlWriter = new XMLWriter();
  62.         
  63.         // Open temporary storage
  64.         if ($pTemporaryStorage == self::STORAGE_MEMORY) {
  65.             $this->_xmlWriter->openMemory();
  66.         } else {
  67.             // Create temporary filename
  68.             $this->_tempFileName = @tempnam('./', 'xml');
  69.             
  70.             // Open storage
  71.             if ($this->_xmlWriter->openUri($this->_tempFileName) === false) {
  72.                 // Fallback to memory...
  73.                 $this->_xmlWriter->openMemory();
  74.             }
  75.         }
  76.         
  77.         // Set default values
  78.         $this->_xmlWriter->setIndent(true);
  79.     }
  80.     
  81.     /**
  82.      * Destructor
  83.      */
  84.     public function __destruct() {
  85.         // Desctruct XMLWriter
  86.         unset($this->_xmlWriter);
  87.         
  88.         // Unlink temporary files
  89.         if ($this->_tempFileName != '') {
  90.             @unlink($this->_tempFileName);
  91.         }
  92.     }
  93.     
  94.     /**
  95.      * Get written data
  96.      *
  97.      * @return $data 
  98.      */
  99.     public function getData() {
  100.         if ($this->_tempFileName == '') {
  101.             return $this->_xmlWriter->outputMemory(true);
  102.         } else {
  103.             $this->_xmlWriter->flush();
  104.             return file_get_contents($this->_tempFileName);
  105.         }
  106.     }
  107.     
  108.     /**
  109.      * Catch function calls (and pass them to internal XMLWriter)
  110.      *
  111.      * @param unknown_type $function 
  112.      * @param unknown_type $args 
  113.      */
  114.     public function __call($function, $args) {
  115.         try {
  116.             @call_user_func_array(array($this->_xmlWriter, $function), $args);
  117.         } catch (Exception $ex) {
  118.             // Do nothing!
  119.         }
  120.     }
  121. }

Documentation generated on Mon, 25 Aug 2008 13:54:26 +0200 by phpDocumentor 1.4.1