feat: support Twig 3 alongside Twig 2#49
Merged
Conversation
Widens the twig/twig dev requirement to "^2.11 || ^3.0" so Assetic's Twig integration is exercised against Twig 3, and resolves the incompatibilities and deprecations Twig 3 surfaces. All changes remain backward compatible with Twig 2.x. - AsseticTokenParser: Twig 3 lexes the opening "[" of a vars=[...] attribute list as an operator token rather than punctuation. Accept either classification so the tag parses on both major versions. - AsseticNode: mark the node #[YieldReady] (Twig 3.9 deprecated nodes that still compile to echo instead of yield; this node only assigns to the context and subcompiles its body, so it is yield-safe), and stop passing the node tag to the parent Node constructor on Twig >= 3.12, which deprecated that argument (the Parser now sets it automatically). The attribute is inert on Twig 2.x and on PHP 7.x, where it parses as a comment. - AsseticExtensionTest: the internal Environment::loadTemplate() signature changed in Twig 3; switch the test helper to the public load() method, which returns a renderable TemplateWrapper on both Twig 2.11+ and 3.x. Verified with the symfony/phpunit-bridge deprecation helper enabled: the full suite passes with no failures and no remaining first-party deprecations on PHP 8.3 against both twig/twig v3.27.1 and v2.16.1.
4bc9a09 to
98a76fa
Compare
LukeTowers
approved these changes
Jun 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Widens the
twig/twigdev requirement from^2.11to^2.11 || ^3.0so Assetic's Twig integration is exercised against Twig 3, and resolves the incompatibilities and deprecations Twig 3 surfaces. All changes are backward compatible with Twig 2.x, so existing consumers on Twig 2 are unaffected.This also removes the first-party reason CI saw deprecation noise on PHP 8.4/8.5: the
Implicitly marking parameter … nullablenotices came from the old Twig 2.x line, which is clean on Twig 3.Changes
composer.json—twig/twig: "^2.11 || ^3.0". Composer resolves the highest compatible version, so CI runs against Twig 3 on PHP 8.x while Twig 2 stays supported.src/Assetic/Extension/Twig/AsseticTokenParser.php— Twig 3 lexes the opening[of avars=[...]attribute list as an operator token rather than punctuation. The parser now accepts either, so{% javascripts … vars=["foo","bar"] %}parses on both majors. (,and]are punctuation in both and are unchanged.)src/Assetic/Extension/Twig/AsseticNode.php— two Twig 3 deprecations in first-party code:echoinstead ofyield.AsseticNodeonly assigns to the context and subcompiles its body (it never emitsecho), so it is yield-safe — marked with#[\Twig\Attribute\YieldReady]. The attribute is inert on Twig 2.x (never resolved) and on PHP 7.x (parses as a comment).Nodeconstructor (the Parser sets it automatically now). The tag is no longer forwarded on Twig ≥ 3.12, while Twig 2.x / < 3.12 still receive it.tests/Assetic/Test/Extension/Twig/AsseticExtensionTest.php— the internalEnvironment::loadTemplate()signature changed in Twig 3; the test helper now uses the publicload()method, which returns a renderableTemplateWrapperon both Twig 2.11+ and 3.x.Verification
Ran the full suite with the
symfony/phpunit-bridgedeprecation helper enabled (the default) — no failures, no errors, and no remaining first-party deprecations — against both Twig versions:(The earlier push failed CI because the bridge correctly flagged the two first-party Twig 3 deprecations above; both are now fixed at the source rather than suppressed.)
phpcs(PSR-12) is clean on the changed files.Notes
Independent of #48 (which adds 8.4/8.5 to the CI matrix and quiets the unfixable vendor deprecations); the two PRs touch disjoint files and can merge in any order. Dropping Twig 2 entirely (
^3.0only) was deliberately avoided to preserve backward compatibility, in keeping with Assetic's wide version support.