From cdc475cdd2bd1067ae498be27b9b8df9b2eb4b51 Mon Sep 17 00:00:00 2001 From: Jan Storm Date: Mon, 9 Sep 2024 16:59:58 +0200 Subject: [PATCH 1/2] Makes the TemplateBoxNode yield ready (#412) --- src/FlashMessage/FlashManager.php | 4 ++-- src/Node/TemplateBoxNode.php | 7 +++++-- tests/App/AppKernel.php | 2 +- tests/Node/TemplateBoxNodeTest.php | 16 ++++++++++------ 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/FlashMessage/FlashManager.php b/src/FlashMessage/FlashManager.php index 1d61cd0..58612d6 100644 --- a/src/FlashMessage/FlashManager.php +++ b/src/FlashMessage/FlashManager.php @@ -29,7 +29,7 @@ final class FlashManager implements FlashManagerInterface public function __construct( private RequestStack $requestStack, private array $types, - private array $cssClasses + private array $cssClasses, ) { } @@ -127,7 +127,7 @@ private function getSession(): SessionInterface $session = $request->getSession(); if (!$session instanceof Session) { - throw new \UnexpectedValueException(sprintf( + throw new \UnexpectedValueException(\sprintf( 'The flash manager only works with a "%s" session.', Session::class )); diff --git a/src/Node/TemplateBoxNode.php b/src/Node/TemplateBoxNode.php index 06f7163..fb78062 100644 --- a/src/Node/TemplateBoxNode.php +++ b/src/Node/TemplateBoxNode.php @@ -13,10 +13,12 @@ namespace Sonata\Twig\Node; +use Twig\Attribute\YieldReady; use Twig\Compiler; use Twig\Node\Expression\AbstractExpression; use Twig\Node\Node; +#[YieldReady] final class TemplateBoxNode extends Node { /** @@ -29,7 +31,7 @@ public function __construct( AbstractExpression $message, private bool $enabled, ?int $lineno = null, - ?string $tag = null + ?string $tag = null, ) { parent::__construct(['message' => $message], [], $lineno ?? 0, $tag); } @@ -54,7 +56,8 @@ public function compile(Compiler $compiler): void " CODE; + $display = class_exists(YieldReady::class) ? 'yield' : 'echo'; $compiler - ->write("echo $message;"); + ->write("$display $message;"); } } diff --git a/tests/App/AppKernel.php b/tests/App/AppKernel.php index b819a27..2ba4542 100644 --- a/tests/App/AppKernel.php +++ b/tests/App/AppKernel.php @@ -56,7 +56,7 @@ public function getProjectDir(): string protected function configureRoutes(RoutingConfigurator $routes): void { - $routes->import(sprintf('%s/config/routes.yaml', $this->getProjectDir())); + $routes->import(\sprintf('%s/config/routes.yaml', $this->getProjectDir())); } protected function configureContainer(ContainerBuilder $containerBuilder, LoaderInterface $loader): void diff --git a/tests/Node/TemplateBoxNodeTest.php b/tests/Node/TemplateBoxNodeTest.php index ad1c7fe..ecc729c 100644 --- a/tests/Node/TemplateBoxNodeTest.php +++ b/tests/Node/TemplateBoxNodeTest.php @@ -14,6 +14,7 @@ namespace Sonata\Twig\Tests\Node; use Sonata\Twig\Node\TemplateBoxNode; +use Twig\Attribute\YieldReady; use Twig\Environment; use Twig\Node\Expression\ConstantExpression; use Twig\Node\Node; @@ -51,19 +52,22 @@ public function getTests(): iterable 1, 'sonata_template_box' ); - yield [$nodeEn, <<<'EOF' + + $display = class_exists(YieldReady::class) ? 'yield' : 'echo'; + + yield [$nodeEn, << + $display "
This is the default message -
This file can be found in {$this->getTemplateName()}.
+
This file can be found in {\$this->getTemplateName()}.
"; EOF, null, false, ]; - yield [$nodeFr, <<<'EOF' + yield [$nodeFr, << + $display "
Ceci est le message par défaut -
This file can be found in {$this->getTemplateName()}.
+
This file can be found in {\$this->getTemplateName()}.
"; EOF, null, false, ]; From 4b23542aad4b089c4376b4b768f7bd60a6102d69 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Mon, 9 Sep 2024 17:02:15 +0200 Subject: [PATCH 2/2] 2.5.0 (#413) --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13c6c46..f99f6d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [2.5.0](https://github.com/sonata-project/twig-extensions/compare/2.4.0...2.5.0) - 2024-09-09 +### Added +- [[#412](https://github.com/sonata-project/twig-extensions/pull/412)] Support for twig's "yield" mode for output generation. ([@JanStorm](https://github.com/JanStorm)) + +### Fixed +- [[#409](https://github.com/sonata-project/twig-extensions/pull/409)] Symfony 7.1 deprecation about `Symfony\Component\HttpKernel\DependencyInjection\Extension` usage ([@VincentLanglet](https://github.com/VincentLanglet)) + ## [2.4.0](https://github.com/sonata-project/twig-extensions/compare/2.3.0...2.4.0) - 2023-11-23 ### Added - [[#392](https://github.com/sonata-project/twig-extensions/pull/392)] Symfony 7 support ([@VincentLanglet](https://github.com/VincentLanglet))