Repository navigation
refactor(templating): add SmartyRenderer wrapping SmartyPage - #1977
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
An active moderate issue remains because SmartyRenderer passes the current lookup instead of the renderer’s captured language, causing localization failures and violating the one-language contract.
1 open issue
What changed in this PR
Adds a Smarty-backed TemplateRenderer adapter around SmartyPage, preserving existing rendering behavior while providing a typed abstraction for future template engines.
Changes:
- Added
SmartyRendererdelegation for rendering, localization, controls, variables, directories, and validation. - Added focused tests covering renderer behavior and SmartyPage compatibility.
- Updated Smarty 5 PHPStan stubs, test-fake signatures, and analysis configuration.
| File | Description |
|---|---|
| tests/phpstan-stubs/Smarty.stub | Corrects the PHPStan signature for Smarty's createTemplate() method. |
| tests/Infrastructure/Common/SmartyRendererTest.php | Tests renderer delegation, variable assignment, control isolation, localization, directories, and validation. |
| tests/fakes/FakeSmarty.php | Aligns the fake Smarty method parameters with Smarty 5. |
| phpstan.neon | Registers the Smarty PHPStan stub for standard analysis. |
| phpstan_next.neon | Registers the Smarty PHPStan stub for stricter analysis. |
| lib/Common/Templating/SmartyRenderer.php | Implements the Smarty-backed TemplateRenderer adapter. |
| lib/Common/namespace.php | Loads SmartyRenderer alongside the legacy common classes. |
Review effort: Lite
Add the Smarty implementation of TemplateRenderer. It creates a SmartyPage and passes every call through to it, so rendering through the interface behaves like rendering with SmartyPage today, with one exception described below. smarty() returns the wrapped page for callers that still need Smarty-specific methods. Nothing uses the class yet. The exception is fetchLocalized(). The renderer records the language that is current when it is created and passes it to SmartyPage::FetchLocalized(). SmartyPage on its own takes the language from the CurrentLanguage variable. When that variable is not assigned, as for the invitation email, it does not find a "-custom" template of the language, and a later assignment could select another language. With the recorded language the customized template is used and the renderer keeps to one language, as the interface requires. The tests pin three behaviours that come from SmartyPage and that a second engine has to take into account: - variables passed to render() stay assigned afterwards - a control template is rendered with its own variables only and does not see the variables assigned to the renderer - fetchLocalized() finds a template that is in no language directory in the regular template directories Add a PHPStan stub for Smarty::createTemplate(). Smarty documents its $parent parameter as null although it accepts a Data object, which made PHPStan reject the named argument the wrapper passes. Give FakeSmarty::getTemplateVars() the parameters Smarty 5 uses. The test fake still had the names of an older Smarty version, so PHPStan reported the wrapper's named call as renamed in a subclass. Assisted-by: Claude:claude-opus-4-8
JohnVillalovos
force-pushed
the
jlvillal/twig
branch
from
November 19, 2026 01:55
19dfb83 to
edc8a8d
Compare
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain, with the SmartyRenderer delegation and its related behavior and compatibility changes covered by the supplied review evidence.
No open issues 🎉
1 resolved since last review
Review effort: Lite
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.

Add the Smarty implementation of TemplateRenderer. It creates a
SmartyPage and passes every call through to it, so rendering through
the interface behaves like rendering with SmartyPage today, with one
exception described below. smarty() returns the wrapped page for
callers that still need Smarty-specific methods.
Nothing uses the class yet.
The exception is fetchLocalized(). The renderer records the language
that is current when it is created and passes it to
SmartyPage::FetchLocalized(). SmartyPage on its own takes the
language from the CurrentLanguage variable. When that variable is
not assigned, as for the invitation email, it does not find a
"-custom" template of the language, and a later assignment could
select another language. With the recorded language the customized
template is used and the renderer keeps to one language, as the
interface requires.
The tests pin three behaviours that come from SmartyPage and that a
second engine has to take into account:
does not see the variables assigned to the renderer
in the regular template directories
Add a PHPStan stub for Smarty::createTemplate(). Smarty documents
its $parent parameter as null although it accepts a Data object,
which made PHPStan reject the named argument the wrapper passes.
Give FakeSmarty::getTemplateVars() the parameters Smarty 5 uses. The
test fake still had the names of an older Smarty version, so PHPStan
reported the wrapper's named call as renamed in a subclass.
Assisted-by: Claude:claude-opus-4-8