PSR-7 & PSR-15 support for WordPress Routes #334
Merged
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.
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 aResponse
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).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 actualResponse
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.