Repository navigation
Let templates call presenter methods passed with the render - #176
Merged
Merged
Conversation
A service can now pass a Presenter with View::render() and render_partial(). The template scope forwards a method call on $this to the presenter when an interface extending Presenter declares it. String and stringable results are escaped like context properties, SafeHtml passes through as markup, and other values come back unchanged. A call without a presenter, an undeclared method or a presenter method shadowed by the scope fails the view through the existing debug and production policy. The loop sample now reads its header through a PostHeader presenter. Closes #173
schlessera
force-pushed
the
feat/173-presenters
branch
from
October 24, 2026 00:04
8596b1f to
4993401
Compare
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.
Closes #173
What changed
A service can now pass a
PresenterwithView::render()andrender_partial(), and the template calls its methods on$this. Only methods declared on an interface that extendsPresenterare forwarded. String and stringable results are escaped like context properties,SafeHtmlpasses through as markup, and anything else comes back unchanged, so a boolean can drive anif. A partial inherits its parent's presenter unless given its own, and the presenter only holds for its own render. These calls fail the view through the existing debug/production policy: one with no presenter, one to an undeclared method, and any call on a presenter that declares a method the scope shadows (raw,render_partial, magic methods). The loop sample now reads its header through aPostHeaderpresenter (QueriedPostHeader, bound in the composition root and injected intoSampleLoopService), anddocs/patterns.mdhas a new "I need a template to ask for more than its context" section.Why this shape
Ruled on #145 (revised decision, 2026-10-24). The earlier ruling put one plugin-wide
ViewContextin the view factories. That object would grow with every subsystem, let every template call every method, make infrastructure views depend on the domain, and need #149's injector fix. Passing the presenter with the render keeps each template's contract to what its service gives it. No constructor, factory or injector changes.Proof
/** @var TemplateScope&PostHeader $this */in place, a misspelt$this->titel()inviews/test-loop-service.phpis reported by both PHPStan (method.notFound) and Psalm (UndefinedInterfaceMethod).finally.Checklist
composer testandcomposer lintpass locally, and CI is green on the current head.breakingand a ruling.Anything left open
Breaking for custom
Viewimplementations, which must accept the new optional$presenterparameters. #175 records that theViewinterface still requiresstdClass.