Release 2.16 (#4780)

This commit is contained in:
Kevin Papst
2024-05-01 14:24:24 +02:00
committed by GitHub
parent 8f8d228fb3
commit 99c296a751
150 changed files with 2498 additions and 1905 deletions

View File

@@ -0,0 +1,32 @@
<?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\Export\Spreadsheet\CellFormatter;
use App\Utils\StringHelper;
use PhpOffice\PhpSpreadsheet\Cell\CellAddress;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
final class StringFormatter implements CellFormatterInterface
{
public function setFormattedValue(Worksheet $sheet, int $column, int $row, $value): void
{
if (null === $value) {
$sheet->setCellValue(CellAddress::fromColumnAndRow($column, $row), '');
return;
}
if (!\is_string($value)) {
throw new \InvalidArgumentException('Unsupported value given, only string is supported');
}
$sheet->setCellValue(CellAddress::fromColumnAndRow($column, $row), StringHelper::sanitizeDDE($value));
}
}

View File

@@ -15,6 +15,7 @@ use App\Export\Spreadsheet\CellFormatter\CellFormatterInterface;
use App\Export\Spreadsheet\CellFormatter\DateFormatter;
use App\Export\Spreadsheet\CellFormatter\DateTimeFormatter;
use App\Export\Spreadsheet\CellFormatter\DurationFormatter;
use App\Export\Spreadsheet\CellFormatter\StringFormatter;
use App\Export\Spreadsheet\CellFormatter\TimeFormatter;
use PhpOffice\PhpSpreadsheet\Cell\CellAddress;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
@@ -30,7 +31,7 @@ class SpreadsheetExporter
*/
private array $formatter = [];
public function __construct(private TranslatorInterface $translator)
public function __construct(private readonly TranslatorInterface $translator)
{
$this->registerCellFormatter('datetime', new DateTimeFormatter());
$this->registerCellFormatter('date', new DateFormatter());
@@ -38,6 +39,7 @@ class SpreadsheetExporter
$this->registerCellFormatter('duration', new DurationFormatter());
$this->registerCellFormatter('boolean', new BooleanFormatter());
$this->registerCellFormatter('array', new ArrayFormatter());
$this->registerCellFormatter('string', new StringFormatter());
}
public function registerCellFormatter(string $type, CellFormatterInterface $formatter): void