From 335f4e8fcd1a9514f195a6e1729c62b8d2bf049c Mon Sep 17 00:00:00 2001 From: ghost Date: Wed, 14 Feb 2024 19:51:44 +0200 Subject: [PATCH] add formatType filter --- src/Twig/AppExtension.php | 74 ++++++++++++++++++++ templates/default/main/index.html.twig | 4 +- templates/default/main/index.rss.twig | 2 +- templates/default/main/namespace.html.twig | 4 +- templates/default/main/namespace.rss.twig | 2 +- templates/default/main/transaction.html.twig | 4 +- 6 files changed, 82 insertions(+), 8 deletions(-) diff --git a/src/Twig/AppExtension.php b/src/Twig/AppExtension.php index badb04b..1305c77 100644 --- a/src/Twig/AppExtension.php +++ b/src/Twig/AppExtension.php @@ -17,6 +17,13 @@ class AppExtension extends AbstractExtension $this, 'jIdenticon' ] + ), + new TwigFilter( + 'format_type', + [ + $this, + 'formatType' + ] ) ]; } @@ -50,4 +57,71 @@ class AppExtension extends AbstractExtension $format ); } + + public function formatType( + mixed $value, + int $code + ): string + { + switch ($code) + { + case \Kvazar\Index\Manticore::TYPE_NULL: + + return '[null]'; + + case \Kvazar\Index\Manticore::TYPE_BOOL: + + return sprintf( + '[bool:%s]', + $value ? 'true' : 'false' + ); + + case \Kvazar\Index\Manticore::TYPE_INT: + + return sprintf( + '[int:%d]', + $value + ); + + case \Kvazar\Index\Manticore::TYPE_FLOAT: + + return sprintf( + '[float:%s]', + $value + ); + + case \Kvazar\Index\Manticore::TYPE_STRING: + + return (string) nl2br( + $value + ); + + case \Kvazar\Index\Manticore::TYPE_BIN: + + return '[binary]'; + + case \Kvazar\Index\Manticore::TYPE_JSON: + + return '[json]'; + + case \Kvazar\Index\Manticore::TYPE_XML: + + return '[xml]'; + + case \Kvazar\Index\Manticore::TYPE_BASE_64: + + return '[base64]'; + + case \Kvazar\Index\Manticore::TYPE_ARRAY: + + return '[array]'; + + case \Kvazar\Index\Manticore::TYPE_OBJECT: + + return '[array]'; + + default: + return '[undefined]'; + } + } } \ No newline at end of file diff --git a/templates/default/main/index.html.twig b/templates/default/main/index.html.twig index d056229..f2899b1 100644 --- a/templates/default/main/index.html.twig +++ b/templates/default/main/index.html.twig @@ -24,10 +24,10 @@
- {{ record.key }} + {{ record.key | format_type(record.type.key) }}
- {{ record.value | nl2br }} + {{ record.value | format_type(record.type.value) }}
{{ record.time | format_date }} {{ 'in' | trans }} {{ record.block }} diff --git a/templates/default/main/index.rss.twig b/templates/default/main/index.rss.twig index e7c0e16..6cb4e21 100644 --- a/templates/default/main/index.rss.twig +++ b/templates/default/main/index.rss.twig @@ -6,7 +6,7 @@ {{ url('main_index') }} {% for record in records %} - {{ record.key }} + {{ record.key | format_type(record.type.key) }} {{ record.namespace }} {{ record.time | date('D, d M Y h:i:s O') }} {{ url('main_transaction',{'transaction':record.transaction}) }} diff --git a/templates/default/main/namespace.html.twig b/templates/default/main/namespace.html.twig index 0cdb5a8..86728db 100644 --- a/templates/default/main/namespace.html.twig +++ b/templates/default/main/namespace.html.twig @@ -25,10 +25,10 @@