Commit Graph

7227 Commits

Author SHA1 Message Date
Vincent Langlet e14a2474fb Fix warning 2025-05-02 17:41:32 +02:00
Vincent Langlet 00d29e6657 Fix instantiation 2025-05-02 17:39:47 +02:00
Fabien Potencier 06eb9eafe2 Bump version 2025-05-02 15:19:55 +02:00
Fabien Potencier b54a265712 Prepare the 3.21.0 release v3.21.0 2025-05-02 15:18:20 +02:00
Fabien Potencier fde4de9fd9 minor #4626 Tweaks html_cva docs (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Tweaks html_cva docs

Commits
-------

f14f2208f9 Tweaks html_cva docs
2025-03-30 09:52:47 +02:00
Fabien Potencier f14f2208f9 Tweaks html_cva docs 2025-03-30 09:51:16 +02:00
Fabien Potencier 7b2fe7cf14 minor #4613 Update html_cva.rst (seb-jean)
This PR was merged into the 3.x branch.

Discussion
----------

Update html_cva.rst

Commits
-------

1a46d12033 Update html_cva.rst
2025-03-30 09:50:03 +02:00
Fabien Potencier 999092d9c4 minor #4621 Update CHANGELOG (andreybolonin)
This PR was merged into the 3.x branch.

Discussion
----------

Update CHANGELOG

Commits
-------

92f7a5e924 Update CHANGELOG
2025-03-26 07:31:45 +01:00
Andrey Bolonin 92f7a5e924 Update CHANGELOG 2025-03-26 07:31:36 +01:00
Fabien Potencier 8a7d912deb feature #3916 Create attributes AsTwigFilter, AsTwigFunction and AsTwigTest to ease extension development (GromNaN)
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
2025-03-24 22:34:23 +01:00
Jérôme Tamarelle 5886907b28 Create attributes AsTwigFilter, AsTwigFunction and AsTwigTest to ease extension development 2025-03-24 22:34:21 +01:00
Fabien Potencier 3c7c97e669 bug #4619 Fix wrong array index (again) (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Fix wrong array index (again)

Commits
-------

09f9a22310 Fix wrong array index (again)
2025-03-21 10:06:23 +01:00
Fabien Potencier 09f9a22310 Fix wrong array index (again) 2025-03-21 09:42:17 +01:00
Fabien Potencier 77a6da9cc7 minor #4616 [Docs] Replace = by : in code examples (smnandre)
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
2025-03-20 22:33:01 +01:00
Fabien Potencier 2a17b4f495 minor #4617 [Doc] Fix code-block in html_cva (smnandre)
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
2025-03-20 22:32:34 +01:00
Fabien Potencier 7b9aee98e1 minor #4618 fix: update extension references in docs to use backticks (smnandre)
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
2025-03-20 22:32:08 +01:00
Simon André 239a060d59 fix: update extension references in docs to use backticks 2025-03-20 08:35:48 +01:00
Simon André a7c0482dc9 [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)
2025-03-20 07:30:17 +01:00
Simon André 84b0499dbd [Docs] Replace = by : in code examples
* function/include
* filters/format_number
2025-03-20 07:23:44 +01:00
Fabien Potencier 95596ce95a minor #4615 fix: deprecated documentation (Garfield-fr)
This PR was merged into the 3.x branch.

Discussion
----------

fix: deprecated documentation

Commits
-------

c325912724 fix: deprecated documentation
2025-03-14 13:18:50 -07:00
Bertrand Zuchuat c325912724 fix: deprecated documentation
Co-authored-by: Bertrand Zuchuat <bertrand.zuchuat@gmail.com>
2025-03-14 21:10:34 +01:00
seb-jean 1a46d12033 Update html_cva.rst 2025-03-12 18:12:07 +01:00
Fabien Potencier 8440cf4ac2 minor #4610 Use : instead of = for named argument in the docs (jdreesen)
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
2025-03-06 18:33:52 +01:00
Jacob Dreesen ccec90c85c Use : instead of = for named argument in the docs 2025-03-06 17:34:44 +01:00
Fabien Potencier ffd515977e minor #4608 use EmptyNode instead of an Nodes instance without children (xabbuh)
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
2025-03-01 08:08:39 +01:00
Christian Flothmann e31a6e4534 use EmptyNode instead of an Nodes instance without children 2025-02-28 22:12:08 +01:00
Fabien Potencier 4692c36145 minor #4607 Fix ModuleNode instanciation when $embeddedTemplates is null (alexandre-daubois)
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
2025-02-28 21:07:09 +01:00
Alexandre Daubois 81c1fcc7d6 Fix ModuleNode instanciation when $embeddedTemplates is null 2025-02-28 20:12:40 +01:00
Fabien Potencier d6c1112f96 minor #4605 reduce the number of deprecations being triggered (xabbuh)
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
2025-02-28 16:10:01 +01:00
Fabien Potencier 74ad2aa9fd minor #4606 merge the Nodes and Node sections (xabbuh)
This PR was merged into the 3.x branch.

Discussion
----------

merge the Nodes and Node sections

Commits
-------

f8b01ebd98 merge the Nodes and Node sections
2025-02-28 16:09:21 +01:00
Christian Flothmann f8b01ebd98 merge the Nodes and Node sections 2025-02-28 14:40:03 +01:00
Christian Flothmann 155d0faab4 reduce the number of deprecations being triggered
Triggering deprecations for specific arguments is not needed as the method
itself is deprecated as well.
2025-02-28 14:36:39 +01:00
Fabien Potencier 76b86aa9da Add missing @deprecated tag 2025-02-28 09:01:15 +01:00
Fabien Potencier c0db761477 minor #4604 Avoid polluting ModuleNode::toString() with embedded templates (fabpot)
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
2025-02-28 08:58:45 +01:00
Fabien Potencier 3d760aec1c Avoid polluting ModuleNode::toString() with embedded templates 2025-02-28 08:57:55 +01:00
Fabien Potencier 1fee48eb3b minor #4603 remove not needed code (xabbuh, fabpot)
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
2025-02-28 08:56:53 +01:00
Fabien Potencier 719bba9d1e Simplify code 2025-02-28 08:54:29 +01:00
Fabien Potencier da64c42dc2 Add tests 2025-02-28 08:52:34 +01:00
Fabien Potencier 71f83ecd0e Tweak Sandbox docs 2025-02-28 07:30:52 +01:00
Fabien Potencier 932a584971 minor #4601 Improve docs on creating new tags (fabpot)
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
2025-02-27 11:10:17 +01:00
Fabien Potencier 96dade342f Improve docs on creating new tags 2025-02-27 10:07:32 +01:00
Christian Flothmann 53facb74c1 remove not needed code 2025-02-27 09:49:34 +01:00
Fabien Potencier 4e1fa3aa43 Remove obsolete comment 2025-02-26 22:19:38 +01:00
Fabien Potencier b86fd0a059 Remove obsolete files 2025-02-26 22:13:11 +01:00
Fabien Potencier b6e7097c02 minor #4600 Move some tests (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Move some tests

Commits
-------

56204e951a Move some tests
2025-02-26 22:11:16 +01:00
Fabien Potencier 56204e951a Move some tests 2025-02-26 22:10:10 +01:00
Fabien Potencier 33a08191b9 bug #4599 Fix Error when the trace has Twig file/line information instead of the original PHP info (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Fix Error when the trace has Twig file/line information instead of the original PHP info

See https://github.com/twigphp/Twig/pull/4592/files#r1966616393
/cc `@smnandre`

Commits
-------

7b43bd0fd7 Fix Error when the trace has Twig file/line information instead of the original PHP info
2025-02-26 21:54:22 +01:00
Fabien Potencier 7b43bd0fd7 Fix Error when the trace has Twig file/line information instead of the original PHP info 2025-02-26 21:02:58 +01:00
Fabien Potencier 02118c7ebd bug #4598 Sync Error file and line (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Sync Error file and line

The PHP exception file and name go together. So, we should only update the line number only if we have a file.

Commits
-------

4a121d90c6 Sync Error file and line
2025-02-26 13:39:00 +01:00
Fabien Potencier 4a121d90c6 Sync Error file and line 2025-02-26 13:26:24 +01:00