added json, xml and txt invoice renderer (#1576)

This commit is contained in:
Kevin Papst
2020-03-21 01:01:47 +01:00
committed by GitHub
parent c89750fe94
commit 1ca1b00d11
19 changed files with 560 additions and 53 deletions

View File

@@ -71,6 +71,7 @@ class Extensions extends AbstractExtension
new TwigFilter('language', [$this, 'language']),
new TwigFilter('amount', [$this, 'amount']),
new TwigFilter('docu_link', [$this, 'documentationLink']),
new TwigFilter('multiline_indent', [$this, 'multilineIndent']),
];
}
@@ -98,6 +99,24 @@ class Extensions extends AbstractExtension
return get_class($object);
}
public function multilineIndent(?string $string, string $indent): string
{
if (null === $string || '' === $string) {
return '';
}
$parts = explode("\r\n", $string);
if (count($parts) === 1) {
$parts = explode("\n", $string);
}
$parts = array_map(function ($part) use ($indent) {
return $indent . $part;
}, $parts);
return implode("\n", $parts);
}
/**
* Transforms seconds into a duration string.
*