fixed multilineIndent (#1669)

This commit is contained in:
Kevin Papst
2020-04-28 17:13:02 +02:00
committed by GitHub
parent 46a7b13293
commit ad2698dae2
9 changed files with 57 additions and 154 deletions

View File

@@ -1,51 +0,0 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Invoice\Renderer;
use App\Invoice\RendererInterface;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
final class CsvRenderer extends AbstractSpreadsheetRenderer implements RendererInterface
{
/**
* @return string[]
*/
protected function getFileExtensions()
{
return ['.csv'];
}
/**
* @return string
*/
protected function getContentType()
{
return 'text/csv';
}
/**
* @param Spreadsheet $spreadsheet
* @return string
* @throws \Exception
*/
protected function saveSpreadsheet(Spreadsheet $spreadsheet)
{
$filename = tempnam(sys_get_temp_dir(), 'kimai-invoice-csv');
if (false === $filename) {
throw new \Exception('Could not open temporary file');
}
$writer = IOFactory::createWriter($spreadsheet, 'Csv');
$writer->save($filename);
return $filename;
}
}

View File

@@ -105,16 +105,19 @@ class Extensions extends AbstractExtension
return '';
}
$parts = explode("\r\n", $string);
if (\count($parts) === 1) {
$parts = explode("\n", $string);
$parts = [];
foreach (explode("\r\n", $string) as $part) {
foreach (explode("\n", $part) as $tmp) {
$parts[] = $tmp;
}
}
$parts = array_map(function ($part) use ($indent) {
return $indent . $part;
}, $parts);
return implode("\n", $parts);
return implode(PHP_EOL, $parts);
}
/**