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

Route registration service. More...

Public Member Functions

 __construct (PluginHooksService $hooks, LoggerInterface $logger, RouteCollection $routes, UrlGenerator $generator)
 Constructor. More...
 
 register ($name, array $params=[])
 Register a new route. More...
 
 unregister ($name)
 Unregister a route by its name. More...
 
 get ($name)
 Get route config from its name. More...
 
 all ()
 Get all registered routes. More...
 
 generateUrl ($name, array $parameters=[])
 Generate a absolute URL for a named route. More...
 
 resolveRouteParameters ($name, ElggEntity $entity=null, array $parameters=[])
 Populates route parameters from entity properties. More...
 
 registerPageHandler ($identifier, $function)
 Register a function that gets called when the first part of a URL is equal to the identifier. More...
 
 unregisterPageHandler ($identifier)
 Unregister a page handler for an identifier. More...
 

Protected Attributes

 $hooks
 
 $routes
 
 $generator
 

Detailed Description

Route registration service.

Definition at line 19 of file RouteRegistrationService.php.

Constructor & Destructor Documentation

Elgg\Router\RouteRegistrationService::__construct ( PluginHooksService  $hooks,
LoggerInterface  $logger,
RouteCollection  $routes,
UrlGenerator  $generator 
)

Constructor.

Parameters
PluginHooksService$hooksHook service
LoggerInterface$loggerLogger
RouteCollection$routesRoute collection
UrlGenerator$generatorURL Generator

Definition at line 46 of file RouteRegistrationService.php.

Member Function Documentation

Elgg\Router\RouteRegistrationService::all ( )

Get all registered routes.

Returns
Route[]

Definition at line 183 of file RouteRegistrationService.php.

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

Generate a absolute URL for a named route.

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

Definition at line 195 of file RouteRegistrationService.php.

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

Get route config from its name.

Parameters
string$nameRoute name
Returns
Route|null

Definition at line 175 of file RouteRegistrationService.php.

Elgg\Router\RouteRegistrationService::register (   $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
InvalidParameterException

Definition at line 80 of file RouteRegistrationService.php.

Elgg\Router\RouteRegistrationService::registerPageHandler (   $identifier,
  $function 
)

Register a function that gets called when the first part of a URL is equal to the identifier.

Parameters
string$identifierThe page type to handle
callable$functionYour function name
Returns
bool Depending on success
Exceptions
InvalidParameterException

Definition at line 267 of file RouteRegistrationService.php.

Elgg\Router\RouteRegistrationService::resolveRouteParameters (   $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 217 of file RouteRegistrationService.php.

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

Unregister a route by its name.

Parameters
string$nameName of the route
Returns
void

Definition at line 164 of file RouteRegistrationService.php.

Elgg\Router\RouteRegistrationService::unregisterPageHandler (   $identifier)

Unregister a page handler for an identifier.

Parameters
string$identifierThe page type identifier
Returns
void

Definition at line 294 of file RouteRegistrationService.php.

Member Data Documentation

Elgg\Router\RouteRegistrationService::$generator
protected

Definition at line 36 of file RouteRegistrationService.php.

Elgg\Router\RouteRegistrationService::$hooks
protected

Definition at line 26 of file RouteRegistrationService.php.

Elgg\Router\RouteRegistrationService::$routes
protected

Definition at line 31 of file RouteRegistrationService.php.


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