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 +30 -0 2.0.0 → 2.1.1 View file →
@@ -1,0 +1,30 @@
1 +<?php
2 +
3 +declare(strict_types=1);
4 +
5 +namespace Metricool\Interfaces;
6 +
7 +interface MiddlewareInterface
8 +{
9 + /**
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.
28 + */
29 + public function handle(\WP_REST_Request $request, callable $next);
30 +}