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, ];