PluginProbe
Metricool – Social media and site statistics / 2.1.1
Metricool – Social media and site statistics v2.1.1
2.1.1 2.1.0 2.0.2 2.0.1 2.0.0 1.27 trunk
← All changes | app/Interfaces/MiddlewareInterface.php +19 -3 2.0.2 → 2.1.1 View file →
@@ -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 }