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
The table introductory paragraph says operator with lowest precedence are listed first ( I assume it means "listed first in the operator table" ).
However, the table starts with a precedence of 500, which seems to be the highest.
I must be misreading this ?
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
This PR was merged into the 3.x branch.
Discussion
----------
[Docs] Replace `=` by `:` in code examples
Replace `=` by `:` in code examples
* function/include
* filters/format_number
Commits
-------
84b0499dbd [Docs] Replace `=` by `:` in code examples
This PR was merged into the 3.x branch.
Discussion
----------
[Doc] Fix `code-block` in html_cva
There is no `terminal` code-block in the current Twig documentation.
Using `bash` here instead is more in line with the other pages.
(...and will allow to simplify CSS needed for code blocks)
Commits
-------
a7c0482dc9 [Doc] Fix `code-block` in html_cva
This PR was merged into the 3.x branch.
Discussion
----------
fix: update extension references in docs to use backticks
Commits
-------
239a060d59 fix: update extension references in docs to use backticks
There is no `terminal` code-block in the current Twig documentation.
Using `bash` here instead is more in line with the other pages.
(...and will allow to simplify CSS needed for code blocks)
This PR was merged into the 3.x branch.
Discussion
----------
Use `:` instead of `=` for named argument in the docs
Commits
-------
ccec90c85c Use `:` instead of `=` for named argument in the docs
This PR was merged into the 3.x branch.
Discussion
----------
use EmptyNode instead of an Nodes instance without children
Commits
-------
e31a6e4534 use EmptyNode instead of an Nodes instance without children
This PR was merged into the 3.x branch.
Discussion
----------
Fix `ModuleNode` instanciation when `$embeddedTemplates` is null
Related to https://github.com/symfony/symfony/pull/59886, in case `$embeddedTemplates` is null
Commits
-------
81c1fcc7d6 Fix `ModuleNode` instanciation when `$embeddedTemplates` is null
This PR was merged into the 3.x branch.
Discussion
----------
reduce the number of deprecations being triggered
Triggering deprecations for specific arguments is not needed as the method itself is deprecated as well.
Commits
-------
155d0faab4 reduce the number of deprecations being triggered
This PR was merged into the 3.x branch.
Discussion
----------
merge the Nodes and Node sections
Commits
-------
f8b01ebd98 merge the Nodes and Node sections
This PR was merged into the 3.x branch.
Discussion
----------
Avoid polluting ModuleNode::toString() with embedded templates
Commits
-------
3d760aec1c Avoid polluting ModuleNode::toString() with embedded templates
This PR was merged into the 3.x branch.
Discussion
----------
remove not needed code
Commits
-------
719bba9d1e Simplify code
da64c42dc2 Add tests
53facb74c1 remove not needed code
This PR was merged into the 3.x branch.
Discussion
----------
Improve docs on creating new tags
/cc `@smnandre`
Commits
-------
96dade342f Improve docs on creating new tags