Skip to content

Commit

Permalink
slightly more generic?
Browse files Browse the repository at this point in the history
  • Loading branch information
Daryl Richter committed Feb 19, 2024
1 parent 82fb60e commit f823cd9
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/Exportable.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,18 @@ public function download($path, callable $callback = null)
*/
private function exportOrDownload($path, $function, callable $callback = null)
{
if (str_ends_with($path, 'csv')) {
$options = new \OpenSpout\Writer\CSV\Options();
$writer = new \OpenSpout\Writer\CSV\Writer($options);
} elseif (str_ends_with($path, 'ods')) {
$options = new \OpenSpout\Writer\ODS\Options();
$writer = new \OpenSpout\Writer\ODS\Writer($options);
$ext = strtoupper(substr($path, -3));
if (in_array($ext, ['CSV', 'ODS'], true)) {
$optionCls = "\OpenSpout\Writer\{$ext}\Options";
$writerCls = "\OpenSpout\Writer\{$ext}\Writer";
$options = new $optionCls();
$writer = new $writerClass($options);
// if (str_ends_with($path, 'csv')) {
// $options = new \OpenSpout\Writer\CSV\Options();
// $writer = new \OpenSpout\Writer\CSV\Writer($options);
// } elseif (str_ends_with($path, 'ods')) {
// $options = new \OpenSpout\Writer\ODS\Options();
// $writer = new \OpenSpout\Writer\ODS\Writer($options);
} else {
$options = new \OpenSpout\Writer\XLSX\Options();
$writer = new \OpenSpout\Writer\XLSX\Writer($options);
Expand Down

0 comments on commit f823cd9

Please sign in to comment.