Documentation

AdminRouteRegistrar
in package

FinalYes

Admin routing surface: registers a wp-admin menu tree whose pages all render through one dispatch pipeline — the current page/route resolves against the adapter {@see RouterInterface} route collection (controller-declared `#[Route]` attributes or imperative registrations) and executes through the framework HTTP kernel, inheriting its middleware pipeline and the `#[Auth]`/`#[Middleware]`/`#[Nonce]` attributes.

Generalizes the pattern each MIDDAG plugin used to hand-roll: the menu slug derives from the host component name (no brand literal), unmatched routes flow through the injected fallback (so the lib forces neither Inertia nor a "Dashboard" page), and responses are emitted through the injected ResponseEmitterInterface so the previously untestable header/echo paths stay assertable. All wp-admin calls go through AdminSupport.

Table of Contents

Properties

$capabilities  : array<string, string>
$context  : HostComponentContextInterface
$defaultCapability  : string
Capability enforced for a page not present in {@see self::$capabilities} (defense-in-depth default; overwritten by the main menu's capability on register()). Fail-closed to WordPress's admin default.
$emitter  : ResponseEmitterInterface
$fallback  : Closure
$kernel  : HttpKernelInterface
$pageHookSuffixes  : array<int, string>
$pageSlugs  : array<int, string>
$routeBases  : array<string, string>
$router  : RouterInterface

Methods

__construct()  : mixed
dispatch()  : void
Resolve a page/route/method to a route and execute it through the HTTP kernel, falling back to the injected callable when nothing matches.
handleInertiaRequest()  : void
Early Inertia XHR interceptor (wire on `admin_init`): if this is an Inertia request for one of this registrar's pages, render and terminate before WordPress emits the admin HTML shell.
menuSlug()  : string
Top-level menu slug: the host component name.
pageHookSuffixes()  : array<int, string>
Registered page hook suffixes (for the consumer's asset-enqueue guard).
register()  : void
Register the wp-admin menu tree. Every page renders through renderApp().
renderApp()  : void
wp-admin page render callback: reads the current page/route/method from the request at this boundary, then dispatches. The response body is written inside the admin shell (no termination).
submenuSlug()  : string
Submenu slug: `{component}-{suffix}`.
emit()  : void
Emit a PSR-7 response through the emitter seam (status, headers, body).
matches()  : bool
Whether the route collection has a route for this path/method. Matching runs here (and again inside the kernel) so the no-match case can flow to the fallback instead of a kernel 404.
psrRequest()  : ServerRequestInterface
Build the PSR-7 request the kernel dispatches: the current request's query/body/cookies/files/server, re-targeted at the synthetic admin route path (the kernel matches paths, not `admin.php?page=...&route=...`).
requestString()  : string
Read a sanitized string from a request superglobal, or $default when the key is absent or not a string (defends against array-valued params).
respondToCurrentRequest()  : void
Shared body of renderApp()/handleInertiaRequest(): capability gate at the WordPress boundary (renderApp() is also reachable through admin_init and admin-ajax.php, where WP's own menu gate never runs — fail-closed), then dispatch; optionally terminate (Inertia XHR path, which must pre-empt the admin shell).
userCanAccess()  : bool
Whether the current user may access $page, checked against the page's registered capability (or the default when the page is unknown). Reads through {@see UserSupport::currentUserCan()}, which fail-closes to false when WordPress is absent.

Properties

$capabilities

private array<string, string> $capabilities = []

page slug => required capability

$defaultCapability

Capability enforced for a page not present in {@see self::$capabilities} (defense-in-depth default; overwritten by the main menu's capability on register()). Fail-closed to WordPress's admin default.

private string $defaultCapability = 'manage_options'

Methods

dispatch()

Resolve a page/route/method to a route and execute it through the HTTP kernel, falling back to the injected callable when nothing matches.

public dispatch(string $page, string $route, string $method) : void

Pure — no superglobals.

Parameters
$page : string
$route : string
$method : string

handleInertiaRequest()

Early Inertia XHR interceptor (wire on `admin_init`): if this is an Inertia request for one of this registrar's pages, render and terminate before WordPress emits the admin HTML shell.

public handleInertiaRequest() : void

menuSlug()

Top-level menu slug: the host component name.

public menuSlug() : string
Return values
string

pageHookSuffixes()

Registered page hook suffixes (for the consumer's asset-enqueue guard).

public pageHookSuffixes() : array<int, string>
Return values
array<int, string>

renderApp()

wp-admin page render callback: reads the current page/route/method from the request at this boundary, then dispatches. The response body is written inside the admin shell (no termination).

public renderApp() : void

submenuSlug()

Submenu slug: `{component}-{suffix}`.

public submenuSlug(string $slugSuffix) : string
Parameters
$slugSuffix : string
Return values
string

emit()

Emit a PSR-7 response through the emitter seam (status, headers, body).

private emit(ResponseInterface $response) : void
Parameters
$response : ResponseInterface

matches()

Whether the route collection has a route for this path/method. Matching runs here (and again inside the kernel) so the no-match case can flow to the fallback instead of a kernel 404.

private matches(string $path, string $method) : bool
Parameters
$path : string
$method : string
Return values
bool

psrRequest()

Build the PSR-7 request the kernel dispatches: the current request's query/body/cookies/files/server, re-targeted at the synthetic admin route path (the kernel matches paths, not `admin.php?page=...&route=...`).

private psrRequest(string $method, string $path) : ServerRequestInterface
Parameters
$method : string
$path : string
Return values
ServerRequestInterface

requestString()

Read a sanitized string from a request superglobal, or $default when the key is absent or not a string (defends against array-valued params).

private requestString(array<string, mixed> $source, string $key[, string $default = '' ]) : string
Parameters
$source : array<string, mixed>
$key : string
$default : string = ''
Return values
string

respondToCurrentRequest()

Shared body of renderApp()/handleInertiaRequest(): capability gate at the WordPress boundary (renderApp() is also reachable through admin_init and admin-ajax.php, where WP's own menu gate never runs — fail-closed), then dispatch; optionally terminate (Inertia XHR path, which must pre-empt the admin shell).

private respondToCurrentRequest(bool $terminate) : void
Parameters
$terminate : bool

userCanAccess()

Whether the current user may access $page, checked against the page's registered capability (or the default when the page is unknown). Reads through {@see UserSupport::currentUserCan()}, which fail-closes to false when WordPress is absent.

private userCanAccess(string $page) : bool
Parameters
$page : string
Return values
bool
On this page

Search results