ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
SimpleExcel.php
Go to the documentation of this file.
1<?php
36namespace SimpleExcel;
37
39
40if (!class_exists('Composer\\Autoload\\ClassLoader', false)){
41 // autoload all interfaces & classes
42 spl_autoload_register(function($class_name){
43 if($class_name != 'SimpleExcel') require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.str_replace('\\', DIRECTORY_SEPARATOR, substr($class_name, strlen('SimpleExcel\\'))).'.php');
44 });
45}
46
54{
59 public $parser;
60
65 public $writer;
66
71 protected $validParserTypes = array('XML', 'CSV', 'TSV', 'HTML', 'JSON');
72 protected $validWriterTypes = array('XML', 'CSV', 'TSV', 'HTML', 'JSON');
73
80 public function __construct($filetype = 'XML'){
81 $this->constructParser($filetype);
82 $this->constructWriter($filetype);
83 }
84
91 public function constructParser($filetype){
92 $filetype = strtoupper($filetype);
93 if(!in_array($filetype, $this->validParserTypes)){
94 throw new \Exception('Filetype '.$filetype.' is not supported', SimpleExcelException::FILETYPE_NOT_SUPPORTED);
95 }
96 $parser_class = 'SimpleExcel\\Parser\\'.$filetype.'Parser';
97 $this->parser = new $parser_class();
98 }
99
107 public function constructWriter($filetype){
108 $filetype = strtoupper($filetype);
109
110 if(!in_array($filetype, $this->validWriterTypes)){
111 throw new \Exception('Filetype '.$filetype.' is not supported', SimpleExcelException::FILETYPE_NOT_SUPPORTED);
112 }
113 $writer_class = 'SimpleExcel\\Writer\\'.$filetype.'Writer';
114 $this->writer = new $writer_class();
115 }
116
122 public function convertTo($filetype){
123 $this->constructWriter($filetype);
124 $this->writer->setData($this->parser->getField());
125 }
126}
constructParser($filetype)
Construct a SimpleExcel Parser.
Definition: SimpleExcel.php:91
__construct($filetype='XML')
SimpleExcel constructor method.
Definition: SimpleExcel.php:80
convertTo($filetype)
Change writer type to convert to another format.
constructWriter($filetype)
Construct a SimpleExcel Writer.
Defines SimpleExcel exception enum.