snicco / http-routing-bundle
Requires
- php: ^7.4|^8.0
- laminas/laminas-httphandlerrunner: ^2.1
- nyholm/psr7-server: ^1.0.2
- psr/log: ^1.1.1
- snicco/better-wp-api: ^2.0
- snicco/better-wp-hooks-bundle: ^2.0
- snicco/event-dispatcher: ^2.0
- snicco/http-routing: ^2.0
- snicco/kernel: ^2.0
- snicco/minimal-logger: ^2.0
- snicco/psr7-error-handler: ^2.0
- snicco/str-arr: ^2.0
- webimpress/safe-writer: ^2.2
- webmozart/assert: ^1.10
Requires (Dev)
- codeception/codeception: ^4.1.29
- guzzlehttp/psr7: ^2.1
- laminas/laminas-diactoros: ^2.8
- lucatume/wp-browser: ~3.1.4
- nyholm/psr7: ^1.0.0
- phpunit/phpunit: ^9.5.13
- snicco/http-routing-testing: ^2.0
- snicco/pimple-bridge: ^2.0
- snicco/testing-bundle: ^2.0
Conflicts
- snicco/better-wp-cache: <2.0.0-beta.9
- snicco/better-wp-cache-bundle: <2.0.0-beta.9
- snicco/better-wp-cli: <2.0.0-beta.9
- snicco/better-wp-cli-testing: <2.0.0-beta.9
- snicco/better-wp-hooks: <2.0.0-beta.9
- snicco/better-wp-mail: <2.0.0-beta.9
- snicco/better-wp-mail-bundle: <2.0.0-beta.9
- snicco/better-wp-mail-testing: <2.0.0-beta.9
- snicco/better-wpdb: <2.0.0-beta.9
- snicco/better-wpdb-bundle: <2.0.0-beta.9
- snicco/blade-bridge: <2.0.0-beta.9
- snicco/blade-bundle: <2.0.0-beta.9
- snicco/content-negotiation-middleware: <2.0.0-beta.9
- snicco/debug-bundle: <2.0.0-beta.9
- snicco/default-headers-middleware: <2.0.0-beta.9
- snicco/eloquent: <2.0.0-beta.9
- snicco/encryption-bundle: <2.0.0-beta.9
- snicco/event-dispatcher-testing: <2.0.0-beta.9
- snicco/guests-only-middleware: <1.0.0
- snicco/http-routing-testing: <2.0.0-beta.9
- snicco/https-only-middleware: <2.0.0-beta.9
- snicco/illuminate-container-bridge: <2.0.0-beta.9
- snicco/kernel-testing: <2.0.0-beta.9
- snicco/method-override-middleware: <2.0.0-beta.9
- snicco/must-match-route-middleware: <2.0.0-beta.9
- snicco/no-robots-middleware: <2.0.0-beta.9
- snicco/open-redirect-protection-middleware: <2.0.0-beta.9
- snicco/payload-middleware: <2.0.0-beta.9
- snicco/pimple-bridge: <2.0.0-beta.9
- snicco/psr7-error-handler: <1.0.0
- snicco/redirect-middleware: <2.0.0-beta.9
- snicco/session: <2.0.0-beta.9
- snicco/session-bundle: <2.0.0-beta.9
- snicco/session-psr16-bridge: <2.0.0-beta.9
- snicco/session-testing: <2.0.0-beta.9
- snicco/session-wp-bridge: <2.0.0-beta.9
- snicco/share-cookies-middleware: <2.0.0-beta.9
- snicco/signed-url: <2.0.0-beta.9
- snicco/signed-url-psr15-bridge: <2.0.0-beta.9
- snicco/signed-url-psr16-bridge: <2.0.0-beta.9
- snicco/signed-url-testing: <2.0.0-beta.9
- snicco/signed-url-wp-bridge: <2.0.0-beta.9
- snicco/templating: <2.0.0-beta.9
- snicco/templating-bundle: <2.0.0-beta.9
- snicco/testable-clock: <2.0.0-beta.9
- snicco/testing-bundle: <2.0.0-beta.9
- snicco/trailing-slash-middleware: <2.0.0-beta.9
- snicco/wp-auth-only-middleware: <2.0.0-beta.9
- snicco/wp-capability-middleware: <2.0.0-beta.9
- snicco/wp-capapility-middleware: <1.0.0
- snicco/wp-guests-only-middleware: <2.0.0-beta.9
- snicco/wp-nonce-middleware: <2.0.0-beta.9
- dev-master
- v2.0.0-beta.9
- v2.0.0-beta.8
- v2.0.0-beta.7
- v2.0.0-beta.6
- v2.0.0-beta.5
- v2.0.0-beta.4
- v2.0.0-beta.3
- v2.0.0-beta.2
- v2.0.0-beta.1
- v1.10.1
- v1.10.0
- v1.9.1
- v1.9.0
- v1.8.1
- v1.8.0
- v1.7.0
- v1.6.2
- v1.6.1
- v1.6.0
- v1.5.0
- v1.4.2
- v1.4.1
- v1.4.0
- v1.3.0
- v1.2.1
- v1.2.0
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.2
- v1.0.1
- v1.0.0
- dev-beta
This package is auto-updated.
Last update: 2024-11-07 14:45:39 UTC
README
This WordPress bundle configures the standalone snicco/http-routing
library for usage in applications based on snicco/kernel
.
Installation
composer install snicco/http-routing-bundle
Configuration
This bundle has extensive configuration options:
- See config/routing.php for the available routing configuration options.
- See config/middleware.php for the available middleware configuration options.
- See config/http_error_handling.php for the available error handling configuration options.
If these files do not exist in your configuration directory the default configuration will be copied the first time the kernel is booted in dev mode.
Add the HttpRoutingBundle
to your bundles.php
configuration file.
<?php // /path/to/configuration/bundles.php use Snicco\Bundle\HttpRouting\HttpRoutingBundle; return [ 'bundles' => [ Snicco\Component\Kernel\ValueObject\Environment::ALL => [ HttpRoutingBundle::class ] ] ];
Usage
This bundle provides to main services that should be used:
HttpKernelRunner
: Sends the current request at the right time through your application. This class serves as an entrypoint to your HTTP request-response cycle.WPAdminMenu
: Uses theAdminMenu
that is configured by your route definitions to integration them with the WordPress admin menu.
This is an example of how the bootstrap file of a plugin could look like:
<?php use Snicco\Bundle\HttpRouting\HttpKernelRunner; use Snicco\Bundle\HttpRouting\WPAdminMenu; use Snicco\Component\Kernel\Kernel; // Create kernel /** * @var Kernel $kernel */ $kernel->boot(); /** * @var HttpKernelRunner $runner */ $runner = $kernel->container()->make(HttpKernelRunner::class); $is_admin = is_admin(); $runner->listen($is_admin); if ($is_admin) { /** * @var WPAdminMenu $admin_menu */ $admin_menu = $kernel->container()->make(WPAdminMenu::class); $admin_menu->setUp('my-plugin-text-domain'); }
Requests and Responses
This bundle takes care of running the middleware pipeline of
the snicco/http-routing
library at just the right moments inside the
WordPress request lifecycle.
There are three types of requests that can be handled:
- API requests, requests where the URI path starts with the API path prefix defined in your routing configuration.
- Admin requests, request that go to the WordPress admin area.
- Frontend requests, all other requests.
The HttpKernelRunner::listen()
method sets appropriate hooks based on the current request type and will then pipe a
request through your application.
All of your middlewares and controllers have three types of responses that can be returned:
DelegatedResponse
, with headers that should be sentDelegatedResponse
, without headers- Any other PSR-7 response
Depending on the current request type here is what will happen for each response type:
- API-request / Frontend-request:
- Admin-request:
Middleware
This bundle provides a couple PSR-15 middlewares that you can use in your application:
ErrorsToExceptions
: Transforms all errors inside your middleware pipeline to proper exceptions. Strongly recommended.SetUserId
: Adds the user id of the current WordPress user to the request.SimpleTemplating
: Adds a simple middleware to renderViewResponses
where the view name has to be an absolute path.
Error handling
This bundle automatically configures the snicco/psr7-error-handler
library that is used by snicco/http-routing
.
You can configure this behaviour with the http_error_handling configuration.
All exceptions inside YOUR middleware pipeline will be handled automatically. WordPress core code and plugins are not affected by this at all.
Contributing
This repository is a read-only split of the development repo of the Snicco project.
This is how you can contribute.
Reporting issues and sending pull requests
Please report issues in the Snicco monorepo.
Security
If you discover a security vulnerability within BetterWPCache, please follow our disclosure procedure.