Elgg  Version 6.2
Public Member Functions | List of all members
Elgg\Router\RouteRegistrationService Class Reference

Route registration service. More...

Public Member Functions

 __construct (protected EventsService $events, protected RouteCollection $routes, protected UrlGenerator $generator)
 Constructor. More...
 
 register (string $name, array $params=[])
 Register a new route. More...
 
 unregister (string $name)
 Unregister a route by its name. More...
 
 get (string $name)
 Get route config from its name. More...
 
 all ()
 Get all registered routes. More...
 
 generateUrl (string $name, array $parameters=[])
 Generate a absolute URL for a named route. More...
 
 resolveRouteParameters (string $name,?\ElggEntity $entity=null, array $parameters=[])
 Populates route parameters from entity properties. More...
 

Detailed Description

Route registration service.

Definition at line 16 of file RouteRegistrationService.php.

Constructor & Destructor Documentation

Elgg\Router\RouteRegistrationService::__construct ( protected EventsService  $events,
protected RouteCollection  $routes,
protected UrlGenerator  $generator 
)

Constructor.

Parameters
EventsService$eventsEvents service
RouteCollection$routesRoute collection
UrlGenerator$generatorURL Generator

Definition at line 27 of file RouteRegistrationService.php.

Member Function Documentation

Elgg\Router\RouteRegistrationService::all ( )

Get all registered routes.

Returns
Route[]

Definition at line 170 of file RouteRegistrationService.php.

Elgg\Router\RouteRegistrationService::generateUrl ( string  $name,
array  $parameters = [] 
)

Generate a absolute URL for a named route.

Parameters
string$nameRoute name
array$parametersQuery parameters
Returns
string|null

Definition at line 182 of file RouteRegistrationService.php.

Elgg\Router\RouteRegistrationService::get ( string  $name)

Get route config from its name.

Parameters
string$nameRoute name
Returns
Route|null

Definition at line 162 of file RouteRegistrationService.php.

Elgg\Router\RouteRegistrationService::register ( string  $name,
array  $params = [] 
)

Register a new route.

Route paths can contain wildcard segments, i.e. /blog/owner/{username} To make a certain wildcard segment optional, add ? to its name, i.e. /blog/owner/{username?}

Wildcard requirements for common named variables such as 'guid' and 'username' will be set automatically.

Parameters
string$nameUnique route name This name can later be used to generate route URLs
array$paramsRoute parameters
  • path : path of the route
  • resource : name of the resource view
  • defaults : default values of wildcard segments
  • requirements : regex patterns for wildcard segment requirements
  • methods : HTTP methods
  • options : additional route options
Returns
Route
Exceptions
InvalidArgumentException

Definition at line 57 of file RouteRegistrationService.php.

Elgg\Router\RouteRegistrationService::resolveRouteParameters ( string  $name,
?\ElggEntity  $entity = null,
array  $parameters = [] 
)

Populates route parameters from entity properties.

Parameters
string$nameRoute name
\ElggEntity | null$entityEntity
array$parametersPreset parameters
Returns
array|false

Definition at line 212 of file RouteRegistrationService.php.

Elgg\Router\RouteRegistrationService::unregister ( string  $name)

Unregister a route by its name.

Parameters
string$nameName of the route
Returns
void

Definition at line 151 of file RouteRegistrationService.php.


The documentation for this class was generated from the following file: