refactor(view): align ViewInterface bindings with Marko's simple-binding preference#90
Merged
Merged
Conversation
…nding
ViewInterface binding was a closure that built the view manually. The
closure existed because the engine needs LatteEngineFactory::create()
(method call, not autowire). But the closure was at the wrong level —
LatteView and TwigView have fully-autowirable constructors.
Per Marko's binding guidance ("Prefer simple bindings. Only use closures
when autowiring can't express what you need"), the closure should sit on
the dependency that genuinely needs the method call (Latte\Engine /
Twig\Environment), not bubble up to the parent.
After this change:
- ViewInterface => LatteView::class (simple binding, autowired)
- Latte\Engine::class => closure calling LatteEngineFactory::create()
- ViewInterface => TwigView::class (simple binding, autowired)
- Twig\Environment::class => closure calling TwigEngineFactory::create()
Module tests updated to verify the new binding shape.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This was referenced May 27, 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
The
view-latteandview-twigmodule.phpfiles wrappedViewInterfacein a closure that manually builtLatteView/TwigView. The closure existed for a real reason — the engine (Latte\Engine/Twig\Environment) needsLatteEngineFactory::create()(a method call, not direct autowiring). But the closure was at the wrong level:LatteViewandTwigViewboth have fully-autowirable constructors (only type-hinted interfaces/classes).Per Marko's binding guidance in
architecture.md:The closure should sit on the dependency that genuinely needs the factory method, not bubble up to the parent.
Before
After
ViewInterfacebinding becomes a simple class mapping (autowired)Latte\Engine(orTwig\Environmentfor view-twig) — the actual service that needs custom build logicLatteView's autowired constructor receives the engine (from closure) and resolver (autowired); thesetLoader()side effect still runs in the constructorSame restructure applied to both
view-latte/module.phpandview-twig/module.phpto keep them symmetric.Why this matters
Future copy-paste from view's
module.phppropagates the correct pattern. View is one of the most-likely-to-be-cargo-culted module configurations in the framework, so getting its shape right matters beyond just these two packages.Test plan
packages/view-latte/tests/— 29 tests pass (ModuleTest updated to verify new shape)packages/view-twig/tests/— 48 tests pass (ModuleTest updated)packages/view/tests/— 43 tests pass (no changes here, regression check)🤖 Generated with Claude Code