chore: lots of changes
This commit is contained in:
29
src/Framework/View/Processors/DateFormatProcessor.php
Normal file
29
src/Framework/View/Processors/DateFormatProcessor.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Framework\View\Processors;
|
||||
|
||||
use App\Framework\View\RenderContext;
|
||||
use App\Framework\View\StringProcessor;
|
||||
|
||||
# Formatiert Datumsfelder etwa mit einem Tag `<date value="iso_date" format="d.m.Y" />`.
|
||||
|
||||
final readonly class DateFormatProcessor implements StringProcessor
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function process(string $html, RenderContext $context): string
|
||||
{
|
||||
return preg_replace_callback('/{{\s*date\((\w+),\s*["\']([^"\']+)["\']\)\s*}}/', function ($matches) use ($context) {
|
||||
$key = $matches[1];
|
||||
$format = $matches[2];
|
||||
|
||||
if (!isset($context->data[$key]) || !($context->data[$key] instanceof \DateTimeInterface)) {
|
||||
return $matches[0]; // Unverändert lassen
|
||||
}
|
||||
|
||||
return $context->data[$key]->format($format);
|
||||
}, $html);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user