Skip to content

Commit

Permalink
Merge 2.x into 3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
SonataCI authored Sep 10, 2024
2 parents f92c52b + 4b23542 commit e1660d1
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 11 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions src/FlashMessage/FlashManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class FlashManager implements FlashManagerInterface
public function __construct(
private RequestStack $requestStack,
private array $types,
private array $cssClasses
private array $cssClasses,
) {
}

Expand Down Expand Up @@ -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
));
Expand Down
7 changes: 5 additions & 2 deletions src/Node/TemplateBoxNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
/**
Expand All @@ -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);
}
Expand All @@ -54,7 +56,8 @@ public function compile(Compiler $compiler): void
</div>"
CODE;

$display = class_exists(YieldReady::class) ? 'yield' : 'echo';
$compiler
->write("echo $message;");
->write("$display $message;");
}
}
2 changes: 1 addition & 1 deletion tests/App/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 10 additions & 6 deletions tests/Node/TemplateBoxNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -51,19 +52,22 @@ public function getTests(): iterable
1,
'sonata_template_box'
);
yield [$nodeEn, <<<'EOF'

$display = class_exists(YieldReady::class) ? 'yield' : 'echo';

yield [$nodeEn, <<<EOF
// line 1
echo "<div class='alert alert-default alert-info'>
$display "<div class='alert alert-default alert-info'>
<strong>This is the default message</strong>
<div>This file can be found in <code>{$this->getTemplateName()}</code>.</div>
<div>This file can be found in <code>{\$this->getTemplateName()}</code>.</div>
</div>";
EOF, null, false,
];
yield [$nodeFr, <<<'EOF'
yield [$nodeFr, <<<EOF
// line 1
echo "<div class='alert alert-default alert-info'>
$display "<div class='alert alert-default alert-info'>
<strong>Ceci est le message par défaut</strong>
<div>This file can be found in <code>{$this->getTemplateName()}</code>.</div>
<div>This file can be found in <code>{\$this->getTemplateName()}</code>.</div>
</div>";
EOF, null, false,
];
Expand Down

0 comments on commit e1660d1

Please sign in to comment.