Commit Graph

7780 Commits

Author SHA1 Message Date
Fabien Potencier 56a7aa4e4f Merge branch '3.x' into 4.x
* 3.x:
  use getShareDir as an indicator of Symfony version
  Add 'invoke' to filters index
  [Core] Fix cycle() with non-countable ArrayAccess+Traversable objects
  Update .gitattributes to exclude phpstan configs
  Bump version
  Prepare the 3.22.1 release
  Update CHANGELOG
  `CoreExtension` : Make error message more readable
  Add caution note for random function usage
  Add throw tag to parse methods
2025-12-05 09:58:08 +01:00
Fabien Potencier 8308f7fa24 bug #4722 use getShareDir as an indicator of Symfony version (tacman)
This PR was squashed before being merged into the 3.x branch.

Discussion
----------

use getShareDir as an indicator of Symfony version

Proposal to fix #4719 , replaces #4721

Commits
-------

c4dcd0bb8c use getShareDir as an indicator of Symfony version
2025-12-05 09:51:55 +01:00
Tac Tacelosky c4dcd0bb8c use getShareDir as an indicator of Symfony version 2025-12-05 09:51:53 +01:00
Fabien Potencier 8074ddcab8 minor #4714 Add 'invoke' to filters index (webda2l)
This PR was merged into the 3.x branch.

Discussion
----------

Add 'invoke' to filters index

Missing from https://github.com/twigphp/Twig/pull/4518 I think.

Commits
-------

f7daf71acc Add 'invoke' to filters index
2025-11-27 06:52:14 +01:00
David ALLIX f7daf71acc Add 'invoke' to filters index 2025-11-26 20:33:56 +01:00
Fabien Potencier ce6698abd5 bug #4713 Fix cycle() with non-countable ArrayAccess+Traversable objects (yoeunes)
This PR was merged into the 3.x branch.

Discussion
----------

Fix cycle() with non-countable ArrayAccess+Traversable objects

When using `cycle()` with an object that implements `\ArrayAccess` and `\Traversable` but is not `\Countable`, the function currently returns the object instance immediately after triggering the deprecation notice.

This prevents the value from being converted to an array, causing the cycle logic to fail or return the object itself.

This PR removes the early return to ensure `self::toArray()` is called, allowing these objects to be cycled correctly as expected.

**How to test**

```php
$seq = new class implements \ArrayAccess, \IteratorAggregate {
    public function offsetExists($offset): bool { return true; }
    public function offsetGet($offset): mixed { return 'val'; }
    public function offsetSet($offset, $value): void {}
    public function offsetUnset($offset): void {}
    public function getIterator(): \Traversable { yield 'odd'; yield 'even'; }
};

// Should return 'odd', currently returns the $seq object
$result = CoreExtension::cycle($seq, 0);
```

Related to #4241

Commits
-------

473653d19b [Core] Fix cycle() with non-countable ArrayAccess+Traversable objects
2025-11-25 07:55:14 +01:00
Younes ENNAJI 473653d19b [Core] Fix cycle() with non-countable ArrayAccess+Traversable objects 2025-11-23 13:20:23 +01:00
Fabien Potencier 2b7cc0ba9f minor #4712 Update .gitattributes to exclude phpstan configs (williamdes)
This PR was merged into the 3.x branch.

Discussion
----------

Update .gitattributes to exclude phpstan configs

They where added in https://github.com/twigphp/Twig/pull/4458

Versions >= 3.16.0 have the not needed files

Commits
-------

2e0c874776 Update .gitattributes to exclude phpstan configs
2025-11-19 18:29:21 +01:00
William Desportes 2e0c874776 Update .gitattributes to exclude phpstan configs 2025-11-19 14:18:11 +01:00
Fabien Potencier 34e874e536 Bump version 2025-11-16 17:02:42 +01:00
Fabien Potencier 1de2ec1fc4 Prepare the 3.22.1 release v3.22.1 2025-11-16 17:01:12 +01:00
Fabien Potencier 6a6543462b Update CHANGELOG 2025-11-15 09:10:04 +01:00
Fabien Potencier 35a3de7012 minor #4711 CoreExtension : Make error message more readable (tcoch)
This PR was squashed before being merged into the 3.x branch.

Discussion
----------

`CoreExtension` : Make error message more readable

It's a silly little patch, but really improves the readability of the error message IMO ...

Commits
-------

40248e4ca9 `CoreExtension` : Make error message more readable
2025-11-15 08:57:38 +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 2996f0b427 minor #4709 Add caution note for random function usage (xelan)
This PR was merged into the 3.x branch.

Discussion
----------

Add caution note for random function usage

See https://www.php.net/manual/en/function.array-rand.php and https://www.php.net/manual/en/function.mt-rand.php. Users should know that the Twig function is a convenience feature, but unusable e.g. for serious gaming/gambling apps due to the potential predictability and limited value range.

Commits
-------

02c5a4b0b6 Add caution note for random function usage
2025-11-04 14:12:13 +01:00
Andreas Erhard 02c5a4b0b6 Add caution note for random function usage 2025-11-04 11:55:35 +01:00
Fabien Potencier 83f264bcd8 Merge branch '3.x' into 4.x
* 3.x:
  Allow Symfony 8 packages in Twig extra packages
  Fix array typehint for $variants in HtmlExtension
2025-11-02 20:03:33 +01:00
Fabien Potencier 94a363525d minor #4708 Allow Symfony 8 packages in Twig extra packages (javiereguiluz)
This PR was merged into the 3.x branch.

Discussion
----------

Allow Symfony 8 packages in Twig extra packages

I'm testing the upcoming Symfony 8 in some apps, and I have some issues with some Twig extra packages that don't allow installing Symfony 8 packages.

Commits
-------

9a8a1dc1dd Allow Symfony 8 packages in Twig extra packages
2025-11-02 20:01:59 +01:00
Javier Eguiluz 9a8a1dc1dd Allow Symfony 8 packages in Twig extra packages 2025-11-02 12:00:49 +01:00
Fabien Potencier 80fa13c253 minor #4707 Fix array typehint for $variants in HtmlExtension (yoeunes)
This PR was merged into the 3.x branch.

Discussion
----------

Fix array typehint for $variants in HtmlExtension

This PR corrects the array typehint for the `$variants` parameter in the `HtmlExtension::htmlCva` method. It was missing a closing angle bracket (`>`).

Commits
-------

64c87eeaa3 Fix array typehint for $variants in HtmlExtension
2025-10-30 07:16:57 -04:00
Younes ENNAJI 64c87eeaa3 Fix array typehint for $variants in HtmlExtension 2025-10-30 01:26:03 +01:00
Fabien Potencier 7489911802 Merge branch '3.x' into 4.x
* 3.x:
  Bump version
  Prepare the 3.22.0 release
2025-10-29 11:58:22 -04:00
Fabien Potencier f663cc345b Bump version 2025-10-29 11:57:52 -04:00
Fabien Potencier 4509984193 Prepare the 3.22.0 release v3.22.0 2025-10-29 11:56:47 -04:00
Fabien Potencier b03de9de05 Merge branch '3.x' into 4.x
* 3.x:
  Update CHANGELOG
  Fix accessing arrays with stringable objects as key
  Update inky_to_html.rst: Updating link
  Update replace.rst
  [Doc] Tweaks in the escaping article
  Compile 'index' with repr (not string) in EmbedNode
  Introduce registerUndefinedTestCallback
  Fix intl test
  Bump minimum Commonmark requirement
  Support two words test guard
  Bump version
  Improve documentation examples for `enum` and `enum_cases`
  Avoid errors when failing to guess the template info for an error
  Add note to format_datetime explaining how to install required extensions
  Fix compatibility layer
2025-10-29 11:55:46 -04:00
Fabien Potencier a5487c8e05 Update CHANGELOG 2025-10-29 11:53:10 -04:00
Fabien Potencier 9a5887a9fa bug #4704 Fix accessing arrays with stringable objects as key (nicolas-grekas)
This PR was merged into the 3.x branch.

Discussion
----------

Fix accessing arrays with stringable objects as key

Fix #4701

Commits
-------

9ae75d315c Fix accessing arrays with stringable objects as key
2025-10-29 11:47:18 -04:00
Nicolas Grekas 9ae75d315c Fix accessing arrays with stringable objects as key 2025-10-24 14:19:16 +02:00
Fabien Potencier d26e8f2b74 minor #4699 Update inky_to_html.rst: Updating link (ThomasLandauer)
This PR was merged into the 3.x branch.

Discussion
----------

Update inky_to_html.rst: Updating link

Page: https://twig.symfony.com/doc/3.x/filters/inky_to_html.html

Commits
-------

b9a4e04731 Update inky_to_html.rst: Updating link
2025-10-20 11:04:47 +02:00
Thomas Landauer b9a4e04731 Update inky_to_html.rst: Updating link
Page: https://twig.symfony.com/doc/3.x/filters/inky_to_html.html
2025-10-19 19:03:40 +02:00
Vincent Langlet 790eee7ae0 Add throw tag to parse methods 2025-10-18 12:28:49 +02:00
Fabien Potencier f0cd0fdb9f minor #4695 Update replace.rst (cyphix333)
This PR was merged into the 3.x branch.

Discussion
----------

Update replace.rst

Missing `fruits` variable declaration.

Commits
-------

df3a281fc1 Update replace.rst
2025-10-07 07:46:05 +02:00
Brett df3a281fc1 Update replace.rst
Missing `fruits` variable declaration.
2025-10-07 07:09:13 +08:00
Fabien Potencier a895a3f00d minor #4694 [Doc] Tweaks in the escaping article (javiereguiluz)
This PR was merged into the 3.x branch.

Discussion
----------

[Doc] Tweaks in the escaping article

AS you can see in the redenred page (https://twig.symfony.com/doc/3.x/filters/escape.html) the tip about `html_attr` contains some uneeded line breaks.

This also tweaks another explanation to make it more clear.

Commits
-------

50327b5019 [Doc] Tweaks in the escaping article
2025-09-25 12:20:18 +02:00
Fabien Potencier dac599c320 bug #4693 Compile 'index' with repr (not string) in EmbedNode (smnandre)
This PR was merged into the 3.x branch.

Discussion
----------

Compile 'index' with repr (not string) in EmbedNode

Before this PR, the generated Template code had quotes around the index (integer) parameter value.

Commits
-------

e4d7915702 Compile 'index' with repr (not string) in EmbedNode
2025-09-25 12:17:47 +02:00
Javier Eguiluz 50327b5019 [Doc] Tweaks in the escaping article 2025-09-25 11:22:21 +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
Fabien Potencier 1d866283ed feature #4687 Introduce registerUndefinedTestCallback (VincentLanglet)
This PR was squashed before being merged into the 3.x branch.

Discussion
----------

Introduce registerUndefinedTestCallback

This is similar to `registerUndefinedFilterCallback` and `registerUndefinedFunctionCallback`

Commits
-------

cc12df995c Introduce registerUndefinedTestCallback
2025-09-16 07:40:30 +02:00
Vincent Langlet cc12df995c Introduce registerUndefinedTestCallback 2025-09-16 07:40:27 +02:00
Fabien Potencier fecc10cb14 minor #4692 Fix intl test (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Fix intl test

Let's try to make it less fragile.

Commits
-------

41bfb6bd8b Fix intl test
2025-09-15 08:07:21 +02:00
Fabien Potencier 41bfb6bd8b Fix intl test 2025-09-15 08:05:04 +02:00
Fabien Potencier d6a5a3e6d0 minor #4691 Bump minimum Commonmark requirement (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Bump minimum Commonmark requirement

All previous versions have security issues

Commits
-------

8f970764e6 Bump minimum Commonmark requirement
2025-09-15 08:00:04 +02:00
Fabien Potencier 8f970764e6 Bump minimum Commonmark requirement 2025-09-15 07:57:37 +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
Fabien Potencier 2a52ec2596 minor #4690 Improve documentation examples for enum and enum_cases (Kocal)
This PR was merged into the 3.x branch.

Discussion
----------

Improve documentation examples for `enum` and `enum_cases`

It may be obvious, but I first thought initializing an BackendEnum with a specific value could be possible with `enum(FQCN, value)`, but it does not, it always returns the first case  instance (if exists).

Instead, `enum(FQCN).from(value)` must be used, and I think it's worth to improve `enum()` examples.

Commits
-------

def4abbd5e Improve documentation examples for `enum` and `enum_cases`
2025-09-15 07:46:50 +02:00
Hugo Alliaume def4abbd5e Improve documentation examples for enum and enum_cases
It may be obvious, but I first thought initializing an BackendEnum with a certain value could be possible with `enum(FQCN, value)`, but it does not, it always returns the first case  instance (if exists).

Instead, `enum(FQCN).from(value)` must be used, I think it's worth to improve `enum()` examples.
2025-09-12 18:14:50 +02:00
Fabien Potencier 98b664a0ca bug #4688 Avoid errors when failing to guess the template info for an error (stof)
This PR was merged into the 3.x branch.

Discussion
----------

Avoid errors when failing to guess the template info for an error

Someone reported on the Symfony Slack a case where they get a TypeError in `new \ReflectionObject($template)` in the guessing logic instead of seeing the original error they have (the one for which guessing was attempted), making it impossible to know the original error: https://symfony-devs.slack.com/archives/C01FN4EQNLX/p1756762972076319?thread_ts=1756753204.711889&cid=C01FN4EQNLX
I don't have a reproducer for that case (the original case involve a Symfony form theme, where the form renderer does weird usages of Twig which might lead to the backtrace not containing the expected template).

Not guessing the template file path and the original template line is better than breaking the error reporting.

Commits
-------

62747cee27 Avoid errors when failing to guess the template info for an error
2025-09-02 14:53:38 +02:00