Skip to content

Avoid loading internal classes from PSR-11 container - #319

Merged
clue merged 1 commit into
clue:mainfrom
clue-labs:container-psr-internals
Oct 29, 2026
Merged

clue merged 1 commit into
clue:mainfrom
clue-labs:container-psr-internals

Conversation

@clue

@clue clue commented Oct 29, 2026

Copy link
Copy Markdown
Owner

This changeset updates the Container to avoid loading its internal classes from a custom PSR-11 container. Previously, autowiring containers such as PHP-DI would report every instantiable class as available, so X would ask them for its own Container, RouteHandler and HttpServerRunner. With PHP-DI, new App(new Container(new DI\Container())) would throw in CLI because it can not create the HttpServerRunner, and the router would load controllers and middleware from a fresh Container instead of the given one. X now creates these itself by default, while your controllers, middleware and configuration are still loaded from the given container:

$container = new DI\Container();

$app = new FrameworkX\App(new FrameworkX\Container($container));

These regressions from #292 and #291 have not been released yet, v0.17.0 is not affected. If you want to configure the HTTP server runner, such as for a larger request body limit via #311, you can still define it in your custom container and load it by setting X_EXPERIMENTAL_RUNNER to its class name.

The built-in container works exactly as before. This includes new test cases covering the PSR-11 adapter, so this has 100% code coverage and should be safe to apply.

Builds on top of #292, #291, #290, #295, #311, #289, #294, #163 and others

@clue clue added the new feature New feature or request label Oct 29, 2026
@clue clue added this to the v0.18.0 milestone Oct 29, 2026
@clue
clue requested a balanced review from Copilot October 29, 2026 12:12

Copilot AI left a comment

Copy link
Copy Markdown

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 were identified for the change isolating framework internals from custom PSR-11 autowiring.

No open issues 🎉

What changed in this PR

Prevents custom PSR-11 autowiring containers from incorrectly creating Framework X internals, while preserving delegation for application classes and configuration.

Changes:

  • Creates the container self-reference, router, and default CLI HTTP runner without consulting the PSR-11 adapter for those classes.
  • Preserves explicit custom runner selection through X_EXPERIMENTAL_RUNNER.
  • Adds regression tests and documents the adapter behavior.
File Description
tests/​ContainerTest.php Tests internal-class isolation and explicit runner selection.
tests/​AppTest.php Verifies default runner creation and router use of the supplied container.
src/​Container.php Bypasses PSR-11 lookup for selected internal classes and the default CLI runner.
docs/​best-practices/​controllers.md Explains custom-container delegation and explicit HTTP runner configuration.

Review effort: Balanced

@clue
clue merged commit abda8cf into clue:main Oct 29, 2026
75 checks passed
@clue
clue deleted the container-psr-internals branch October 29, 2026 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants