SimpleExcel\SimpleExcel::constructParser PHP Method

constructParser() public method

Construct a SimpleExcel Parser
public constructParser ( string $filetype )
$filetype string Set the filetype of the file which will be parsed (XML/CSV/TSV/HTML/JSON)
    public function constructParser($filetype)
    {
        $filetype = strtoupper($filetype);
        if (!in_array($filetype, $this->validParserTypes)) {
            throw new \Exception('Filetype ' . $filetype . ' is not supported', SimpleExcelException::FILETYPE_NOT_SUPPORTED);
        }
        $parser_class = 'SimpleExcel\\Parser\\' . $filetype . 'Parser';
        $this->parser = new $parser_class();
    }

Usage Example

Example #1
0
 public function testConstruct()
 {
     $excel = new SimpleExcel('CSV');
     $excel2 = new SimpleExcel();
     $excel2->constructParser('CSV');
     $this->assertEquals($excel->parser, $excel2->parser);
     return $excel;
 }