Skip to content

refactor(templating): add SmartyRenderer wrapping SmartyPage - #1977

Merged
JohnVillalovos merged 1 commit into
mainfrom
jlvillal/twig
Nov 19, 2026
Merged

JohnVillalovos merged 1 commit into
mainfrom
jlvillal/twig

Conversation

@JohnVillalovos

@JohnVillalovos JohnVillalovos commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 SmartyRenderer delegation 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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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

@JohnVillalovos
JohnVillalovos merged commit 867a6d7 into main Nov 19, 2026
15 checks passed
@JohnVillalovos
JohnVillalovos deleted the jlvillal/twig branch November 19, 2026 02:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants