Commit Graph

6191 Commits

Author SHA1 Message Date
Fabien Potencier c8d6df7eb2 Remove usage of isset before array_key_exists as performance is not an issue anymore 2023-12-09 17:24:12 +01:00
Fabien Potencier a2eb71ce66 minor #3935 Simplify generated code by using named arguments (fabpot)
This PR was squashed before being merged into the 4.x branch.

Discussion
----------

Simplify generated code by using named arguments

Commits
-------

bce22e4c Use named arguments
a64561b4 Simplify code
2023-12-09 17:22:30 +01:00
Fabien Potencier bce22e4c32 Use named arguments 2023-12-09 17:18:55 +01:00
Fabien Potencier a64561b420 Simplify code 2023-12-09 17:18:14 +01:00
Fabien Potencier aa4b59c0ed minor #3934 Use PHP 8 features (fabpot)
This PR was squashed before being merged into the 4.x branch.

Discussion
----------

Use PHP 8 features

Commits
-------

be67e969 Use str_* when possible
0668be9e Use arrow function
06d9fc6a Use is_countable()
89d37cd5 Use get_debug_type()
308aa5ba Remove usage of list()
a42eba63 Use match instead of switch
fed8dd10 Use ::class
2023-12-09 17:14:40 +01:00
Fabien Potencier be67e9690f Use str_* when possible 2023-12-09 15:33:38 +01:00
Fabien Potencier 0668be9e76 Use arrow function 2023-12-09 15:33:38 +01:00
Fabien Potencier 06d9fc6ad0 Use is_countable() 2023-12-09 15:33:38 +01:00
Fabien Potencier 89d37cd510 Use get_debug_type() 2023-12-09 15:33:38 +01:00
Fabien Potencier 308aa5ba45 Remove usage of list() 2023-12-09 15:33:38 +01:00
Fabien Potencier a42eba63c5 Use match instead of switch 2023-12-09 15:33:38 +01:00
Fabien Potencier fed8dd102b Use ::class 2023-12-09 15:33:38 +01:00
Fabien Potencier 67c8798074 minor #3933 Remove obsolete code (fabpot)
This PR was squashed before being merged into the 4.x branch.

Discussion
----------

Remove obsolete code

Commits
-------

b9cf29d5 Remove obsolete code
583d7b2d Remove hack to inline throwing an exception
3d5ad9ac Remove obsolete code
3472ae12 Simplify code
2023-12-09 14:58:14 +01:00
Fabien Potencier b9cf29d53d Remove obsolete code 2023-12-09 14:56:21 +01:00
Fabien Potencier 583d7b2d2c Remove hack to inline throwing an exception 2023-12-09 14:52:04 +01:00
Fabien Potencier 3d5ad9ac51 Remove obsolete code 2023-12-09 14:50:25 +01:00
Fabien Potencier 3472ae1241 Simplify code 2023-12-09 14:50:13 +01:00
Fabien Potencier 15dadf9a67 feature #3932 [4.x] Bump to PHP 8.2 (fabpot)
This PR was squashed before being merged into the 4.x branch.

Discussion
----------

[4.x] Bump to PHP 8.2

Commits
-------

bcfe41ef Remove obsolete docs
5dc2ba92 Remove tests on non-supported PHP versions
f930a284 Bump to 4.0 and require PHP 8.2
2023-12-09 14:46:56 +01:00
Fabien Potencier bcfe41efff Remove obsolete docs 2023-12-09 13:46:54 +01:00
Fabien Potencier 5dc2ba921f Remove tests on non-supported PHP versions 2023-12-09 13:46:26 +01:00
Fabien Potencier f930a284fe Bump to 4.0 and require PHP 8.2 2023-12-09 13:45:50 +01:00
Fabien Potencier f83b415386 Merge branch '2.x' into 3.x
* 2.x:
  update Blackfire documentation URL
  Prepare the 2.15.6 release
  Update CHANGELOG
2023-12-09 12:45:27 +01:00
Fabien Potencier ec57248c14 minor #3929 update Blackfire documentation URL (Ca-Jou)
This PR was submitted for the 3.x branch but it was merged into the 2.x branch instead.

Discussion
----------

update Blackfire documentation URL

Update Blackfire documentation's URL in README file

Commits
-------

ed2cfbd6 update Blackfire documentation URL
2023-12-09 12:44:06 +01:00
Ca-Jou ed2cfbd6f0 update Blackfire documentation URL 2023-12-09 12:44:01 +01:00
Fabien Potencier aeeec9a5e9 Bump version 2023-11-21 19:55:42 +01:00
Fabien Potencier 9d15f0ac07 Prepare the 3.8.0 release v3.8.0 2023-11-21 19:54:41 +01:00
Fabien Potencier b65ccdfb7d Update CHANGELOG 2023-11-21 19:53:58 +01:00
Fabien Potencier ad637405a8 Prepare the 2.15.6 release v2.15.6 2023-11-21 18:34:48 +01:00
Fabien Potencier a41a0e7fa5 Update CHANGELOG 2023-11-21 18:34:15 +01:00
Fabien Potencier 78e1cdd84c bug #3903 Fix timezone fallback to CoreExtension in IntlExtension (keulinho)
This PR was merged into the 3.x branch.

Discussion
----------

Fix timezone fallback to CoreExtension in IntlExtension

This is probably a regression from #3844

Refer to my comment on the original MR: https://github.com/twigphp/Twig/pull/3844#issuecomment-1792464040

Commits
-------

144c4dac Fix timezone fallback to CoreExtension in IntlExtension
2023-11-21 18:27:48 +01:00
Fabien Potencier 2f73ee35ca minor #3900 Minor rename of Sandbox test: functions->methods (YSaxon)
This PR was merged into the 3.x branch.

Discussion
----------

Minor rename of Sandbox test: functions->methods

Commits
-------

62732646 Minor rename of SandboxTest functions->methods
2023-11-21 17:18:42 +01:00
Fabien Potencier ff98249d0b minor #3911 Add PHP 8.3 to the CI (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Add PHP 8.3 to the CI

Commits
-------

a04cc88a Add PHP 8.3 to the CI
2023-11-21 16:50:45 +01:00
Fabien Potencier a04cc88ad7 Add PHP 8.3 to the CI 2023-11-21 16:47:02 +01:00
Fabien Potencier e6ba716520 minor #3908 Bump dependencies (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Bump dependencies

Commits
-------

fdb9d9ed Bump dependencies
2023-11-21 16:45:18 +01:00
Fabien Potencier fdb9d9eddf Bump dependencies 2023-11-21 15:02:01 +01:00
Fabien Potencier 6f74d5b7d6 minor #3909 Fix tests and CS (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Fix tests and CS

Commits
-------

4be326ae Fix tests and CS
2023-11-21 15:01:23 +01:00
Fabien Potencier 4be326aeeb Fix tests and CS 2023-11-21 14:57:52 +01:00
Jonas Elfering 144c4dac7f Fix timezone fallback to CoreExtension in IntlExtension
This is probably a regression from #3844
2023-11-03 15:14:20 +01:00
Yaakov Saxon 62732646c8 Minor rename of SandboxTest functions->methods 2023-10-27 12:15:56 -04:00
Fabien Potencier 9f42a76306 minor #3835 Removed duplicate sentence in macro scoping (virtualize)
This PR was merged into the 3.x branch.

Discussion
----------

Removed duplicate sentence in macro scoping

Commits
-------

73f5cad8 Remove duplicate sentence in macro scoping
2023-10-26 17:56:31 -07:00
Fabien Potencier b285fccd59 bug #3830 Catch errors thrown during template rendering (richards-square)
This PR was squashed before being merged into the 3.x branch.

Discussion
----------

Catch errors thrown during template rendering

Some errors, like not providing a function the proper number of arguments or division by zero, extend from `\Error` rather than `\Exception`. This PR catches these types of errors during template rendering and throws a `RuntimeError` in order to provide better debugging information.

Commits
-------

85bf01b4 Catch errors thrown during template rendering
2023-10-26 17:55:51 -07:00
Drew Richards 85bf01b4ab Catch errors thrown during template rendering 2023-10-26 17:55:48 -07:00
Fabien Potencier 9a602c7532 feature #3695 Add @codeCoverageIgnore to untestable compiled methods (markhuot)
This PR was merged into the 3.x branch.

Discussion
----------

Add `@codeCoverageIgnore` to untestable compiled methods

I've been experimenting with adding my compiled templates to my code coverage reports and it works largely as expected. Templates that get executed return percentages accurate to the number of lines the tests actually cover. The only exception are the "meta" methods on the compiled template that aren't necessarily called by the tests.

This PR adds ``@codeCoverageIgnore`` comments to the compiled template for all non-display methods so the coverage report only lists lines from `doDisplay`.

I'm assuming that I will need to update some of the Twig tests to account for these new comments, but am curious if you'd be open to this change.

An example screenshot below. The last line shows line 46 out of the compiled template is never executed. The compiled template's `getDebugInfo` even correctly informs me that line 46 maps to line 4 in my `.twig` so I'll work on updating the line numbering next.

![image](https://user-images.githubusercontent.com/48975/166098890-fbaf99ad-9aa4-4430-9f82-050f482a6777.png)

Commits
-------

1cf610bd Add `@codeCoverageIgnore` to untestable compiled methods
2023-10-26 17:52:38 -07:00
Fabien Potencier 065634f498 bug #3844 Fix IntlExtension::formatDateTime use of date formatter prototype (drjayvee)
This PR was squashed before being merged into the 3.x branch.

Discussion
----------

Fix IntlExtension::formatDateTime use of date formatter prototype

See https://github.com/twigphp/intl-extra/pull/6 for more details

Commits
-------

c75762c3 Fix IntlExtension::formatDateTime use of date formatter prototype
2023-10-26 17:47:32 -07:00
Jeroen Versteeg c75762c354 Fix IntlExtension::formatDateTime use of date formatter prototype 2023-10-26 17:47:31 -07:00
Fabien Potencier 248855b34b Merge branch '2.x' into 3.x
* 2.x:
  Fix premature loop exit in Security Policy lookup of allowed methods/properties
2023-10-26 17:38:13 -07:00
Fabien Potencier 02262dee80 bug #3873 Fix premature loop exit in Security Policy lookup of allowed methods/properties (YSaxon)
This PR was squashed before being merged into the 2.x branch.

Discussion
----------

Fix premature loop exit in Security Policy lookup of allowed methods/properties

The current security policy logic exits too soon when checking permissions for allowed classes and their methods/properties, causing false negatives in situations involving classes related by inheritance.

Consider the following configuration:

```
'methods' => [
  'App\BasicCollection' => ['sortAlphabetically'],
  'App\AdvancedCollection'=> ['sortByTimestamp'],
],
```
where `AdvancedCollection` is a subclass of `BasicCollection`, and `mylist` is an instance of `AdvancedCollection`

If you try to call `{{ mylist.sortByTimestamp() }}`, the current code will first match `mylist` against `App\BasicCollection`. Since `sortByTimestamp` is not an allowed method for `App\BasicCollection`, the code will exit the loop and incorrectly deny access. It will never get to checking `App\AdvancedCollection`.

Note that reordering classes in the config can't solve this issue. If you flipped the order, then it would fail for `{{ mylist.sortAlphabetically() }}` instead.

This pull request fixes the issue by only exiting the loop early when both the class and method/property match.

Commits
-------

5e1838db Fix premature loop exit in Security Policy lookup of allowed methods/properties
2023-10-26 17:37:16 -07:00
Yaakov Saxon 5e1838dbca Fix premature loop exit in Security Policy lookup of allowed methods/properties 2023-10-26 17:37:13 -07:00
Fabien Potencier 415f4cc3ee minor #3896 Compile Elvis operator into Elvis operator ?: (GromNaN)
This PR was merged into the 3.x branch.

Discussion
----------

Compile Elvis operator into Elvis operator `?:`

When using ternary operator without "then" part, the "condition" part is evaluated twice, which is inconsistent with how PHP works.
The Twig template `A ?: B` is currently compiled as `A ? A : B` in PHP. This PR change it to `A ?: B`.

If `A` is a complex expression, it improves performance to only execute the expression once.
If `A` is has a side effect (like updating a variable), the expression being executed twice could result in a bug. ([example in PHP](https://3v4l.org/LWZLR))

Example with ``@WebProfiler`/Collector/form.html.twig` [line 9](https://github.com/symfony/symfony/blob/e6d1ed4edb5ae197ec7d25ddaf64cfa456229504/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/form.html.twig#L9) (see deep [diff](https://www.diffchecker.com/jOm3dE13/))

```twig
{{ collector.data.nb_errors ?: collector.data.forms|length }}
```

Previous compilation:
```php
echo twig_escape_filter($this->env, (((isset($context["error_count"]) || array_key_exists("error_count", $context) ? $context["error_count"] : (function () { throw new RuntimeError('Variable "error_count" does not exist.', 9, $this->source); })())) ? ((isset($context["error_count"]) || array_key_exists("error_count", $context) ? $context["error_count"] : (function () { throw new RuntimeError('Variable "error_count" does not exist.', 9, $this->source); })())) : (twig_get_attribute($this->env, $this->source, (isset($context["collector"]) || array_key_exists("collector", $context) ? $context["collector"] : (function () { throw new RuntimeError('Variable "collector" does not exist.', 9, $this->source); })()), "countDefines", [], "any", false, false, false, 9))), "html", null, true);
```

After this change:
```php
echo twig_escape_filter($this->env, ((isset($context["error_count"]) || array_key_exists("error_count", $context) ? $context["error_count"] : (function () { throw new RuntimeError('Variable "error_count" does not exist.', 9, $this->source); })()) ?: twig_get_attribute($this->env, $this->source, (isset($context["collector"]) || array_key_exists("collector", $context) ? $context["collector"] : (function () { throw new RuntimeError('Variable "collector" does not exist.', 9, $this->source); })()), "countDefines", [], "any", false, false, false, 9)), "html", null, true);
```

Commits
-------

fb0d7495 Compile Elvis operator with Elvis operator
2023-10-22 14:57:13 +02:00
Fabien Potencier 758018b79b minor #3897 Compile starts/ends with using str_starts_with and str_ends_with (GromNaN)
This PR was merged into the 3.x branch.

Discussion
----------

Compile `starts/ends with` using `str_starts_with` and `str_ends_with`

Since we now require PHP 8.0 polyfill #3884, we can use `str_starts_with` and `str_ends_with` to compile `starts with` and `ends with` expressions.

Example with `bootstrap_4_layout.html.twig` [line 6-7](https://github.com/symfony/symfony/blob/e6d1ed4edb5ae197ec7d25ddaf64cfa456229504/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig#L6-L7) (see deep [diff](https://www.diffchecker.com/18CtPeja/)):

```twig
    {%- set prepend = not (money_pattern starts with '{{') -%}
    {%- set append = not (money_pattern ends with '}}') -%}
```

Previous compilation:
```php
// line 6
$context["prepend"] =  !(is_string($__internal_compile_0 = (isset($context["money_pattern"]) || array_key_exists("money_pattern", $context) ? $context["money_pattern"] : (function () { throw new RuntimeError('Variable "money_pattern" does not exist.', 6, $this->source); })())) && is_string($__internal_compile_1 = "{{") && ('' === $__internal_compile_1 || 0 === strpos($__internal_compile_0, $__internal_compile_1)));
// line 7
$context["append"] =  !(is_string($__internal_compile_2 = (isset($context["money_pattern"]) || array_key_exists("money_pattern", $context) ? $context["money_pattern"] : (function () { throw new RuntimeError('Variable "money_pattern" does not exist.', 7, $this->source); })())) && is_string($__internal_compile_3 = "}}") && ('' === $__internal_compile_3 || $__internal_compile_3 === substr($__internal_compile_2, -strlen($__internal_compile_3))));
```

With this change:
```php
// line 6
$context["prepend"] =  !(is_string($__internal_compile_0 = (isset($context["money_pattern"]) || array_key_exists("money_pattern", $context) ? $context["money_pattern"] : (function () { throw new RuntimeError('Variable "money_pattern" does not exist.', 6, $this->source); })())) && is_string($__internal_compile_1 = "{{") && str_starts_with($__internal_compile_0, $__internal_compile_1));
// line 7
$context["append"] =  !(is_string($__internal_compile_2 = (isset($context["money_pattern"]) || array_key_exists("money_pattern", $context) ? $context["money_pattern"] : (function () { throw new RuntimeError('Variable "money_pattern" does not exist.', 7, $this->source); })())) && is_string($__internal_compile_3 = "}}") && str_ends_with($__internal_compile_2, $__internal_compile_3));
```

Commits
-------

30b5a566 Compile starts/ends with using PHP8 functions str_starts/ends_with
2023-10-22 14:56:22 +02:00