ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
SimpleExcel.php
Go to the documentation of this file.
1 <?php
36 namespace SimpleExcel;
37 
39 
40 if (!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 }