Commit Graph

7108 Commits

Author SHA1 Message Date
Fabien Potencier f4a596e5b0 Make Node abstract 2024-09-27 08:03:01 +02:00
Fabien Potencier 3b15ba5a4c Fix usages of Node() 2024-09-27 08:01:33 +02:00
Fabien Potencier 0c6bd47d6b Merge branch '3.x' into 4.x
* 3.x:
  Deprecate using Node directly, introduce EmptyNode and Nodes
  Add support for inline comments
  Update plural.rst: Fixing(?) broken links
  Fix CS
  Add support for accessing class constants with the dot operator
  Fix getting a property on an object casted to an array
  Replace strtr() by strtolower()
  Improve escape deprecation message
  Remove useless assign in compiled code
  Add fixture filename as key
  Be more precise about double-escaping
  Fix template name in error for an unknown dynamic extends called from an include
2024-09-27 07:59:52 +02:00
Fabien Potencier faf8471d47 feature #4335 Deprecate instantiating Node directly, introduce EmptyNode and Nodes (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Deprecate instantiating Node directly, introduce EmptyNode and Nodes

Based on some comments from `@stof`:

See https://github.com/twigphp/Twig/pull/4292#discussion_r1751651242
See https://github.com/twigphp/Twig/pull/4333#discussion_r1773531733

First interesting usage here: 65ee72a71f60c3680c2aceef7b9932cee7f84e89

Commits
-------

8b278986b8 Deprecate using Node directly, introduce EmptyNode and Nodes
2024-09-27 07:43:50 +02:00
Fabien Potencier 8b278986b8 Deprecate using Node directly, introduce EmptyNode and Nodes 2024-09-27 07:42:41 +02:00
Fabien Potencier a1daf1e551 minor #4357 Update plural.rst: Fixing(?) broken links (ThomasLandauer)
This PR was merged into the 3.x branch.

Discussion
----------

Update plural.rst: Fixing(?) broken links

More important question: Is the filter's name `plural` or `pluralize`??

Commits
-------

cc3a2b7bac Update plural.rst: Fixing(?) broken links
2024-09-27 07:34:31 +02:00
Fabien Potencier 1e4ceff2a8 feature #4349 Add support for inline comments (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Add support for inline comments

Closes #4001

Commits
-------

d9d8bb0df3 Add support for inline comments
2024-09-27 07:32:40 +02:00
Fabien Potencier d9d8bb0df3 Add support for inline comments 2024-09-27 07:32:09 +02:00
Fabien Potencier 61766f4d9a minor #4356 Add generics for LoopIterator (ruudk)
This PR was merged into the 4.x branch.

Discussion
----------

 Add generics for LoopIterator

/cc `@stof`

Commits
-------

a4dc388c62  Add generics for LoopIterator
2024-09-27 07:26:01 +02:00
Thomas Landauer cc3a2b7bac Update plural.rst: Fixing(?) broken links
More important question: Is the filter's name `plural` or `pluralize`??
2024-09-27 01:23:50 +02:00
Fabien Potencier a23cd9feeb Fix CS 2024-09-26 21:22:23 +02:00
Fabien Potencier f4b17ce8fa bug #4336 Fix template name in error for an unknown dynamic extends called from an include (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Fix template name in error for an unknown dynamic extends called from an include

Closes #3265

The code was introduced in #1529, but removing it nowadays does not break any existing test.

Review ignoring whitespace.

Commits
-------

4824f2a4a3 Fix template name in error for an unknown dynamic extends called from an include
2024-09-26 20:59:11 +02:00
Fabien Potencier b843e780bc minor #4355 Simplify compiled for loop code (ruudk)
This PR was squashed before being merged into the 4.x branch.

Discussion
----------

Simplify compiled `for` loop code

**Do not pass closure as reference**
It's not needed.

**Do not use same var names in loop function**
These variables are passed in when the loop function is invoked when yielding.
Giving them the same internal var names complicates things for no good reason.

Commits
-------

a096c202e3 Do not use same var names in loop function
fcb16a0f86 Do not pass closure as reference
2024-09-26 20:43:38 +02:00
Fabien Potencier 57147e7513 feature #4353 Add support for accessing class constants with the dot operator (nicolas-grekas)
This PR was merged into the 3.x branch.

Discussion
----------

Add support for accessing class constants with the dot operator

This PR allows accessing class constants from objects: `{{ foo.SOME_CONSTANT }}`. This should nicely replace the `constant()` function when an object is at hand, and is actually needed to make the `enum` function work in #4352.

Commits
-------

1ea0452323 Add support for accessing class constants with the dot operator
2024-09-26 20:37:32 +02:00
Fabien Potencier 5038a30c72 bug #4351 Fix getting a property on an object casted to an array (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Fix getting a property on an object casted to an array

Closes #3371

Commits
-------

7d5269e100 Fix getting a property on an object casted to an array
2024-09-26 20:35:25 +02:00
Fabien Potencier 63a04d8ab7 minor #4350 Replace strtr() by strtolower() (nicolas-grekas)
This PR was merged into the 3.x branch.

Discussion
----------

Replace strtr() by strtolower()

The performance of `strtolower()` has been fixed in PHP 8.

Commits
-------

04471ab8cd Replace strtr() by strtolower()
2024-09-26 20:34:22 +02:00
Ruud Kamphuis a4dc388c62 Add generics for LoopIterator
This makes it possible for PHPStan to understand what happens when iterating.
2024-09-26 20:21:01 +02:00
Ruud Kamphuis a096c202e3 Do not use same var names in loop function
These variables are passed in when the loop function is invoked when yielding.
Giving them the same internal var names complicates things for no good reason.
2024-09-26 19:36:47 +02:00
Ruud Kamphuis fcb16a0f86 Do not pass closure as reference
It's not needed.
2024-09-26 19:23:18 +02:00
Nicolas Grekas 1ea0452323 Add support for accessing class constants with the dot operator 2024-09-26 18:06:21 +02:00
Fabien Potencier 7d5269e100 Fix getting a property on an object casted to an array 2024-09-26 17:55:00 +02:00
Nicolas Grekas 04471ab8cd Replace strtr() by strtolower() 2024-09-26 17:48:39 +02:00
Fabien Potencier 355a80c5df minor #4347 Remove useless Closure::bind in for loop (ruudk)
This PR was merged into the 4.x branch.

Discussion
----------

Remove useless Closure::bind in for loop

This has no effect. The returned value is not used.

https://www.php.net/manual/en/closure.bind.php

Commits
-------

c48aa4649f Remove useless Closure::bind in for loop
2024-09-26 16:12:10 +02:00
Fabien Potencier 0123d22968 minor #4348 Replace return; yield with yield from [] (ruudk)
This PR was merged into the 4.x branch.

Discussion
----------

Replace `return; yield` with yield from `[]`

See #4259

Commits
-------

317c69d0ff Replace `return; yield` with yield from `[]`
2024-09-26 16:11:17 +02:00
Ruud Kamphuis 317c69d0ff Replace return; yield with yield from []
See #4259
2024-09-26 16:07:09 +02:00
Ruud Kamphuis c48aa4649f Remove useless Closure::bind in for loop 2024-09-26 16:04:42 +02:00
Fabien Potencier d008fa408e minor #4345 Add fixture filename as key (ruudk)
This PR was merged into the 3.x branch.

Discussion
----------

Add fixture filename as key

This way, it's easier to see which test failed and what the file was.

In PHPStorm this is visualized very nice.
![Screenshot 2024-09-26 at 14 19 49@2x](https://github.com/user-attachments/assets/1fe87364-c014-4cff-9b90-b9db0368efc8)

Commits
-------

633d70103d Add fixture filename as key
2024-09-26 15:11:48 +02:00
Fabien Potencier fea6cc344e minor #4346 Remove useless assign in compiled code (ruudk)
This PR was merged into the 3.x branch.

Discussion
----------

Remove useless assign in compiled code

It's already unset / initialized on catch.

Having it this way, is a bit easier for me when analyzing this in TwigStan.

Commits
-------

5c73c6695c Remove useless assign in compiled code
2024-09-26 15:10:13 +02:00
Fabien Potencier d1c754ecdf minor #4344 Improve escape deprecation message (ruudk)
This PR was squashed before being merged into the 3.x branch.

Discussion
----------

Improve escape deprecation message

This was introduced in https://github.com/twigphp/Twig/pull/4176

According to #4343 the message can be improved.

I made a few changes to the test to make it easier to work with. Best to review this PR **commit by commit**.

/cc `@stof`

Commits
-------

7256713c86 Improve escape deprecation message
2024-09-26 15:09:44 +02:00
Ruud Kamphuis 7256713c86 Improve escape deprecation message 2024-09-26 15:09:41 +02:00
Ruud Kamphuis 5c73c6695c Remove useless assign in compiled code 2024-09-26 14:36:01 +02:00
Ruud Kamphuis 633d70103d Add fixture filename as key
This way, it's easier to see which test failed and what the file was.

In PHPStorm this is visualized very nice.
2024-09-26 14:19:35 +02:00
Fabien Potencier 4607cce80f minor #4342 Be more precise about double-escaping (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Be more precise about double-escaping

Closes #3918

Commits
-------

fe3d615aa4 Be more precise about double-escaping
2024-09-26 12:52:31 +02:00
Fabien Potencier 4dd20ba005 Merge branch '3.x' into 4.x
* 3.x:
  Add start/end time accessors on Profile
  Fix 'ignore missing' when used on an 'embed' tag
  Fix the possibility to override an aliased block (via use)
  Add test
  Add hot cache reload for templates
  Add RemovableCacheInterface
  Add some tests
  Optimize compiled code for "set" tag
  Improve how trim behaves
  Add more tests
  Add return types in FileystemLoader
  Add compile-time checks for the "matches" operator
2024-09-26 09:28:03 +02:00
Fabien Potencier fe3d615aa4 Be more precise about double-escaping 2024-09-26 08:58:21 +02:00
Fabien Potencier be308bc5ac feature #4341 Add start/end time accessors on Profile (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Add start/end time accessors on Profile

Closes #3418

Commits
-------

f83c844b7d Add start/end time accessors on Profile
2024-09-26 08:23:09 +02:00
Fabien Potencier f83c844b7d Add start/end time accessors on Profile 2024-09-26 08:19:38 +02:00
Fabien Potencier bb30a7ba26 bug #4340 Fix 'ignore missing' when used on an 'embed' tag (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Fix 'ignore missing' when used on an 'embed' tag

Closes #3085

Commits
-------

09790a7542 Fix 'ignore missing' when used on an 'embed' tag
2024-09-26 07:56:31 +02:00
Fabien Potencier 09790a7542 Fix 'ignore missing' when used on an 'embed' tag 2024-09-26 07:55:44 +02:00
Fabien Potencier 588a5c5676 bug #4339 Fix the possibility to override an aliased block (via use) (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Fix the possibility to override an aliased block (via use)

Closes #3709

Commits
-------

955611d5bb Fix the possibility to override an aliased block (via use)
2024-09-25 22:17:13 +02:00
Fabien Potencier c203b27db2 feature #4334 Improve how trim behaves (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Improve how trim behaves

Closes #3651

Commits
-------

10c3142d3b Improve how trim behaves
2024-09-25 22:10:15 +02:00
Fabien Potencier 955611d5bb Fix the possibility to override an aliased block (via use) 2024-09-25 22:08:16 +02:00
Fabien Potencier 3ddab4f8b4 feature #4338 Add template cache hot reload (fabpot)
This PR was squashed before being merged into the 3.x branch.

Discussion
----------

Add template cache hot reload

Closes #3880

This PR achieves 2 things in the minimum amount of code (in 2 commits):

* It adds a new `RemovableCacheInterface` that allows cache to be removed.
* It adds a memory cache to allow updating existing templates in the same process (think FrakenPHP for instance) without polluting the permanent cache.

Commits
-------

00ba8046b0 Add test
dca5099aad Add hot cache reload for templates
786a67b1a9 Add RemovableCacheInterface
2024-09-25 18:40:47 +02:00
Fabien Potencier 00ba8046b0 Add test 2024-09-25 17:28:51 +02:00
Fabien Potencier dca5099aad Add hot cache reload for templates 2024-09-25 17:28:51 +02:00
Fabien Potencier 786a67b1a9 Add RemovableCacheInterface 2024-09-25 17:28:51 +02:00
Fabien Potencier 04f21b2650 minor #4337 Add some tests (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Add some tests

Closes #3691

The bug described in #3691 has been fixed via #3999.

This PR adds tests to prove it works now and to avoid future regressions.

Commits
-------

85c2ba5147 Add some tests
2024-09-25 10:43:15 +02:00
Fabien Potencier 85c2ba5147 Add some tests 2024-09-24 22:13:47 +02:00
Fabien Potencier 4824f2a4a3 Fix template name in error for an unknown dynamic extends called from an include 2024-09-24 20:55:19 +02:00
Fabien Potencier efc527ea65 minor #4333 Optimize compiled code for "set" tag (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Optimize compiled code for "set" tag

Commits
-------

9855e35d44 Optimize compiled code for "set" tag
2024-09-24 17:04:08 +02:00