Skip to content

refactor: let the WpRest module run without Laravel's application - #464

Merged
ogorzalka merged 1 commit into
release/v13.36.0from
refactor/wp-rest-decoupling
Oct 12, 2026
Merged

ogorzalka merged 1 commit into
release/v13.36.0from
refactor/wp-rest-decoupling

Conversation

@ogorzalka

@ogorzalka ogorzalka commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

First step of extracting pollora/wp-rest (roadmap, medium term: "dependency injection without Laravel's container"). Nothing moves yet: the module stops reaching for Laravel's application.

What changes

  • WpRestDiscovery resolves each #[WpRestRoute] controller through the discovery's instance pool: Laravel's container in a Pollora application, pollora/discovery's reflection autowiring elsewhere.
  • WpRestAttributableWrapper takes that instance instead of building it (newInstance() with no argument, and resolve(LoggerInterface) on failure).
  • Custom HandlesAttributes attributes get the PSR-11 container given to WpRestDiscovery (autowired by Laravel) instead of app().
  • tests/Unit/WpRest/PackageBoundaryTest.php: the module (with Pollora\Support\WpGlobals, used by it alone) may only use the attributes, discovery, PSR contracts and WordPress; its service provider stays in the framework.

Bug fixed on the way

A controller with a required constructor dependency was never built (newInstance() failed, the error was logged), so every request to its routes failed with Trying to invoke non static method … without an object. New test: a controller depending on a repository registers its route on rest_api_init and answers through it.

Checks

1882 tests, PHPStan 0. pollora-test cannot run the release branch (it lacks pollora/discovery and pollora/attributes) and the diff does not apply to develop; the E2E suite covers REST routes with and without permissions.

WpRestDiscovery resolves controllers through the discovery's instance
pool and hands custom HandlesAttributes attributes the PSR-11 container
it was given, instead of app(); the wrapper takes the instance instead of
building it with resolve() for its logger. An architecture test keeps the
module to attributes, discovery, PSR contracts and WordPress.

Fixes a REST controller with a constructor dependency never being built.
@ogorzalka
ogorzalka merged commit 1343d8e into release/v13.36.0 Oct 12, 2026
11 checks passed
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.

1 participant