Commit Graph

243 Commits

Author SHA1 Message Date
Fabien Potencier c1933323ba Simplify implementation 2024-07-28 10:08:38 +02:00
Fabien Potencier e95d6b2f21 Add support for recursive loops 2024-07-28 10:08:35 +02:00
Fabien Potencier 8b47fc319a Use first class callable syntax 2024-07-14 14:01:33 +02:00
Fabien Potencier 17ef0bef4b Introduce a Loop object 2024-07-11 08:03:08 +02:00
Fabien Potencier 9acc085110 Merge branch '3.x' into 4.x
* 3.x:
  fix condition for running use_yield test with extra packages
  fix the set of installed packages for TwigExtraBundle on PHP 8.0
  simplify an iterable check
  Fixed typo
  Tweak code, tests, and docs for shuffle
  Add shuffle filter
2024-07-06 10:46:01 +02:00
Christian Flothmann 8602b7f3dc simplify an iterable check 2024-07-05 23:09:31 +02:00
Fabien Potencier 2dacaadd98 Tweak code, tests, and docs for shuffle 2024-07-05 09:39:44 +02:00
sarah-eit 17430ae5ac Add shuffle filter 2024-07-05 09:20:37 +02:00
Fabien Potencier 3734ba6a17 Merge branch '3.x' into 4.x
* 3.x:
  Remove usage of uniqid
  Document OPTIMIZE_TEXT_NODES
  Issue #3828: Add sequence and mapping tests
2024-07-01 18:45:00 +02:00
Pierre c5c95a2d5c Issue #3828: Add sequence and mapping tests 2024-06-22 19:48:59 +02:00
Fabien Potencier 3236429dc8 Merge branch '3.x' into 4.x
* 3.x:
  Fix typo
  Tweak
  Rename array to sequence
  Rename hash to mapping
2024-06-22 19:42:47 +02:00
Fabien Potencier c44be99a84 Rename array to sequence 2024-06-22 19:37:51 +02:00
Fabien Potencier c250afdda0 Optimize sprintf() calls for PHP 8.4 2024-06-21 08:27:51 +02:00
Fabien Potencier b63bde3063 Optimize sprintf() calls for PHP 8.4 2024-06-21 08:16:55 +02:00
Fabien Potencier 58b17d795f Merge branch '3.x' into 4.x
* 3.x:
  Fix BC break on escaper extension
  Fix constant return type
2024-05-11 23:08:49 +02:00
Fabien Potencier f6ce88df2f Fix constant return type 2024-05-11 20:51:17 +02:00
Fabien Potencier f582a3e381 Fix CS 2024-05-01 16:41:44 +02:00
Fabien Potencier 51bcd21df0 Merge branch '3.x' into 4.x
* 3.x:
  Fix CS
2024-05-01 16:07:15 +02:00
Fabien Potencier b222be9974 Fix CS 2024-05-01 16:06:53 +02:00
Fabien Potencier d425c11b56 Merge branch '3.x' into 4.x
* 3.x:
  Make some CoreExtension methods part of the public API
2024-05-01 14:12:10 +02:00
Fabien Potencier 0a275945af Make some CoreExtension methods part of the public API 2024-05-01 14:11:02 +02:00
Fabien Potencier 3d99ed8bdb Merge branch '3.x' into 4.x
* 3.x:
  Move some static extension methods to non-static
  Add needs_charset option for filters and functions
  Fix method call
  Rename some internal methods
2024-05-01 13:58:23 +02:00
Fabien Potencier 283475b102 Move some static extension methods to non-static 2024-05-01 13:48:35 +02:00
Fabien Potencier c63f695e8a Add needs_charset option for filters and functions 2024-05-01 13:12:48 +02:00
Fabien Potencier 16acdf69fe Rename some internal methods 2024-05-01 10:19:22 +02:00
Fabien Potencier 5fdb1ee11a Merge branch '3.x' into 4.x
* 3.x:
  Fix a @return type hint
  Fix CS
  Fix a test
  Fix type
  Simplify sandbox code
  Get rid of weird code
  [html-extra] filter classes
  Fix some inconsistencies
2024-04-30 15:46:54 +02:00
Fabien Potencier 82f8864e7b Fix a @return type hint 2024-04-30 15:38:55 +02:00
Fabien Potencier fa714ce6bd Fix CS 2024-04-30 15:30:51 +02:00
Fabien Potencier c2fc437f6a Fix a test 2024-04-30 15:23:35 +02:00
Fabien Potencier 9a11ee1c64 Merge branch '3.x' into 4.x
* 3.x:
  Bump version to 3.9.4-DEV
  Fix a warning
  Use ::class everywhere
  Auto-close PRs on subtree-splits
  Bump version
  Prepare the 3.9.3 release
  Update CHANGELOG
  Ensure Lexer:: is always initialized
  fix: #4033 add missing unwrap call when a TemplateWrapper instance can be present
  change extended DI extension class
  fix: #4029 when use_yield is true CaptureNode use iterator_to_array preserveKeys argument to false
2024-04-24 08:25:00 +02:00
Fabien Potencier a71ae1923e Use ::class everywhere 2024-04-19 10:26:00 -04:00
Fabien Potencier 3b5044ab32 Merge branch '3.x' into 4.x
* 3.x:
  Fix exception when timezone is false
  Fix param name in docblock (minor)
  Minor fixes
2024-04-03 17:09:03 +02:00
Simon André 2d262bc35f Fix param name in docblock (minor) 2024-04-03 13:36:36 +02:00
Nicolas Grekas e70777405d Add #[YieldReady] to allow extensions to tell when they're ready for yielding 2024-02-15 10:27:26 +01:00
Fabien Potencier ae7e6cc9a3 Merge branch '3.x' into 4.x
* 3.x:
  Fix CS
  Remove redundant "$thing instanceof \Countable" check
  Update PHPUnit schema
  fix TwigExtraBundle tests with Symfony 6.0/6.1
2024-02-10 10:03:27 +01:00
Fabien Potencier 7f5958c5e3 minor #3996 Remove redundant "instanceof \Countable" check (minor) (smnandre)
This PR was merged into the 3.x branch.

Discussion
----------

Remove redundant "instanceof \Countable" check (minor)

In [CoreExtension::lengthFilter](https://github.com/twigphp/Twig/compare/3.x...smnandre:fix/remove-check-countable?expand=1#diff-29e85e483c6ec4a9c2fd144820b6722c86df60d54175b355d85e806253313c1a), the check L1183 is redundant as "`$thing instanceof \Countable`" is already checked L1175.

```diff
    if ($thing instanceof \Countable || \is_array($thing) || $thing instanceof \SimpleXMLElement) {
        return \count($thing);
    }

    if ($thing instanceof \Traversable) {
        return iterator_count($thing);
    }

-    if (method_exists($thing, '__toString') && !$thing instanceof \Countable) {
+    if (method_exists($thing, '__toString')) {
        return mb_strlen((string) $thing, $env->getCharset());
    }
```

Commits
-------

2836af3d Remove redundant "$thing instanceof \Countable" check
2024-02-10 10:00:39 +01:00
Fabien Potencier f7f11ea410 Fix CS 2024-02-10 09:52:03 +01:00
Simon André 2836af3d3f Remove redundant "$thing instanceof \Countable" check
The check L1183 is redundant as "$thing instanceof \Countable" is already checked L1175.

```php
        if ($thing instanceof \Countable || \is_array($thing) || $thing instanceof \SimpleXMLElement) {
            return \count($thing);
        }

        if ($thing instanceof \Traversable) {
            return iterator_count($thing);
        }

        if (method_exists($thing, '__toString') && !$thing instanceof \Countable) {
            return mb_strlen((string) $thing, $env->getCharset());
        }
```
2024-02-10 02:32:40 +01:00
Fabien Potencier f9871531b7 Merge branch '3.x' into 4.x
* 3.x:
  Fxi some errors reported by phpstan
2024-02-05 19:00:15 +01:00
Fabien Potencier 2b2ac80d34 Fxi some errors reported by phpstan 2024-02-05 17:48:36 +01:00
Fabien Potencier d234a60efa Merge branch '3.x' into 4.x
* 3.x:
  Bump actions/cache for CI
  Remove an obsolete comment
  Throws proper Twig exception when using cycle on an empty array
  Add tests when a template doesn't have output nodes
  Optimize TextNodes
  Remove list() usage in code
  Remove usage of list() in favor of []
2024-01-22 18:50:54 +01:00
Fabien Potencier d21666f728 Throws proper Twig exception when using cycle on an empty array 2024-01-11 21:47:04 +01:00
Fabien Potencier fa91edfcc6 Merge branch '3.x' into 4.x
* 3.x:
  Fix intl tests
  Improve error message
  Bump version
  Update CHANGELOG
2023-12-24 09:45:46 +01:00
Malte Wunsch 3963851a41 Improve error message
It is not obvious that you cannot use the Twig function `constant` to get the special `::class` constants of classes like so: `{{ constant('Twig\\Extension\\CoreExtension::class') }}`, due to the underlying PHP function `\constant()`.

The previous error message in this case: 'Constant "Twig\Extension\CoreExtension::class" is undefined.' was not very helpful.
2023-12-22 08:51:25 +01:00
Fabien Potencier 35640b6d2d Add type hints to private properties 2023-12-14 20:43:37 +01:00
Fabien Potencier ffa55e8cae minor #3942 Use DateTimeImmutable (fabpot)
This PR was merged into the 4.x branch.

Discussion
----------

Use DateTimeImmutable

Commits
-------

b3e8b8ac Use DateTimeImmutable
2023-12-13 12:55:07 +01:00
Fabien Potencier b3e8b8ac39 Use DateTimeImmutable 2023-12-12 22:53:10 +01:00
Fabien Potencier 1493fdfb19 Remove deprecated method 2023-12-11 13:46:08 +01:00
Fabien Potencier ac423430aa Merge branch '3.x' into 4.x
* 3.x:
  Fix CS
  Move functions for CoreExtension
  Move functions for EscaperExtension
  Move functions for StringLoaderExtension
  Move functions for DebugExtension
  Move functions for MarkdownExtension
  Move functions for InkyExtension
  Move functions for CssInlinerExtension
  Move functions for HtmlExtension
  Deprecate internal extension functions in favor of methods on the extension classes
  Tweak deprecated docs
2023-12-10 20:55:15 +01:00
Fabien Potencier aa7c454e2d Fix CS 2023-12-10 20:34:32 +01:00