API Reference
Class and method documentation for WPZylos Routing.
Router
Frontend routing with WordPress rewrite integration.
Methods
| Method | Description |
|---|---|
get(string $pattern, callable|array $handler): Route | Register GET route |
post(string $pattern, callable|array $handler): Route | Register POST route |
put(string $pattern, callable|array $handler): Route | Register PUT route |
patch(string $pattern, callable|array $handler): Route | Register PATCH route |
delete(string $pattern, callable|array $handler): Route | Register DELETE route |
match(array $methods, string $pattern, callable|array $handler): Route | Register route for multiple methods |
any(string $pattern, callable|array $handler): Route | Register route for all methods |
group(array $attributes, callable $callback): static | Create route group |
url(string $name, array $params = []): string | Generate URL from named route |
dispatch(string $method, string $uri): ?MatchedRoute | Dispatch a request |
getRoute(string $name): ?Route | Get a route by name |
registerNamedRoute(Route $route): void | Register a named route |
getRoutes(): Route[] | Get all registered routes |
Route
Individual route definition.
Methods
| Method | Description |
|---|---|
name(string $name): static | Set route name |
middleware(string|array $middleware): static | Add middleware |
where(string $key, string $pattern): static | Add parameter constraint |
getName(): ?string | Get route name |
getMethod(): string | Get HTTP method |
getPattern(): string | Get URL pattern |
getHandler(): callable|array | Get route handler |
getMiddleware(): array | Get middleware stack |
getConstraints(): array | Get parameter constraints |
RestRouter
REST API routing for /wp-json/ endpoints.
Constructor
new RestRouter(string $namespace, string $version = 'v1')
Methods
| Method | Description |
|---|---|
get(string $pattern, callable|array $handler): RestRoute | Register GET endpoint |
post(string $pattern, callable|array $handler): RestRoute | Register POST endpoint |
put(string $pattern, callable|array $handler): RestRoute | Register PUT endpoint |
patch(string $pattern, callable|array $handler): RestRoute | Register PATCH endpoint |
delete(string $pattern, callable|array $handler): RestRoute | Register DELETE endpoint |
match(array $methods, string $pattern, callable|array $handler): RestRoute | Register multi-method endpoint |
group(array $attributes, callable $callback): static | Create route group |
resource(string $name, string $controller, array $only = []): static | Create resource routes |
getRoutes(): RestRoute[] | Get all registered routes |
getNamespace(): string | Get REST namespace |
RestRoute
REST API route definition.
Methods
| Method | Description |
|---|---|
name(string $name): static | Set route name |
middleware(string|array $middleware): static | Add middleware |
permission(string $capability): static | Set required capability |
setPermissionCallback(callable $callback): static | Set custom permission callback |
args(array $args): static | Define argument schema |
where(string $key, string $pattern): static | Add parameter constraint |
getWpMethod(): string | Get WP REST method constant |
getWpPattern(): string | Get WP-formatted pattern |
getPermission(): ?string | Get required capability |
getPermissionCallback(): ?callable | Get permission callback |
getArgs(): array | Get argument schema |
AjaxRouter
WordPress AJAX action routing.
Constructor
new AjaxRouter(ContextInterface $context, ContainerInterface $container)
Methods
| Method | Description |
|---|---|
public(string $action, callable|array $handler): AjaxRoute | Register public action |
private(string $action, callable|array $handler): AjaxRoute | Register private action (login required) |
group(array $attributes, callable $callback): static | Create route group |
url(string $action): string | Get AJAX URL for action |
nonce(string $action): string | Generate nonce for action |
nonceField(string $action): string | Generate nonce field HTML |
getRoutes(): AjaxRoute[] | Get all registered routes |
register(): void | Register all routes with WordPress |
AjaxRoute
AJAX action definition.
Methods
| Method | Description |
|---|---|
middleware(string|array $middleware): static | Add middleware |
nonce(string $action): static | Set custom nonce action |
withoutNonce(): static | Disable nonce verification |
isPublic(): bool | Check if route is public |
shouldVerifyNonce(): bool | Check if nonce should be verified |
getAction(): string | Get action name |
getHandler(): callable|array | Get route handler |
getMiddleware(): array | Get middleware stack |
getNonceAction(): string | Get nonce action name |
RouteDispatcher
Dispatches frontend routes on template_redirect.
Methods
| Method | Description |
|---|---|
dispatch(): bool | Dispatch matching route, returns handled |
shouldDispatch(): bool | Check if dispatch should run in context |
registerHook(): void | Register WordPress hook |
RestDispatcher
Registers REST routes on rest_api_init.
Methods
| Method | Description |
|---|---|
register(): void | Register all routes with WordPress |
registerHook(): void | Register WordPress hook |
WPAdapter
WordPress rewrite integration.
Methods
| Method | Description |
|---|---|
registerRewriteRules(Route[] $routes): void | Register rewrite rules |
addQueryVars(array $vars): array | Add query variables |
isPluginRoute(): bool | Check if current request matches |
getMatchedPattern(): ?string | Get matched route pattern |
static flush(): void | Flush rewrite rules |
RoutingServiceProvider
Service provider for routing components.
Registered Services
| Binding | Type |
|---|---|
Router::class | Singleton |
'router' | Alias |
RestRouter::class | Singleton |
'rest' | Alias |
AjaxRouter::class | Singleton |
'ajax' | Alias |
RouteDispatcher::class | Singleton |
RestDispatcher::class | Singleton |
WPAdapter::class | Singleton |