Index

tWithRoutes

MMO\core\classes · 1 symbol · generated 5 Oct 2026

trait

tWithRoutes

tWithRoutes.php:23

Gives a controller class (any class with methods decorated with #[APIRoute(...)], e.g. an aController) convenient static access to its own routes as registered in the running Application: looking a route up by method name, building a URL for it, or turning it into a Link.

trait MMO\core\classes\tWithRoutes
Namespace
MMO\core\classes
class RepositoryController { use tWithRoutes; #[APIRoute('GET|data/schemas.json', 'Get schemas', mediaTypes: ['json'])] public function routeSchemas(Route $route): array {...} } RepositoryController::Url('routeSchemas'); // e.g. '/data/schemas.json', once the app is running and this // controller is registered

Index

ExtractRoutes($config) staticExtract all the APIRoute from this class, regardless of the fact they are registered in the application
HasRoutes() staticTells if any APIRoute are registered in the application
Link($method, $data) staticBuild a Link (URL + label/icon/description/title, taken from the route's APIRoute metadata) for a registered route.
Route($method) staticGet a registered APIRoute WARNING: if this class was not registered in the application, it will return null.
Routes() staticGet a list of registered APIRoutes (from this class) in the application WARNING: if this class was not registered in the application, it will return an empty array.
Url($method, $data) staticBuild the URL for a registered route, filling in any {placeholder} from $data.

Methods6

ExtractRoutes($config)

statictWithRoutes.php:92

Extract all the APIRoute from this class, regardless of the fact they are registered in the application

static function ExtractRoutes(array $config = []): array
$config = []array
returnsarray
RepositoryController::ExtractRoutes(); // every #[APIRoute] declared on this class, via reflection, // even if the class was never registered with an Application

HasRoutes()

statictWithRoutes.php:52

Tells if any APIRoute are registered in the application

static function HasRoutes(): bool
returnsbool
RepositoryController::HasRoutes(); // true once this controller has been registered with the Application

Route($method)

statictWithRoutes.php:43

Get a registered APIRoute WARNING: if this class was not registered in the application, it will return null.

static function Route(string $method): ?MMO\core\attributes\APIRouteuse ExtractRoutes instead to get a list of all APIRoute, even if the class is not registered in the application
$methodstringthe name of the method carrying the #[APIRoute] attribute
returnsnull | APIRoute
RepositoryController::Route('routeSchemas'); // the APIRoute for that method, or null if not registered

Routes()

statictWithRoutes.php:31

Get a list of registered APIRoutes (from this class) in the application WARNING: if this class was not registered in the application, it will return an empty array.

static function Routes(): arrayuse ExtractRoutes instead to get a list of all APIRoute, even if the class is not registered in the application
returnsarray
RepositoryController::Routes(); // every APIRoute this controller registered with the running Application

Url($method, $data)

statictWithRoutes.php:64

Build the URL for a registered route, filling in any {placeholder} from $data.

static function Url(string $method, ?array $data = null): string
$methodstringthe name of the method carrying the #[APIRoute] attribute
$data = nullnull | arrayvalues for the route's URL placeholders (e.g. {uid} in data.json?uid={uid})
returnsstring
throwsif $method has no registered route (either the class or the method is not routed)
RepositoryController::Url('routeEntity', ['uid' => 'user/42']); // e.g. '/data.json?uid=user/42'