Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PSR-7 & PSR-15 support for WordPress Routes #334

Merged
merged 9 commits into from
Jan 30, 2024
Merged

Conversation

broskees
Copy link
Contributor

@broskees broskees commented Jan 26, 2024

This PR add PSR-7 & PSR-15 support for WordPress Routes.

By using output buffering to capture WordPress's output and make it the body of a Response, we can force WordPress requests to actually emit a Response class. This allows PSR-15 (Middleware) and and PSR-7 (Request/Response classes) compatibility for WordPress itself. This works EVEN if WordPress uses output buffering as well, since output buffering can handle nested calls (see here).

WordPress requests are already a Laravel Route, why is this necessary also?

For Middleware to be fully functional, they should also be able to make changes to the Response before it's sent to the client (See Laravel's documentation for an example of this: https://laravel.com/docs/10.x/middleware#before-after-middleware). This is impossible unless there is an actual Response class to manipulate.

Additionally, I'm improving on my last PR by using named routes instead of using a fake JsonResponse to identify WordPress requests like in my last PR. This lowers our maintenance burden and uses Laravel's native route matching to identify WordPress routes instead.

@QWp6t
Copy link
Member

QWp6t commented Jan 30, 2024

@Log1x, @broskees

Does my refactor make sense to y'all? If so, we can merge this. (I just didn't want to do a significant refactor without another pair of eyes peepin' it.)

@Log1x
Copy link
Member

Log1x commented Jan 30, 2024

Does my refactor make sense to y'all? If so, we can merge this. (I just didn't want to do a significant refactor without another pair of eyes peepin' it.)

LGTM :shipit:

@QWp6t QWp6t merged commit 9de4924 into roots:main Jan 30, 2024
2 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.

3 participants