| @@ -6,9 +6,25 @@ | ||
| 6 | 6 | |
| 7 | 7 | interface MiddlewareInterface |
| 8 | 8 | { |
| 9 | 9 | /** |
| 10 | - * Handle an incoming request. Return null to continue to the next | |
| 11 | - * middleware/callback, or return a WP_REST_Response to short-circuit. | |
| 10 | + * Handle an incoming REST request as part of the middleware pipeline. | |
| 11 | + * | |
| 12 | + * Middleware are composed into an "onion" pipeline by | |
| 13 | + * {@see \Metricool\Managers\EndpointManager::callbackMiddleware()}, where each | |
| 14 | + * layer wraps the next one and the endpoint callback sits at the core. | |
| 15 | + * | |
| 16 | + * Continue the request with: `return $next($request);` | |
| 17 | + * | |
| 18 | + * Short-circuit: return a `\WP_REST_Response` directly, | |
| 19 | + * e.g. a 403 when an authorization check fails. Neither the remaining | |
| 20 | + * middleware nor the endpoint callback will run. | |
| 21 | + * | |
| 22 | + * Thrown exceptions are caught by the pipeline wrapper and converted into a | |
| 23 | + * 500 `\WP_REST_Response` containing the exception message. | |
| 24 | + * | |
| 25 | + * @param \WP_REST_Request $request The incoming REST request. | |
| 26 | + * @param callable(\WP_REST_Request): mixed $next The next middleware in the pipeline | |
| 27 | + * @return mixed `$next($request)` or `\WP_REST_Response` when short-circuiting. | |
| 12 | 28 | */ |
| 13 | - public function handle(\WP_REST_Request $request): ?\WP_REST_Response; | |
| 29 | + public function handle(\WP_REST_Request $request, callable $next); | |
| 14 | 30 | } |