Commit Graph

1400 Commits

Author SHA1 Message Date
Felds Liscia 263c04fd1f Add null-safe operator 2026-01-17 14:57:47 +01:00
Christian Flothmann 55cb67f87d bump version 2026-01-16 11:26:26 +01:00
Fabien Potencier 94c8bdd6a6 Add === and !== operators 2026-01-14 09:58:48 +01:00
Fabien Potencier 2376bbaf3e Fix spread operator behavior 2026-01-12 08:54:38 +01:00
Fabien Potencier 4537dff30b Fix typo 2026-01-05 21:37:31 +01:00
Ondřej Machulda 86997d1bef Fix opcache preload warning for unlinked anonymous class 2026-01-05 19:11:58 +01:00
Fabien Potencier aa8635647f Bump version 2025-12-14 12:29:52 +01:00
Fabien Potencier 946ddeafa3 Prepare the 3.22.2 release 2025-12-14 12:28:47 +01:00
Andreas 4d98cce4e4 Avoid ord deprecation in PHP 8.5
Change the one usage of ord() in Twig where a multibyte character can trigger the new deprecation in PHP 8.5, which is in the `html_attr` escape functionality, previously leading to:

ord(): Providing a string that is not one byte long is deprecated. Use ord($str[0]) instead"
2025-12-14 11:29:02 +01:00
Younes ENNAJI 473653d19b [Core] Fix cycle() with non-countable ArrayAccess+Traversable objects 2025-11-23 13:20:23 +01:00
Fabien Potencier 34e874e536 Bump version 2025-11-16 17:02:42 +01:00
Fabien Potencier 1de2ec1fc4 Prepare the 3.22.1 release 2025-11-16 17:01:12 +01:00
Thomas Cochard 40248e4ca9 CoreExtension : Make error message more readable 2025-11-15 08:57:35 +01:00
Fabien Potencier d58c8be15d minor #4698 Add throw tag to parse methods (VincentLanglet)
This PR was merged into the 3.x branch.

Discussion
----------

Add throw tag to parse methods

Hi `@fabpot`, with PHPStan improving every day his exception checking, it's useful to have well documented method.

I didn't update all of them (there are too many), and focus on the one I have issue with:
- Almost all the InfixExpressionParserInterface/PrefixExpressionParserInterface implements throws a SyntaxError in parse method
- Parser::parse method is catching SyntaxError and rethrowing them so it should be added to the phpdoc
- Since Parser::parse catch Parser::subparse, it would be useful to add the phpdoc to subparse

Commits
-------

790eee7ae0 Add throw tag to parse methods
2025-11-05 13:48:28 +01:00
Fabien Potencier f663cc345b Bump version 2025-10-29 11:57:52 -04:00
Fabien Potencier 4509984193 Prepare the 3.22.0 release 2025-10-29 11:56:47 -04:00
Nicolas Grekas 9ae75d315c Fix accessing arrays with stringable objects as key 2025-10-24 14:19:16 +02:00
Vincent Langlet 790eee7ae0 Add throw tag to parse methods 2025-10-18 12:28:49 +02:00
Simon André e4d7915702 Compile 'index' with repr (not string) in EmbedNode
Before this fix, the generated Template code had quotes around the
index (integer) parameter value.
2025-09-25 08:28:51 +02:00
Vincent Langlet cc12df995c Introduce registerUndefinedTestCallback 2025-09-16 07:40:27 +02:00
Fabien Potencier 32f88a2368 feature #4689 Support two words test guard (VincentLanglet)
This PR was squashed before being merged into the 3.x branch.

Discussion
----------

Support two words test guard

Extracted from https://github.com/twigphp/Twig/pull/4687

Commits
-------

30977bdea9 Support two words test guard
2025-09-15 07:51:44 +02:00
Vincent Langlet 30977bdea9 Support two words test guard 2025-09-15 07:51:41 +02:00
Fabien Potencier 57a2f85783 Bump version 2025-09-15 07:48:29 +02:00
Christophe Coevoet 62747cee27 Avoid errors when failing to guess the template info for an error 2025-09-02 14:21:58 +02:00
Fabien Potencier 806049f7a2 Fix compatibility layer 2025-08-17 19:23:48 +02:00
Kevin van Sonsbeek 8c78952757 #4677: Add use statements for classes referenced in the getOperators @psalm-return doc 2025-08-04 21:13:52 +02:00
Nicolas Grekas fec73458dc minor #4664 CS fixes (nicolas-grekas)
This PR was merged into the 3.x branch.

Discussion
----------

CS fixes

Commits
-------

85a4817128 CS fixes
2025-07-29 10:10:06 +02:00
Nicolas Grekas 85a4817128 CS fixes 2025-07-29 10:07:07 +02:00
Gregor Harlan 823f50297b Escaper performance: avoid static variables 2025-07-12 15:47:09 +02:00
Fabien Potencier 12a40e714c Bump version 2025-05-03 09:23:07 +02:00
Fabien Potencier 285123877d Prepare the 3.21.1 release 2025-05-03 09:21:55 +02:00
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 2025-05-02 15:18:20 +02: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 09f9a22310 Fix wrong array index (again) 2025-03-21 09:42:17 +01:00
Christian Flothmann e31a6e4534 use EmptyNode instead of an Nodes instance without children 2025-02-28 22:12:08 +01:00
Alexandre Daubois 81c1fcc7d6 Fix ModuleNode instanciation when $embeddedTemplates is null 2025-02-28 20:12:40 +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 719bba9d1e Simplify code 2025-02-28 08:54:29 +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 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 4a121d90c6 Sync Error file and line 2025-02-26 13:26:24 +01:00
Fabien Potencier 7cde13f6c9 bug #4595 Improve error reporting (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Improve error reporting

Commits
-------

d5dc3eee99 Improve error reporting
2025-02-22 18:27:58 +01:00