Loading src/UnicaenRenderer/Entity/Db/Template.php +5 −1 Original line number Diff line number Diff line Loading @@ -32,10 +32,12 @@ class Template implements ResourceInterface const TEMPLATE_ENGINE_DEFAULT = 'default'; const TEMPLATE_ENGINE_LAMINAS = 'laminas'; const TEMPLATE_ENGINE_TWIG = 'twig'; const TEMPLATE_ENGINE_TWIGLIGHT = 'twiglight'; const TEMPLATE_ENGINES = [ self::TEMPLATE_ENGINE_DEFAULT => "Moteur par défaut", self::TEMPLATE_ENGINE_LAMINAS => "Moteur Laminas (PhpRenderer)", self::TEMPLATE_ENGINE_TWIG => "Moteur Twig", self::TEMPLATE_ENGINE_TWIGLIGHT => "Moteur Twig Basique", ]; private ?int $id = null; Loading Loading @@ -95,7 +97,9 @@ class Template implements ResourceInterface */ public function requiresTextEditing(): bool { return $this->getEngine() !== Template::TEMPLATE_ENGINE_DEFAULT; return $this->getEngine() !== Template::TEMPLATE_ENGINE_DEFAULT && $this->getEngine() !== Template::TEMPLATE_ENGINE_TWIGLIGHT; } public function getDescription(): ?string Loading src/UnicaenRenderer/Service/TemplateEngine/TwigLight/TwigLightTemplateEngine.php 0 → 100644 +67 −0 Original line number Diff line number Diff line <?php namespace UnicaenRenderer\Service\TemplateEngine\TwigLight; use BadMethodCallException; use RuntimeException; use Twig\Environment; use Twig\Error\Error; use Twig\Loader\ArrayLoader; use UnicaenRenderer\Entity\Db\Macro; use UnicaenRenderer\Service\TemplateEngine\AbstractTemplateEngine; use UnicaenRenderer\Service\TemplateEngine\Twig\TwigTemplateEngine; class TwigLightTemplateEngine extends TwigTemplateEngine { // protected ArrayLoader $twigLoader; // protected Environment $twig; // // public function __construct() // { // $this->twigLoader = new ArrayLoader(); // $this->twig = new Environment($this->twigLoader, [ //// 'cache' => '/path/to/compilation_cache', // ]); // } // // public function checkTemplate(): array // { // throw new BadMethodCallException("Non supporté !"); // } // // public function renderTemplateSujet(): string // { // $templateName = $this->template->getCode() . '_sujet'; // $this->twigLoader->setTemplate($templateName, $this->template->getSujet()); // try { // $content = $this->twig->render($templateName, $this->variables); // } catch (Error $e) { // throw new RuntimeException("Erreur rencontrée lors de la génération Twig", null, $e); // } // // return $content; // } // // public function renderTemplateCorps(): string // { // $templateName = $this->template->getCode() . '_corps'; // $this->twigLoader->setTemplate($templateName, $this->template->getCorps()); // try { // $content = $this->twig->render($templateName, $this->variables); // } catch (Error $e) { // throw new RuntimeException("Erreur rencontrée lors de la génération Twig", null, $e); // } // // $texte = "<style>"; // $texte .= $this->template->getCss(); // $texte .= "</style>"; // $texte .= $content; // // return $texte; // } // // public function generateMacroSourceCode(Macro $macro): string // { // return '{{ ' . $macro->getVariable() . '.' . $macro->getMethode() . ' }}'; // } } No newline at end of file src/UnicaenRenderer/Service/TemplateEngine/TwigLight/TwigLightTemplateEngineFactory.php 0 → 100644 +14 −0 Original line number Diff line number Diff line <?php namespace UnicaenRenderer\Service\TemplateEngine\TwigLight; use Laminas\ServiceManager\Factory\FactoryInterface; use Psr\Container\ContainerInterface; class TwigLightTemplateEngineFactory implements FactoryInterface { public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null): TwigLightTemplateEngine { return new TwigLightTemplateEngine(); } } No newline at end of file src/UnicaenRenderer/Service/TemplateEngineManager/TemplateEngineManager.php +4 −0 Original line number Diff line number Diff line Loading @@ -11,6 +11,8 @@ use UnicaenRenderer\Service\TemplateEngine\Laminas\LaminasTemplateEngineFactory; use UnicaenRenderer\Service\TemplateEngine\TemplateEngineInterface; use UnicaenRenderer\Service\TemplateEngine\Twig\TwigTemplateEngine; use UnicaenRenderer\Service\TemplateEngine\Twig\TwigTemplateEngineFactory; use UnicaenRenderer\Service\TemplateEngine\TwigLight\TwigLightTemplateEngine; use UnicaenRenderer\Service\TemplateEngine\TwigLight\TwigLightTemplateEngineFactory; class TemplateEngineManager extends AbstractPluginManager { Loading @@ -20,12 +22,14 @@ class TemplateEngineManager extends AbstractPluginManager DefaultTemplateEngine::class => DefaultTemplateEngineFactory::class, LaminasTemplateEngine::class => LaminasTemplateEngineFactory::class, TwigTemplateEngine::class => TwigTemplateEngineFactory::class, TwigLightTemplateEngine::class => TwigLightTemplateEngineFactory::class, ]; protected $aliases = [ Template::TEMPLATE_ENGINE_DEFAULT => DefaultTemplateEngine::class, Template::TEMPLATE_ENGINE_LAMINAS => LaminasTemplateEngine::class, Template::TEMPLATE_ENGINE_TWIG => TwigTemplateEngine::class, Template::TEMPLATE_ENGINE_TWIGLIGHT => TwigLightTemplateEngine::class, ]; /** Loading Loading
src/UnicaenRenderer/Entity/Db/Template.php +5 −1 Original line number Diff line number Diff line Loading @@ -32,10 +32,12 @@ class Template implements ResourceInterface const TEMPLATE_ENGINE_DEFAULT = 'default'; const TEMPLATE_ENGINE_LAMINAS = 'laminas'; const TEMPLATE_ENGINE_TWIG = 'twig'; const TEMPLATE_ENGINE_TWIGLIGHT = 'twiglight'; const TEMPLATE_ENGINES = [ self::TEMPLATE_ENGINE_DEFAULT => "Moteur par défaut", self::TEMPLATE_ENGINE_LAMINAS => "Moteur Laminas (PhpRenderer)", self::TEMPLATE_ENGINE_TWIG => "Moteur Twig", self::TEMPLATE_ENGINE_TWIGLIGHT => "Moteur Twig Basique", ]; private ?int $id = null; Loading Loading @@ -95,7 +97,9 @@ class Template implements ResourceInterface */ public function requiresTextEditing(): bool { return $this->getEngine() !== Template::TEMPLATE_ENGINE_DEFAULT; return $this->getEngine() !== Template::TEMPLATE_ENGINE_DEFAULT && $this->getEngine() !== Template::TEMPLATE_ENGINE_TWIGLIGHT; } public function getDescription(): ?string Loading
src/UnicaenRenderer/Service/TemplateEngine/TwigLight/TwigLightTemplateEngine.php 0 → 100644 +67 −0 Original line number Diff line number Diff line <?php namespace UnicaenRenderer\Service\TemplateEngine\TwigLight; use BadMethodCallException; use RuntimeException; use Twig\Environment; use Twig\Error\Error; use Twig\Loader\ArrayLoader; use UnicaenRenderer\Entity\Db\Macro; use UnicaenRenderer\Service\TemplateEngine\AbstractTemplateEngine; use UnicaenRenderer\Service\TemplateEngine\Twig\TwigTemplateEngine; class TwigLightTemplateEngine extends TwigTemplateEngine { // protected ArrayLoader $twigLoader; // protected Environment $twig; // // public function __construct() // { // $this->twigLoader = new ArrayLoader(); // $this->twig = new Environment($this->twigLoader, [ //// 'cache' => '/path/to/compilation_cache', // ]); // } // // public function checkTemplate(): array // { // throw new BadMethodCallException("Non supporté !"); // } // // public function renderTemplateSujet(): string // { // $templateName = $this->template->getCode() . '_sujet'; // $this->twigLoader->setTemplate($templateName, $this->template->getSujet()); // try { // $content = $this->twig->render($templateName, $this->variables); // } catch (Error $e) { // throw new RuntimeException("Erreur rencontrée lors de la génération Twig", null, $e); // } // // return $content; // } // // public function renderTemplateCorps(): string // { // $templateName = $this->template->getCode() . '_corps'; // $this->twigLoader->setTemplate($templateName, $this->template->getCorps()); // try { // $content = $this->twig->render($templateName, $this->variables); // } catch (Error $e) { // throw new RuntimeException("Erreur rencontrée lors de la génération Twig", null, $e); // } // // $texte = "<style>"; // $texte .= $this->template->getCss(); // $texte .= "</style>"; // $texte .= $content; // // return $texte; // } // // public function generateMacroSourceCode(Macro $macro): string // { // return '{{ ' . $macro->getVariable() . '.' . $macro->getMethode() . ' }}'; // } } No newline at end of file
src/UnicaenRenderer/Service/TemplateEngine/TwigLight/TwigLightTemplateEngineFactory.php 0 → 100644 +14 −0 Original line number Diff line number Diff line <?php namespace UnicaenRenderer\Service\TemplateEngine\TwigLight; use Laminas\ServiceManager\Factory\FactoryInterface; use Psr\Container\ContainerInterface; class TwigLightTemplateEngineFactory implements FactoryInterface { public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null): TwigLightTemplateEngine { return new TwigLightTemplateEngine(); } } No newline at end of file
src/UnicaenRenderer/Service/TemplateEngineManager/TemplateEngineManager.php +4 −0 Original line number Diff line number Diff line Loading @@ -11,6 +11,8 @@ use UnicaenRenderer\Service\TemplateEngine\Laminas\LaminasTemplateEngineFactory; use UnicaenRenderer\Service\TemplateEngine\TemplateEngineInterface; use UnicaenRenderer\Service\TemplateEngine\Twig\TwigTemplateEngine; use UnicaenRenderer\Service\TemplateEngine\Twig\TwigTemplateEngineFactory; use UnicaenRenderer\Service\TemplateEngine\TwigLight\TwigLightTemplateEngine; use UnicaenRenderer\Service\TemplateEngine\TwigLight\TwigLightTemplateEngineFactory; class TemplateEngineManager extends AbstractPluginManager { Loading @@ -20,12 +22,14 @@ class TemplateEngineManager extends AbstractPluginManager DefaultTemplateEngine::class => DefaultTemplateEngineFactory::class, LaminasTemplateEngine::class => LaminasTemplateEngineFactory::class, TwigTemplateEngine::class => TwigTemplateEngineFactory::class, TwigLightTemplateEngine::class => TwigLightTemplateEngineFactory::class, ]; protected $aliases = [ Template::TEMPLATE_ENGINE_DEFAULT => DefaultTemplateEngine::class, Template::TEMPLATE_ENGINE_LAMINAS => LaminasTemplateEngine::class, Template::TEMPLATE_ENGINE_TWIG => TwigTemplateEngine::class, Template::TEMPLATE_ENGINE_TWIGLIGHT => TwigLightTemplateEngine::class, ]; /** Loading