Commit Graph

101 Commits

Author SHA1 Message Date
Alexandre Daubois 819c6a89fe Fix sandbox bypass in the {% sandbox %} tag when including a preloaded template 2026-05-19 23:00:58 +02:00
Vincent Langlet 30977bdea9 Support two words test guard 2025-09-15 07:51:41 +02:00
Alexandre Daubois 9c6b95f2a6 Make in_array() calls strict 2025-02-19 15:29:33 +01:00
Fabien Potencier 4b57f48a65 Use generics in ExpressionParsers 2025-02-14 08:38:53 +01:00
Fabien Potencier f67078b5c4 Move Operators to ExpressionParsers, deprecate ExpressionParser 2025-02-14 08:38:53 +01:00
Fabien Potencier 42c82e1e9b Extract operators logic from ExpressionParser to their own classes 2025-02-14 08:38:53 +01:00
Ruud Kamphuis a84e602b4f Use correct lineno for ForElseNode
It should take the line number of the `{% else %}` block.
2025-02-07 14:48:08 +01:00
Fabien Potencier f594248a40 Fix CS 2025-01-26 11:54:00 +01:00
Fabien Potencier 609767522a Add ForElseNode 2025-01-24 15:25:30 +01:00
Fabien Potencier b6d9dd62ee Fix inheritance logic to be able to use instanceof ContextVariable instead of NameExpression 2025-01-24 13:47:29 +01:00
Fabien Potencier 72c91f6260 minor #4534 Add return type annotations on Twig 3 to prepare Twig 4 (smnandre)
This PR was squashed before being merged into the 3.x branch.

Discussion
----------

Add return type annotations on Twig 3 to prepare Twig 4

Started to add missing type annotation following `@stof` comment [here](https://github.com/twigphp/Twig/pull/4523#discussion_r1901915880).

Update:  I checked here every class (but one) in the `src` directory.

But you should ~~probably~~ **certainely** have another look.

Remains:
- src/ExpressionParser.php, where i'm not confident enough about the best return types (AbstractExpression|null works almost everytime, but lack some precision)
- extra directory
- tests directory

I'm happy to let them to someone else.... this was less fun than I expected 😅

Commits
-------

82be13429c Add return type annotations on Twig 3 to prepare Twig 4
2025-01-24 11:33:02 +01:00
Simon André 82be13429c Add return type annotations on Twig 3 to prepare Twig 4 2025-01-24 11:32:59 +01:00
Fabien Potencier dff6fdd675 Make {} optional for the types tag 2025-01-06 13:53:28 +01:00
Fabien Potencier b53c639f7d Ignore exceptions from undefined handlers when using the guard tag 2024-12-19 15:10:50 +01:00
Fabien Potencier c13ca48ca5 Use .html.twig in code example instead of .html 2024-12-18 11:13:19 +01:00
Fabien Potencier 44516133e2 Fix CS 2024-11-30 09:33:57 +01:00
Fabien Potencier 4f8ba93600 Enforce AbstractBinary for all binary operators 2024-11-29 16:51:09 +01:00
Fabien Potencier 89fdc7d31d Refactor code 2024-10-25 07:47:55 +02:00
Fabien Potencier 612c7a14be Improve ImportNode impl 2024-10-24 07:23:37 +02:00
Fabien Potencier 2735f81a22 feature #4398 Rename Node classes related to variables (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Rename Node classes related to variables

Whenever I work on Twig internals, it's always complicated to reason about variable names, probably because the class names are confusing. This PR is an attempt to find "better" and more explicit names.

This PR does the following renaming:

 * `NameExpression` to `Variable\ContextVariable`
    Represents the value of a context variable like `$context[VAR] ?? null`

 * `AssignNameExpression` to `Variable\AssignContextVariable`
    Represents a context variable assignment like in `$context[VAR] = `

 * `TempNameExpression` to `Variable\LocalVariable`
    Represents a "private" local variable like `$_l111`

Commits
-------

fc15e7ccbc Rename Node classes related to variables
2024-10-23 22:29:28 +02:00
Fabien Potencier f43eba5b10 minor #4403 Documentation for types tag uses Twig types in examples instead of PHP (drjayvee)
This PR was squashed before being merged into the 3.x branch.

Discussion
----------

Documentation for types tag uses Twig types in examples instead of PHP

Specifically, "bool" => "boolean" and "int" => "number".

This aligns the `types` documentation with templates.rst. See #4362

Thanks, `@alexander`-schranz!

Commits
-------

f3e0a00cf0 Documentation for types tag uses Twig types in examples instead of PHP
2024-10-23 16:54:05 +02:00
Jeroen Versteeg f3e0a00cf0 Documentation for types tag uses Twig types in examples instead of PHP 2024-10-23 16:54:04 +02:00
Fabien Potencier fc15e7ccbc Rename Node classes related to variables 2024-10-23 12:36:57 +02:00
Fabien Potencier 72693884c4 Simplify code 2024-10-21 07:20:17 +02:00
Fabien Potencier 1105964873 Rework macros handling 2024-10-20 21:53:20 +02:00
Fabien Potencier 66658a3c1d Check reserved names in TempNameExpression 2024-10-14 19:42:47 +02:00
Fabien Potencier 9af72e6323 Fix AssignNameExpression to forbid using names that won't work 2024-10-14 13:55:40 +02:00
Fabien Potencier 62f0a96b68 Introduce a way to test Twig callables at compile time 2024-10-08 18:41:34 +02:00
Fabien Potencier 8b278986b8 Deprecate using Node directly, introduce EmptyNode and Nodes 2024-09-27 07:42:41 +02:00
Fabien Potencier 9369a48c53 Deprecate the sandbox tag 2024-09-10 22:41:00 +02:00
Fabien Potencier 995e7c2270 Fix CS 2024-09-09 08:49:09 +02:00
Fabien Potencier 2ae0c0d38c Fix CS 2024-09-06 12:33:38 +02:00
Jeroen Versteeg 67dabd8182 Add types tag 2024-08-29 19:26:49 +02:00
Christian Flothmann 70396d75dc deprecate passing a tag to ImportNode 2024-08-28 14:40:27 +02:00
Fabien Potencier 5fca700cbd Deprecate the fact that the extends and use tags are always allowed in a sandboxed template 2024-08-28 13:40:53 +02:00
Fabien Potencier 9e6c4a6ac1 Deprecate some internal methods from Parser 2024-08-26 09:24:03 +02:00
Fabien Potencier cf4727606a Move code from ExtendsTokenParser to Parser 2024-08-26 07:56:37 +02:00
Simon André c662e0ce27 Remove remaining const optimizations
After #4198 some `Token::` const optimization remains.

This PR remove them.. **in case** it was not intended
2024-08-15 19:11:55 +02:00
Fabien Potencier cd0ac3cc0a Remove const optimization 2024-08-12 09:40:52 +02:00
Fabien Potencier 0ce79df5c4 Use trigger_deprecation() instead of trigger_error() for deprecations 2024-08-08 14:28:28 +02:00
Fabien Potencier b63bde3063 Optimize sprintf() calls for PHP 8.4 2024-06-21 08:16:55 +02:00
Fabien Potencier 2b2ac80d34 Fxi some errors reported by phpstan 2024-02-05 17:48:36 +01:00
Fabien Potencier af8ec178b6 Remove list() usage in code 2024-01-05 12:46:24 +01:00
Fabien Potencier 5193653ecb Fix CS 2023-10-08 09:05:22 +02:00
Den 17c6371fb5 Some code style fixes 2021-05-14 10:26:05 +02:00
Fabien Potencier b95735da2e Mark built-in token parsers as @internal 2020-11-30 12:04:32 +01:00
Fabien Potencier 0fdf96c389 Merge branch '2.x' into 3.x
* 2.x:
  Add a test
  Fix typo
  Fix compatibility with PHPUnit 10
  Update doc for macro with embed tags
  fix typo in ApplyTokenParser PHP doc
  Fixes #3351
2020-08-05 16:54:08 +02:00
Fabien Potencier 38bd74d03a Merge branch '1.x' into 2.x
* 1.x:
  Add a test
  fix typo in ApplyTokenParser PHP doc
  Fixes #3351
2020-08-05 16:53:59 +02:00
Chris Jung 47b5028f46 fix typo in ApplyTokenParser PHP doc
Typo
2020-07-21 13:11:49 +02:00
Steve Nebes a343589583 Updated spaceless deprecation to point to apply tag, as the filter tag is now deprecated too 2019-11-28 15:04:01 +01:00