Elgg  Version master
Public Member Functions | Protected Attributes | List of all members
Elgg\Router\RouteRegistrationService Class Reference

Route registration service. More...

Public Member Functions

 __construct (EventsService $events, RouteCollection $routes, 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...
 

Protected Attributes

 $events
 
 $routes
 
 $generator
 

Detailed Description

Route registration service.

Definition at line 16 of file RouteRegistrationService.php.

Constructor & Destructor Documentation

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

Constructor.

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

Definition at line 42 of file RouteRegistrationService.php.

Member Function Documentation

Elgg\Router\RouteRegistrationService::all ( )

Get all registered routes.

Returns
Route[]

Definition at line 187 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 199 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 179 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
Returns
Route
Exceptions
InvalidArgumentException

Definition at line 74 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 229 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 168 of file RouteRegistrationService.php.

Member Data Documentation

Elgg\Router\RouteRegistrationService::$events
protected

Definition at line 23 of file RouteRegistrationService.php.

Elgg\Router\RouteRegistrationService::$generator
protected

Definition at line 33 of file RouteRegistrationService.php.

Elgg\Router\RouteRegistrationService::$routes
protected

Definition at line 28 of file RouteRegistrationService.php.


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