WpRouter
in package
implements
RouterInterface
Symfony-backed router for the WordPress adapter, the counterpart of the Moodle adapter's `MoodleRouter`.
Routes live in a RouteCollection; discovery is delegated to the
framework RouteLoaderInterface, which reflection-scans controllers
for #[Route] attributes (class-level attribute = path/name group).
Controllers declare their own routes, and the same collection feeds matching
(WpHttpKernel) and URL generation.
URL generation returns Symfony PATHS (/collaborators/42). The router does
not compose wp-admin URLs: the admin surface (AdminRouteRegistrar) passes
the path in the route query argument of its menu page
(admin.php?page={slug}&route={path}), and the consumer builds that URL.
Table of Contents
Interfaces
- RouterInterface
- Adapter-local routing contract, the WordPress counterpart of the Moodle adapter's `RouterInterface`.
Properties
- $context : RequestContext|null
- $generator : UrlGenerator|null
- $loader : RouteLoaderInterface
- $routes : RouteCollection
Methods
- __construct() : mixed
- generateUrl() : string
- Generate a URL path for a named route.
- getContext() : RequestContext|null
- Get the current routing context (host, scheme, base path).
- getRoutes() : RouteCollection
- Retrieve the registered route collection.
- initializeContext() : void
- Initialize the routing context (base URL, host, scheme) from globals.
- register() : void
- Manually register a route.
- registerDefaultRoutes() : void
- Register default system routes (e.g. 404) and global regex requirements.
- scanAnnotations() : void
- Scan a controller class for `#[Route]` attributes and register the discovered routes (delegated to the framework route loader).
Properties
$context
private
RequestContext|null
$context
= null
$generator
private
UrlGenerator|null
$generator
= null
$loader read-only
private
RouteLoaderInterface
$loader
= new RouteLoader()
$routes read-only
private
RouteCollection
$routes
Methods
__construct()
public
__construct([RouteLoaderInterface $loader = new RouteLoader() ]) : mixed
Parameters
- $loader : RouteLoaderInterface = new RouteLoader()
generateUrl()
Generate a URL path for a named route.
public
generateUrl(string $route[, array<string|int, mixed> $parameters = [] ][, int $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH ]) : string
Parameters
- $route : string
- $parameters : array<string|int, mixed> = []
- $referenceType : int = UrlGeneratorInterface::ABSOLUTE_PATH
Return values
stringgetContext()
Get the current routing context (host, scheme, base path).
public
getContext() : RequestContext|null
Return values
RequestContext|nullgetRoutes()
Retrieve the registered route collection.
public
getRoutes() : RouteCollection
Return values
RouteCollectioninitializeContext()
Initialize the routing context (base URL, host, scheme) from globals.
public
initializeContext() : void
register()
Manually register a route.
public
register(string $name, string $path, string $controller, string $method[, array<string|int, mixed> $requirements = [] ]) : void
Parameters
- $name : string
- $path : string
- $controller : string
- $method : string
- $requirements : array<string|int, mixed> = []
-
regex requirements for parameters
registerDefaultRoutes()
Register default system routes (e.g. 404) and global regex requirements.
public
registerDefaultRoutes() : void
scanAnnotations()
Scan a controller class for `#[Route]` attributes and register the discovered routes (delegated to the framework route loader).
public
scanAnnotations(ContainerInterface $container[, string|null $specificClass = null ]) : void
Parameters
- $container : ContainerInterface
- $specificClass : string|null = null