This PR was merged into the 3.x branch.
Discussion
----------
Add note to format_datetime explaining how to install required extensions
Commits
-------
d0177b94cd Add note to format_datetime explaining how to install required extensions
This PR was merged into the 3.x branch.
Discussion
----------
Add missing use statements in ExtensionInterface
Fixes#4677
Note: The classes were used specifically in a ``@psalm`-return` doc statement. But as the repository does not have any psalm config, and does not check it in the CI, this seems to have gone unnoticed for a few months.
Commits
-------
8c78952757#4677: Add use statements for classes referenced in the getOperators `@psalm`-return doc
This PR was merged into the 3.x branch.
Discussion
----------
Allow usage of other Markdown converters than CommonMark in LeagueMarkdown
Since the `CommonMarkConverter` from `League\CommonMark` doesn't allow customizing the `Environment` class at construct-time, this simple change allows providing an instance the parent class, so we can both inject a config to the converter AND a custom list of extensions (like `CommonMarkCoreExtension`) via the constructor.
This PR fixes#3581
Commits
-------
81e66e96bf Update LeagueMarkdown.php
This PR was squashed before being merged into the 3.x branch.
Discussion
----------
Escaper performance: avoid static variables
Replace two static variables with `match` expressions.
And bypass a third static variable for the common charset `UTF-8`.
Commits
-------
823f50297b Escaper performance: avoid static variables
This PR was merged into the 3.x branch.
Discussion
----------
Fix compatibility with Symfony 8
Commits
-------
b6a105c952 Fix compatibility with Symfony 8
This PR was merged into the 3.x branch.
Discussion
----------
Add documentation for use_yield option
Documentation was present in the source code, but missing in the docs.
Commits
-------
b8827b412d Add documentation for use_yield option
This PR was merged into the 3.x branch.
Discussion
----------
Coding standard suggestion about empty content
Hi `@fabpot`
As suggested by `@stof` https://github.com/symfony/symfony/pull/60761#discussion_r2140647490
This would allow writing `{#--#}` rather than `{#- -#}` when following the twig coding standard.
Commits
-------
0b93a1fa5a Stof suggestion about empty content
This PR was merged into the 3.x branch.
Discussion
----------
Update templates.rst: Removing duplication
Page: https://twig.symfony.com/doc/3.x/templates.html#dot_operator
Reason: This is repeated a few lines further down.
Commits
-------
a26f43a6a6 Update templates.rst: Removing duplication
This PR was merged into the 3.x branch.
Discussion
----------
[CommonMark] Update configuration keys + allow extra keys for extensions
This PR adds missing keys from the current version of CommonMark (2.7).
It also fixes a bug where extra keys are removed. The original intent was to keep the extra keys, so extensions could be configured as well. Currently, these keys are removed, meaning extensions can not be configured.
Original PR #3737.
Commits
-------
a8aadc3e99 Update configuration keys + allow extra keys for extensions
This PR was merged into the 3.x branch.
Discussion
----------
replace typographic quote with straigt single quote
make DOCtor-RST 1.68 happy and account for OskarStark/doctor-rst#2011
Commits
-------
057ea92274 replace typographic quote with straigt single quote
This PR was merged into the 3.x branch.
Discussion
----------
[Docs] Add TwigCsFixer in tools list
Twig CS Fixer is already present in the code style / conventions page, but it feels to me very logical we see it on the "integration / tools" page.
Commits
-------
2184db3b9b Add TwigCsFixer in tools list
This PR was squashed before being merged into the 3.x branch.
Discussion
----------
Fix ExtensionSet usage of BinaryOperatorExpressionParser
This fix both issue of https://github.com/twigphp/Twig/issues/4632
Commits
-------
e14a2474fb Fix warning
00d29e6657 Fix instantiation
This PR was squashed before being merged into the 3.x branch.
Discussion
----------
Create attributes `AsTwigFilter`, `AsTwigFunction` and `AsTwigTest` to ease extension development
One drawback to writing extensions at present is that the declaration of functions/filters/tests is not directly adjacent to the methods. It's worse for runtime extensions because they need to be in 2 different classes. See [`SerializerExtension`](https://github.com/symfony/symfony/blob/7.0/src/Symfony/Bridge/Twig/Extension/SerializerExtension.php) and [`SerializerRuntime`](https://github.com/symfony/symfony/blob/7.0/src/Symfony/Bridge/Twig/Extension/SerializerRuntime.php) as an example.
By using attributes for filters, functions and tests definition, we can make writing extensions more expressive, and use reflection to detect particular options (`needs_environment`, `needs_context`, `is_variadic`).
Example if we implemented the `formatDate` filter: https://github.com/twigphp/Twig/blob/aeeec9a5e907a79e50a6bb78979154599401726e/extra/intl-extra/IntlExtension.php#L392-L395
By using the `AsTwigFilter` attribute, it is not necessary to create the `getFilters()` method. The `needs_environment` option is detected from method signature. The name is still required as the method naming convention (camelCase) doesn't match with Twig naming convention (snake_case).
```php
use Twig\Extension\Attribute\AsTwigFilter;
class IntlExtension
{
#[AsTwigFilter(name: 'format_date')]
public function formatDate(Environment $env, $date, ?string $dateFormat = 'medium', string $pattern = '', $timezone = null, string $calendar = 'gregorian', string $locale = null): string
{
return $this->formatDateTime($env, $date, $dateFormat, 'none', $pattern, $timezone, $calendar, $locale);
}
}
```
This approach does not totally replace the current definition of extensions, which is still necessary for advanced needs. It does, however, make for more pleasant reading and writing.
This makes writing lazy-loaded runtime extension the easiest way to create Twig extension in Symfony: https://github.com/symfony/symfony/pull/52748
Related to https://github.com/symfony/symfony/issues/50016
Is there any need to cache the parsing of method attributes? They are only read at compile time, but that can have a performance impact during development or when using dynamic templates.
Commits
-------
5886907b28 Create attributes `AsTwigFilter`, `AsTwigFunction` and `AsTwigTest` to ease extension development