RuntimeRoutes final class
Minn\Rest\RuntimeRoutes · public/minn/src/Minn/Rest/RuntimeRoutes.php · 479 lines
Routes plugin code registered with register_rest_route(), answered through the runtime's server after the engine's own routes have had their turn; the runtime's say before the engine answers at all (an authentication refusal, a pre-dispatch answer, a removed endpoint); and the runtime's namespaces folded into the index.
Used by 19 (show)
Constants and properties
| private | DISPATCH_DONE = array ( 'rest_filter_response_fields' => 10, 'rest_send_allow_header' => 10, ) | rest_post_dispatch's defaults the engine does itself: every answer is cut to its _fields before it is served. |
| private | ROUTE_SCOPED = array ( '_wp_connectors_rest_settings_dispatch' => array ( 0 => 10, 1 => '/wp/v2/settings', ), ) | rest_post_dispatch's defaults that touch one route only: elsewhere they hand the answer back as it came, so they are left out there. |
| private | SERVE_DONE = array ( '_oembed_rest_pre_serve_request' => 10, 'rest_send_cors_headers' => 10, ) | rest_pre_serve_request's defaults the engine does itself: oEmbed's XML (see oembedXml()). |
| private | static ?WeakMap $requests | |
| private | static ?WeakMap $matches | |
| private | static ?WeakMap $origins |
Public
| static | gate(Minn\Http\Request $request): ?Minn\Http\Response# | What plugin code decides before any route runs, engine routes included, in the reference's order: rest_authentication_errors may refuse the request, rest_pre_dispatch may answer it outright, and a route a rest_endpoints filter removed is no route at all. Null lets the engine's router proceed. | |||
| static | predispatch(Minn\Http\Request $request): ?Minn\Http\Response# | What plugin code decides before a route runs, for a request inside another (an embedded link) as for the first: rest_pre_dispatch may answer it outright, and a route a rest_endpoints filter removed is no route at all. Null lets the router proceed. | |||
| static | dispatch(Minn\Http\Request $request): ?Minn\Http\Response# | Null when the runtime has no route for the request either. | |||
| static | allowedMethods(string $route, WP_REST_Request $wpRequest): array# | The methods of a plugin's route whose handler lets this request through (a handler with no permission callback does). @return list<string> @return list<string> | |||
| static | targetHints(string $href): ?array# | The methods a self link's caller may use there, as the reference hints them on every self link it serves (targetHints.allow): the route the link names, each of its methods whose handler lets this caller through; null when no route of the runtime's takes the link. A route the engine answers itself is judged by its policies, as its Allow header is (probe rest-registry-controllers). @return list<string>|null | |||
| static | mergeIndex(Minn\Http\Response $response): Minn\Http\Response# | The engine's index plus the namespaces and routes the runtime holds. | |||
| static | adopt(Minn\Http\Request $request, WP_REST_Request $wpRequest): void# | An in-process call's own request object stands for the engine's request: the server sets its route's parameters on it, as the reference's dispatch does. | |||
| static | sanitized(Minn\Http\Request $request, array $registered): WP_REST_Request# | The request as the list's handler reads it: its parameters with their defaults, sanitized by their schemas, as plugins' filters see it too.
| |||
| static | wpRequest(Minn\Http\Request $request): WP_REST_Request# | The request as the runtime's server reads it, and as a REST filter or action hands it to plugins: the same object each time. | |||
| static | matched(Minn\Http\Request $request, string $route, array $handler): void# | Keeps the route and handler a request matched, for the response plugins see at serving.
| |||
| static | toWpError(Minn\RestError $error): WP_Error# | An engine refusal as plugins handle one. | |||
| static | toWp(Minn\Http\Response $response): WP_REST_Response# | An engine answer as plugins handle one: its data decoded (an empty object stays one), its links on the response rather than in the data, its status and headers. | |||
| static | wpHeaders(array $headers, string $route = ''): array# | A route's own headers as the reference's response object holds them: a list's totals are numbers, but the comments list's stay text.
@return array<string, string|int> | |||
| static | itemResponse(array $item): WP_REST_Response# | One item a response carries, as a response object: its data without _links, the links on the response.
| |||
| static | fromWp(mixed $result): Minn\Http\Response# | Whatever the filters left, as the engine sends it; what they handed back untouched is the engine's own answer, byte for byte. | |||
| static | serve(Minn\Http\Request $request, Minn\Http\Response $response): Minn\Http\Response# | The server's last word on any REST answer, engine or plugin route, as the reference serves one: rest_post_dispatch may change it, rest_pre_serve_request may serve it itself (what it prints is the body), and rest_pre_echo_response may rewrite the data echoed. With nothing hooked, the answer goes out as it is. | |||
| static | servedAsXml(Minn\Http\Request $request, Minn\Http\Response $response): bool# | Whether the answer went out as oEmbed's XML. The reference prints it in rest_pre_serve_request ahead of rest_send_cors_headers, so none of the CORS headers follow it, Vary: Origin among them. | |||
| static | ensure(mixed $result): WP_REST_Response# | A callback's return as a response object, an error converted. | |||
| static | server(): WP_REST_Server# | The runtime's REST server, the one door to it (built, with rest_api_init, on first use). |
Internals 10
Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.
| private | allow(WP_REST_Response $result, string $route, WP_REST_Request $wpRequest): void# | The Allow header a plugin's route answers with, as the reference's rest_send_allow_header sets it: every method of the route whose handler's permission callback lets this request through (a handler with none counts). Left alone when the handler set one itself. | |||
| private | dispatchDone(Minn\Http\Request $request): array# | @return array<string, int> the rest_post_dispatch callbacks this request leaves out: the engine's own, and the route-scoped ones off their route | |||
| private | asksForXml(Minn\Http\Request $request): bool# | The embed route only: the proxy answers JSON whatever its format. | |||
| private | oembedXml(Minn\Http\Request $request, Minn\Http\Response $response): ?Minn\Http\Response# | An embed asked for as XML (format=xml), as the reference's _oembed_rest_pre_serve_request serves it over HTTP: the data, or the error (its code, message and data), as an oembed document, text/xml, with the status it had. Null for anything else. | |||
| private | look(WP_REST_Response $response): array# | What a response looks like to the code that may change it. @return array<int, mixed> @return array<int, mixed> | |||
| private | remember(object $made, Minn\Http\Response|Minn\RestError $origin, array $look): void# | ||||
| private | decode(string $json): mixed# | JSON as arrays, as plugins read REST data, with an empty object kept an object so it is sent back as one. | |||
| private | expand(array $links): array# | Compacted link relations ("wp:term") back to the relations a response holds ("https://api.w.org/term"); the CURIE list itself is rebuilt when the response is compacted again.
@return array<string, list<array<string, mixed>>> | |||
| private | newWpRequest(Minn\Http\Request $request): WP_REST_Request# | ||||
| private | toResponse(WP_REST_Response $response): Minn\Http\Response# |
Nothing matches.