Repository navigation
Resolve route controllers through the application container - #20
Merged
Merged
Conversation
Route::make() had its own reflection-based injector that ignored the container, so controller constructors did not follow container bindings: - A container singleton injected into a controller's constructor was a different instance from the same singleton injected into its action. - Interfaces bound in the container failed with `Class "..." does not exist`. - Services built by container closures, and scalar parameters that have defaults, failed with "must be a class type". - A static process-wide cache shared unbound services between unrelated controllers. It cached only classes that have a constructor. Route::make() keeps its signature and now delegates to app()->make(). Each dispatch builds the controller fresh. Bind it with app()->singleton() to share one instance. The protected Route::$instances, cache(), is_cached() and get_cached() are removed. Adds regression tests for each case, a "Controller constructor injection" section in docs/routing-examples.md, a 3.3.2 changelog entry, and the OpenSpec change route-controller-container-resolution. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Moves the route-controller-container-resolution change into openspec/changes/archive/2026-11-12-route-controller-container-resolution/ and adds its requirements as the new main spec in openspec/specs/route-controller-resolution/spec.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Problem
Route::make()had its own reflection-based injector that ignored the application container, so controller constructors did not follow container bindings:Class "..." does not exist.array) failed with "must be a class type".int $limit = 10) failed in the same way.Route::$instances) shared unbound services between unrelated controllers. It cached only classes that have a constructor.Change
Route::make()keeps its signature and now delegates toapp()->make(). Controllers and their dependencies follow the same bindings, singletons and defaults as everything else the container resolves.app()->singleton(SomeController::class)to share one instance.Route::$instances,cache(),is_cached()andget_cached()are removed. The cache gained little in WordPress, where each request is a new PHP process, and it caused the instance mismatch above.Compatibility
Routethat used the removed protected cache members. Nothing in the public API changes.singleton()when one shared instance is needed.Tests
tests/Unit/RouteDiTest.phpgains one regression test for each case above:Each test failed before the change. The circular-dependency test is unchanged and still passes.
composer test:unit: 953 tests, 2252 assertions, all passing.composer phpcs: 0 errors. It shows only the 3 line-length warnings already present inTemplateEngine.phpandValidationRule.php.Docs
docs/routing-examples.md.CHANGELOG.mdentry under 3.3.2 / Fixed.route-controller-container-resolution.🤖 Generated with Claude Code