From 701bf6c1ed3e89a47054bf8cae825206473b756d Mon Sep 17 00:00:00 2001 From: Tim Date: Wed, 23 Apr 2025 01:24:08 +0200 Subject: [PATCH] Implement very basic twig parser --- composer.json | 2 +- src/Form/SnipType.php | 1 - .../SnipContent/SnipContentService.php | 5 +++- src/Service/SnipParser/Twig/TwigParser.php | 24 +++++++++++++++++++ 4 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 src/Service/SnipParser/Twig/TwigParser.php diff --git a/composer.json b/composer.json index 38cb685..3a11296 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "symfony/validator": "7.2.*", "symfony/yaml": "7.2.*", "twig/extra-bundle": "^2.12|^3.0", - "twig/twig": "^2.12|^3.0" + "twig/twig": "^3.0" }, "require-dev": { "deployer/deployer": "^7.3", diff --git a/src/Form/SnipType.php b/src/Form/SnipType.php index 6471132..1b746f0 100644 --- a/src/Form/SnipType.php +++ b/src/Form/SnipType.php @@ -18,7 +18,6 @@ class SnipType extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options): void { - dump(iterator_to_array($this->parserFactory->getChoices())); $builder ->add('name') ->add('parser', ChoiceType::class, [ diff --git a/src/Service/SnipContent/SnipContentService.php b/src/Service/SnipContent/SnipContentService.php index fba5d9b..09b4ba6 100644 --- a/src/Service/SnipContent/SnipContentService.php +++ b/src/Service/SnipContent/SnipContentService.php @@ -45,8 +45,11 @@ readonly class SnipContentService return $this->rebuildText($contentRepo->find($snip->getActiveVersion())); } - public function rebuildText(SnipContent $snipContent): string + public function rebuildText(?SnipContent $snipContent): string { + if ($snipContent === null) { + return ''; + } if ($snipContent->getText()) { return $snipContent->getText(); } diff --git a/src/Service/SnipParser/Twig/TwigParser.php b/src/Service/SnipParser/Twig/TwigParser.php new file mode 100644 index 0000000..a06f924 --- /dev/null +++ b/src/Service/SnipParser/Twig/TwigParser.php @@ -0,0 +1,24 @@ + $content, + ]); + $twig = new Environment($arrayLoader); + return $twig->render('index'); + } +} \ No newline at end of file