API / Minn\Rest / RouteCatalogue

RouteCatalogue final readonly class

Minn\Rest\RouteCatalogue · public/minn/src/Minn/Rest/RouteCatalogue.php · 144 lines

The routes the engine serves, described in the reference's shape for the index and for an OPTIONS request: every route's namespace, its methods and the parameters it declares, gathered per concrete route from the attributes so a client learns what really works on it, with the namespaces they fall under. Routes are keyed as the reference spells them ('/wp/v2/posts/(?P<id>[\d]+)').

Constants and properties

privateSERVER_ROUTES = array ( 0 => '/batch/v1', )

The routes the reference's server registers itself, outside any namespace.

privateFIRST = 'oembed/1.0'

The namespace the reference registers before any plugin's.

privateCORE = array ( 0 => 'wp/v2', 1 => 'wp-site-health/v1', 2 => 'wp-block-editor/v1', 3 => 'wp-abilities/v1', )

The core namespaces the reference registers after the plugins', in its order.

privatereadonly Minn\Http\Router $router

Promoted from the constructor.

privatereadonly Minn\Rest\Types $types

Promoted from the constructor.

privatereadonly Minn\Rest\RestUrl $url

Promoted from the constructor.

Public

new__construct(Minn\Http\Router $router, Minn\Rest\Types $types, Minn\Rest\RestUrl $url)#
methodall(): array#

Every route the engine serves, the root and each namespace's index among them, and the namespaces.

@return array{namespaces: list<string>, routes: array<string, array<string, mixed>>}
staticordered(array $namespaces): array#

The namespaces in the order the reference's index lists them, which is the order they were registered in: oEmbed's first, then each plugin's (Minn Admin's among them) as they came, then core's own.

$namespaceslist<string>
@return list<string>
staticnamespaceOf(string $route): string#

The namespace a route is listed under: its first two segments when the second is a version. The routes the reference's server registers itself, the batch route among them, belong to none, so none is listed for them and their path answers no namespace index.

methoddescribing(string $path): ?array#

The first route whose pattern takes the path, as the reference finds the route an OPTIONS request describes, with its description; null when none does.

@return array{0: string, 1: array<string, mixed>}|null

Internals 2

Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.

privateendpoints(array $rows, array $bases): array#

Each concrete route's endpoints as the reference lists them: one per handler and set of parameters (an update's POST, PUT and PATCH are one), the methods in the reference's order, the endpoints ordered by their first method. A method an earlier pattern already answers on the route is left to it, as the router leaves it.

$rowslist<RouteRow>
$baseslist<string>
@return array<string, list<array{methods: list<string>, args: array<string, mixed>}>>
privaterank(string $method): int#

A method's place in the reference's order.