diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 909e97dd62b..350fb93921c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,7 +4,7 @@ on: pull_request: push: branches: - - '3.x' + - '4.x' env: SYMFONY_PHPUNIT_DISABLE_RESULT_CACHE: 1 @@ -23,11 +23,6 @@ jobs: strategy: matrix: php-version: - - '7.2.5' - - '7.3' - - '7.4' - - '8.0' - - '8.1' - '8.2' - '8.3' experimental: [false] @@ -70,11 +65,6 @@ jobs: strategy: matrix: php-version: - - '7.2.5' - - '7.3' - - '7.4' - - '8.0' - - '8.1' - '8.2' - '8.3' extension: diff --git a/CHANGELOG b/CHANGELOG index 14ba7576b17..929180044b0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,200 +1,3 @@ -# 3.8.1 (2023-XX-XX) +# 4.0.0 (2024-XX-XX) - * Add return type for Symfony 7 compatibility - * Fix premature loop exit in Security Policy lookup of allowed methods/properties - -# 3.8.0 (2023-11-21) - - * Catch errors thrown during template rendering - * Fix IntlExtension::formatDateTime use of date formatter prototype - * Fix premature loop exit in Security Policy lookup of allowed methods/properties - * Remove NumberFormatter::TYPE_CURRENCY (deprecated in PHP 8.3) - * Restore return type annotations - * Allow Symfony 7 packages to be installed - * Deprecate `twig_test_iterable` function. Use the native `is_iterable` instead. - -# 3.7.1 (2023-08-28) - - * Fix some phpdocs - -# 3.7.0 (2023-07-26) - - * Add support for the ...spread operator on arrays and hashes - -# 3.6.1 (2023-06-08) - - * Suppress some native return type deprecation messages - -# 3.6.0 (2023-05-03) - - * Allow psr/container 2.0 - * Add the new PHP 8.0 IntlDateFormatter::RELATIVE_* constants for date formatting - * Make the Lexer initialize itself lazily - -# 3.5.1 (2023-02-08) - - * Arrow functions passed to the "reduce" filter now accept the current key as a third argument - * Restores the leniency of the matches twig comparison - * Fix error messages in sandboxed mode for "has some" and "has every" - -# 3.5.0 (2022-12-27) - - * Make Twig\ExpressionParser non-internal - * Add "has some" and "has every" operators - * Add Compile::reset() - * Throw a better runtime error when the "matches" regexp is not valid - * Add "twig *_names" intl functions - * Fix optimizing closures callbacks - * Add a better exception when getting an undefined constant via `constant` - * Fix `if` nodes when outside of a block and with an empty body - -# 3.4.3 (2022-09-28) - - * Fix a security issue on filesystem loader (possibility to load a template outside a configured directory) - -# 3.4.2 (2022-08-12) - - * Allow inherited magic method to still run with calling class - * Fix CallExpression::reflectCallable() throwing TypeError - * Fix typo in naming (currency_code) - -# 3.4.1 (2022-05-17) - -* Fix optimizing non-public named closures - -# 3.4.0 (2022-05-22) - - * Add support for named closures - -# 3.3.10 (2022-04-06) - - * Enable bytecode invalidation when auto_reload is enabled - -# 3.3.9 (2022-03-25) - - * Fix custom escapers when using multiple Twig environments - * Add support for "constant('class', object)" - * Do not reuse internally generated variable names during parsing - -# 3.3.8 (2022-02-04) - - * Fix a security issue when in a sandbox: the `sort` filter must require a Closure for the `arrow` parameter - * Fix deprecation notice on `round` - * Fix call to deprecated `convertToHtml` method - -# 3.3.7 (2022-01-03) - -* Allow more null support when Twig expects a string (for better 8.1 support) -* Only use Commonmark extensions if markdown enabled - -# 3.3.6 (2022-01-03) - -* Only use Commonmark extensions if markdown enabled - -# 3.3.5 (2022-01-03) - -* Allow CommonMark extensions to easily be added -* Allow null when Twig expects a string (for better 8.1 support) -* Make some performance optimizations -* Allow Symfony translation contract v3+ - -# 3.3.4 (2021-11-25) - - * Bump minimum supported Symfony component versions - * Fix a deprecated message - -# 3.3.3 (2021-09-17) - - * Allow Symfony 6 - * Improve compatibility with PHP 8.1 - * Explicitly specify the encoding for mb_ord in JS escaper - -# 3.3.2 (2021-05-16) - - * Revert "Throw a proper exception when a template name is an absolute path (as it has never been supported)" - -# 3.3.1 (2021-05-12) - - * Fix PHP 8.1 compatibility - * Throw a proper exception when a template name is an absolute path (as it has never been supported) - -# 3.3.0 (2021-02-08) - - * Fix macro calls in a "cache" tag - * Add the slug filter - * Allow extra bundle to be compatible with Twig 2 - -# 3.2.1 (2021-01-05) - - * Fix extra bundle compat with older versions of Symfony - -# 3.2.0 (2021-01-05) - - * Add the Cache extension in the "extra" repositories: "cache" tag - * Add "registerUndefinedTokenParserCallback" - * Mark built-in node visitors as @internal - * Fix "odd" not working for negative numbers - -# 3.1.1 (2020-10-27) - - * Fix "include(template_from_string())" - -# 3.1.0 (2020-10-21) - - * Fix sandbox support when using "include(template_from_string())" - * Make round brackets optional for one argument tests like "same as" or "divisible by" - * Add support for ES2015 style object initialisation shortcut { a } is the same as { 'a': a } - -# 3.0.5 (2020-08-05) - - * Fix twig_compare w.r.t. whitespace trimming - * Fix sandbox not disabled if syntax error occurs within {% sandbox %} tag - * Fix a regression when not using a space before an operator - * Restrict callables to closures in filters - * Allow trailing commas in argument lists (in calls as well as definitions) - -# 3.0.4 (2020-07-05) - - * Fix comparison operators - * Fix options not taken into account when using "Michelf\MarkdownExtra" - * Fix "Twig\Extra\Intl\IntlExtension::getCountryName()" to accept "null" as a first argument - * Throw exception in case non-Traversable data is passed to "filter" - * Fix context optimization on PHP 7.4 - * Fix PHP 8 compatibility - * Fix ambiguous syntax parsing - -# 3.0.3 (2020-02-11) - - * Add a check to ensure that iconv() is defined - -# 3.0.2 (2020-02-11) - - * Avoid exceptions when an intl resource is not found - * Fix implementation of case-insensitivity for method names - -# 3.0.1 (2019-12-28) - - * fixed Symfony 5.0 support for the HTML extra extension - -# 3.0.0 (2019-11-15) - - * fixed number formatter in Intl extra extension when using a formatter prototype - -# 3.0.0-BETA1 (2019-11-11) - - * removed the "if" condition support on the "for" tag - * made the in, <, >, <=, >=, ==, and != operators more strict when comparing strings and integers/floats - * removed the "filter" tag - * added type hints everywhere - * changed Environment::resolveTemplate() to always return a TemplateWrapper instance - * removed Template::__toString() - * removed Parser::isReservedMacroName() - * removed SanboxedPrintNode - * removed Node::setTemplateName() - * made classes maked as "@final" final - * removed InitRuntimeInterface, ExistsLoaderInterface, and SourceContextLoaderInterface - * removed the "spaceless" tag - * removed Twig\Environment::getBaseTemplateClass() and Twig\Environment::setBaseTemplateClass() - * removed the "base_template_class" option on Twig\Environment - * bumped minimum PHP version to 7.2 - * removed PSR-0 classes + * Drop support for PHP < 8.2 diff --git a/composer.json b/composer.json index 1b1726fe882..ddec2e46249 100644 --- a/composer.json +++ b/composer.json @@ -24,8 +24,7 @@ } ], "require": { - "php": ">=7.2.5", - "symfony/polyfill-php80": "^1.22", + "php": ">=8.2", "symfony/polyfill-mbstring": "^1.3", "symfony/polyfill-ctype": "^1.8" }, diff --git a/doc/deprecated.rst b/doc/deprecated.rst index b624b569628..1b60f012986 100644 --- a/doc/deprecated.rst +++ b/doc/deprecated.rst @@ -1,9 +1,6 @@ Deprecated Features =================== -This document lists deprecated features in Twig 3.x. Deprecated features are +This document lists deprecated features in Twig 4.x. Deprecated features are kept for backward compatibility and removed in the next major release (a -feature that was deprecated in Twig 3.x is removed in Twig 4.0). - -The `twig_test_iterable` function is deprecated; use the native `is_iterable` -instead. +feature that was deprecated in Twig 4.x is removed in Twig 5.0). diff --git a/doc/filters/format_datetime.rst b/doc/filters/format_datetime.rst index 8f3b46d479a..3ca9f0be672 100644 --- a/doc/filters/format_datetime.rst +++ b/doc/filters/format_datetime.rst @@ -24,13 +24,9 @@ You can tweak the output for the date part and the time part: {# mercredi 7 août 2019 23:39:12 UTC #} {{ '2019-08-07 23:39:12'|format_datetime('full', 'full', locale='fr') }} -Supported values are: ``none``, ``short``, ``medium``, ``long``, and ``full``. - -.. versionadded:: 3.6 - - ``relative_short``, ``relative_medium``, ``relative_long``, and ``relative_full`` are also supported when running on - PHP 8.0 and superior or when using a polyfill that define the ``IntlDateFormatter::RELATIVE_*`` constants and - associated behavior. +Supported values are: ``none``, ``short``, ``medium``, ``long``, ``full``, +``relative_short``, ``relative_medium``, ``relative_long``, and +``relative_full``. For greater flexibility, you can even define your own pattern (see the `ICU user guide`_ for supported patterns). diff --git a/doc/functions/country_names.rst b/doc/functions/country_names.rst index 692137b0431..6064f946aee 100644 --- a/doc/functions/country_names.rst +++ b/doc/functions/country_names.rst @@ -1,10 +1,6 @@ ``country_names`` ================= -.. versionadded:: 3.5 - - The ``country_names`` function was added in Twig 3.5. - The ``country_names`` function returns the names of the countries: .. code-block:: twig diff --git a/doc/functions/currency_names.rst b/doc/functions/currency_names.rst index dfb446c8650..63c83bde3d3 100644 --- a/doc/functions/currency_names.rst +++ b/doc/functions/currency_names.rst @@ -1,10 +1,6 @@ ``currency_names`` ================== -.. versionadded:: 3.5 - - The ``currency_names`` function was added in Twig 3.5. - The ``currency_names`` function returns the names of the currencies: .. code-block:: twig diff --git a/doc/functions/language_names.rst b/doc/functions/language_names.rst index f1cce488a73..be3f8f703ac 100644 --- a/doc/functions/language_names.rst +++ b/doc/functions/language_names.rst @@ -1,10 +1,6 @@ ``language_names`` ================== -.. versionadded:: 3.5 - - The ``language_names`` function was added in Twig 3.5. - The ``language_names`` function returns the names of the languages: .. code-block:: twig diff --git a/doc/functions/locale_names.rst b/doc/functions/locale_names.rst index 320ab672470..af18bc946f3 100644 --- a/doc/functions/locale_names.rst +++ b/doc/functions/locale_names.rst @@ -1,10 +1,6 @@ ``locale_names`` ================ -.. versionadded:: 3.5 - - The ``locale_names`` function was added in Twig 3.5. - The ``locale_names`` function returns the names of the locales: .. code-block:: twig diff --git a/doc/functions/script_names.rst b/doc/functions/script_names.rst index 79b20c65fe2..49b1282b421 100644 --- a/doc/functions/script_names.rst +++ b/doc/functions/script_names.rst @@ -1,10 +1,6 @@ ``script_names`` ================ -.. versionadded:: 3.5 - - The ``script_names`` function was added in Twig 3.5. - The ``script_names`` function returns the names of the scripts: .. code-block:: twig diff --git a/doc/functions/timezone_names.rst b/doc/functions/timezone_names.rst index 69db196fddd..053176942e6 100644 --- a/doc/functions/timezone_names.rst +++ b/doc/functions/timezone_names.rst @@ -1,10 +1,6 @@ ``timezone_names`` ================== -.. versionadded:: 3.5 - - The ``timezone_names`` function was added in Twig 3.5. - The ``timezone_names`` function returns the names of the timezones: .. code-block:: twig diff --git a/doc/installation.rst b/doc/installation.rst index 5fd56507abe..3dd8a2198d5 100644 --- a/doc/installation.rst +++ b/doc/installation.rst @@ -5,6 +5,6 @@ Install `Composer`_ and run the following command to get the latest version: .. code-block:: bash - composer require "twig/twig:^3.0" + composer require "twig/twig:^4.0" .. _`Composer`: https://getcomposer.org/download/ diff --git a/doc/intro.rst b/doc/intro.rst index 8914507e4f0..f35a44e20f1 100644 --- a/doc/intro.rst +++ b/doc/intro.rst @@ -30,7 +30,7 @@ Slim, Yii, Laravel, and Codeigniter — just to name a few. Prerequisites ------------- -Twig 3.x needs at least **PHP 7.2.5** to run. +Twig 4.x needs at least **PHP 8.2.0** to run. Installation ------------ @@ -39,7 +39,7 @@ The recommended way to install Twig is via Composer: .. code-block:: bash - composer require "twig/twig:^3.0" + composer require "twig/twig:^4.0" Basic API Usage --------------- diff --git a/doc/recipes.rst b/doc/recipes.rst index 8c1caa8058a..889ae70b551 100644 --- a/doc/recipes.rst +++ b/doc/recipes.rst @@ -266,11 +266,6 @@ is accessible via the ``loop.parent.loop.index`` variable. Defining undefined Functions, Filters, and Tags on the Fly ---------------------------------------------------------- -.. versionadded:: 3.2 - - The ``registerUndefinedTokenParserCallback()`` method was added in Twig - 3.2. - When a function/filter/tag is not defined, Twig defaults to throw a ``\Twig\Error\SyntaxError`` exception. However, it can also call a `callback`_ (any valid PHP callable) which should return a function/filter/tag. diff --git a/doc/tags/cache.rst b/doc/tags/cache.rst index b1d032bc461..9989877a2fb 100644 --- a/doc/tags/cache.rst +++ b/doc/tags/cache.rst @@ -1,10 +1,6 @@ ``cache`` ========= -.. versionadded:: 3.2 - - The ``cache`` tag was added in Twig 3.2. - The ``cache`` tag tells Twig to cache a template fragment: .. code-block:: twig diff --git a/extra/cache-extra/composer.json b/extra/cache-extra/composer.json index 04177a419de..bb0b62c2f57 100644 --- a/extra/cache-extra/composer.json +++ b/extra/cache-extra/composer.json @@ -15,7 +15,7 @@ } ], "require": { - "php": ">=7.2.5", + "php": ">=8.2", "symfony/cache": "^5.0|^6.0|^7.0", "twig/twig": "^3.0" }, diff --git a/extra/cssinliner-extra/composer.json b/extra/cssinliner-extra/composer.json index 32be7b44de4..29e2a47a9e5 100644 --- a/extra/cssinliner-extra/composer.json +++ b/extra/cssinliner-extra/composer.json @@ -15,7 +15,7 @@ } ], "require": { - "php": ">=7.2.5", + "php": ">=8.2", "tijsverkoyen/css-to-inline-styles": "^2.0", "twig/twig": "^3.0" }, diff --git a/extra/html-extra/composer.json b/extra/html-extra/composer.json index e67e53e5a82..0794d99b741 100644 --- a/extra/html-extra/composer.json +++ b/extra/html-extra/composer.json @@ -15,7 +15,7 @@ } ], "require": { - "php": ">=7.2.5", + "php": ">=8.2", "symfony/mime": "^5.4|^6.0|^7.0", "twig/twig": "^3.0" }, diff --git a/extra/inky-extra/composer.json b/extra/inky-extra/composer.json index 2cb5a5ad308..3559d4ed714 100644 --- a/extra/inky-extra/composer.json +++ b/extra/inky-extra/composer.json @@ -15,7 +15,7 @@ } ], "require": { - "php": ">=7.2.5", + "php": ">=8.2", "lorenzo/pinky": "^1.0.5", "twig/twig": "^3.0" }, diff --git a/extra/intl-extra/composer.json b/extra/intl-extra/composer.json index 208347077a2..6dfca0d1159 100644 --- a/extra/intl-extra/composer.json +++ b/extra/intl-extra/composer.json @@ -15,7 +15,7 @@ } ], "require": { - "php": ">=7.2.5", + "php": ">=8.2", "twig/twig": "^3.0", "symfony/intl": "^5.4|^6.0|^7.0" }, diff --git a/extra/markdown-extra/composer.json b/extra/markdown-extra/composer.json index 52dc07d9ec2..7ac5d067632 100644 --- a/extra/markdown-extra/composer.json +++ b/extra/markdown-extra/composer.json @@ -15,7 +15,7 @@ } ], "require": { - "php": ">=7.2.5", + "php": ">=8.2", "twig/twig": "^3.0" }, "require-dev": { diff --git a/extra/string-extra/composer.json b/extra/string-extra/composer.json index 77050a11785..783f01fdf5d 100644 --- a/extra/string-extra/composer.json +++ b/extra/string-extra/composer.json @@ -15,7 +15,7 @@ } ], "require": { - "php": ">=7.2.5", + "php": ">=8.2", "symfony/string": "^5.4|^6.0|^7.0", "symfony/translation-contracts": "^1.1|^2|^3", "twig/twig": "^3.0" diff --git a/extra/twig-extra-bundle/composer.json b/extra/twig-extra-bundle/composer.json index cbdbd4b8ab0..f8d20357695 100644 --- a/extra/twig-extra-bundle/composer.json +++ b/extra/twig-extra-bundle/composer.json @@ -15,7 +15,7 @@ } ], "require": { - "php": ">=7.2.5", + "php": ">=8.2", "symfony/framework-bundle": "^5.4|^6.0|^7.0", "symfony/twig-bundle": "^5.4|^6.0|^7.0", "twig/twig": "^3.0" diff --git a/src/Environment.php b/src/Environment.php index 5329b143ee2..f55d110583d 100644 --- a/src/Environment.php +++ b/src/Environment.php @@ -40,11 +40,11 @@ */ class Environment { - public const VERSION = '3.8.1-DEV'; - public const VERSION_ID = 30801; - public const MAJOR_VERSION = 3; - public const MINOR_VERSION = 8; - public const RELEASE_VERSION = 1; + public const VERSION = '4.0.0-DEV'; + public const VERSION_ID = 40000; + public const MAJOR_VERSION = 4; + public const MINOR_VERSION = 0; + public const RELEASE_VERSION = 0; public const EXTRA_VERSION = 'DEV'; private $charset; diff --git a/tests/Fixtures/regression/simple_xml_element.test b/tests/Fixtures/regression/simple_xml_element.test deleted file mode 100644 index ae633c8817f..00000000000 --- a/tests/Fixtures/regression/simple_xml_element.test +++ /dev/null @@ -1,19 +0,0 @@ ---TEST-- -Twig is able to deal with SimpleXMLElement instances as variables ---CONDITION-- -version_compare(phpversion(), '8.0', '<') ---TEMPLATE-- -Hello '{{ images.image.0.group }}'! -{{ images.image.0.group.attributes.myattr }} -{{ images.children().image.count() }} -{% for image in images %} - - {{ image.group }} -{% endfor %} ---DATA-- -return ['images' => new \SimpleXMLElement('foobar')] ---EXPECT-- -Hello 'foo'! -example -2 - - foo - - bar