Implement very basic twig parser
This commit is contained in:
parent
943177bc08
commit
701bf6c1ed
@ -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",
|
||||
|
@ -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, [
|
||||
|
@ -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();
|
||||
}
|
||||
|
24
src/Service/SnipParser/Twig/TwigParser.php
Normal file
24
src/Service/SnipParser/Twig/TwigParser.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service\SnipParser\Twig;
|
||||
|
||||
use App\Service\SnipParser\AbstractParser;
|
||||
use Twig\Environment;
|
||||
use Twig\Loader\ArrayLoader;
|
||||
|
||||
class TwigParser extends AbstractParser
|
||||
{
|
||||
public static function getName(): string
|
||||
{
|
||||
return 'twig';
|
||||
}
|
||||
|
||||
public function parseView(string $content): string
|
||||
{
|
||||
$arrayLoader = new ArrayLoader([
|
||||
'index' => $content,
|
||||
]);
|
||||
$twig = new Environment($arrayLoader);
|
||||
return $twig->render('index');
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user