Documentation

RestRouteAttributeRegistrar
in package

FinalYes

Attribute-driven REST routing surface: the declarative counterpart of the imperative {@see RestRouteRegistrar}.

Controllers declare their routes with Symfony #[Route] attributes (the same shape the admin surface already uses) instead of an imperative registerRoutes() body. This registrar reflection-scans each controller through the framework RouteLoaderInterface, translates every route to a WordPress path and registers it with register_rest_route, delegating the permission_callback/callback pair to the WpRestKernel. The namespace is derived from the host component ({componentName}/{version}), matching RestRouteRegistrar so both surfaces can coexist during a controller-by-controller migration.

Table of Contents

Properties

$apiNamespace  : string
$container  : ContainerInterface
$controllers  : array<int, class-string>
$kernel  : WpRestKernel
$loader  : RouteLoaderInterface

Methods

__construct()  : mixed
addController()  : void
buildRoutes()  : array<int, array{path: string, methods: list, controller: class-string, action: string}>
Flatten every registered controller's `#[Route]` attributes into WordPress route specs. Kept separate from {@see register()} so the translation is unit-testable without the `register_rest_route` side effect.
getNamespace()  : string
register()  : void
Register every route with WordPress, wiring the kernel as the permission/handler pair. Triggered on `rest_api_init`.

Properties

Methods

__construct()

public __construct(WpRestKernel $kernel, HostComponentContextInterface $context, ContainerInterface $container[, RouteLoaderInterface $loader = new RouteLoader() ][, string $apiVersion = 'v1' ]) : mixed
Parameters
$kernel : WpRestKernel
$context : HostComponentContextInterface
$container : ContainerInterface
$loader : RouteLoaderInterface = new RouteLoader()
$apiVersion : string = 'v1'

addController()

public addController(class-string $controllerClass) : void
Parameters
$controllerClass : class-string

buildRoutes()

Flatten every registered controller's `#[Route]` attributes into WordPress route specs. Kept separate from {@see register()} so the translation is unit-testable without the `register_rest_route` side effect.

public buildRoutes() : array<int, array{path: string, methods: list, controller: class-string, action: string}>
Return values
array<int, array{path: string, methods: list, controller: class-string, action: string}>

register()

Register every route with WordPress, wiring the kernel as the permission/handler pair. Triggered on `rest_api_init`.

public register() : void
On this page

Search results