PHP Class Webiny\Component\Router\Router

Inheritance: use trait Webiny\Component\StdLib\StdLibTrait, use trait Webiny\Component\ServiceManager\ServiceManagerTrait, use trait Webiny\Component\StdLib\SingletonTrait, use trait Webiny\Component\Cache\CacheTrait, use trait Webiny\Component\StdLib\ComponentTrait
Datei anzeigen Open project: Webiny/Framework Class Usage Examples

Public Methods

Method Description
appendRoutes ( ConfigObject $routes ) Adds a route to the end of the current route collection.
execute ( MatchedRoute $route ) : mixed Execute callback from MatchedRoute and return result.
Required callback structure is: Callback: Class: \Your\Class Method: handle Static: true // (Optional, "false" by default)
generate ( string $name, array $parameters = [], boolean $absolute = true ) : string Generate a url from a route.
getCache ( ) : boolean | CacheStorage Get the current cache parameter.
getRouteCollection ( ) : RouteCollection
initialize ( ) Initializes the Route by reading the default config, registering routes and creating necessary object instances.
match ( string | UrlObject $url ) : MatchedRoute | boolean Tries to match the given url against current RouteCollection.
prependRoutes ( ConfigObject $routes ) Adds a route to the beginning of the current route collection.
setCache ( boolean | CacheStorage | string $cache ) Sets the cache parameter.
setRouteCollection ( RouteCollection $routeCollection ) Overwrite the current route collection with the defined one.

Protected Methods

Method Description
init ( ) Initialize based on singleton callback.
postSetConfig ( ) Post setConfig callback.

Private Methods

Method Description
loadFromCache ( string $path ) : boolean | string Get a value from cache.
saveToCache ( string $path, string $value ) Save the given value into cache.

Method Details

appendRoutes() public method

Adds a route to the end of the current route collection.
public appendRoutes ( ConfigObject $routes )
$routes Webiny\Component\Config\ConfigObject An instance of ConfigObject holding the routes.

execute() public method

public execute ( MatchedRoute $route ) : mixed
$route Webiny\Component\Router\Matcher\MatchedRoute
return mixed

generate() public method

Generate a url from a route.
public generate ( string $name, array $parameters = [], boolean $absolute = true ) : string
$name string Name of the Route.
$parameters array List of parameters that need to be replaced within the Route path.
$absolute boolean Do you want to get the absolute url or relative. Default is absolute.
return string Generated url.

getCache() public method

Get the current cache parameter.
public getCache ( ) : boolean | CacheStorage
return boolean | Webiny\Component\Cache\CacheStorage

getRouteCollection() public static method

public static getRouteCollection ( ) : RouteCollection
return Webiny\Component\Router\Route\RouteCollection

init() protected method

Initialize based on singleton callback.
protected init ( )

initialize() public method

Note: this method is called automatically when you do Router::setConfig().
public initialize ( )

match() public method

Tries to match the given url against current RouteCollection.
public match ( string | UrlObject $url ) : MatchedRoute | boolean
$url string | Webiny\Component\StdLib\StdObject\UrlObject\UrlObject Url to match.
return Webiny\Component\Router\Matcher\MatchedRoute | boolean MatchedRoute instance is returned if url was matched. Otherwise false is returned.

postSetConfig() protected static method

Post setConfig callback.
protected static postSetConfig ( )

prependRoutes() public method

Adds a route to the beginning of the current route collection.
public prependRoutes ( ConfigObject $routes )
$routes Webiny\Component\Config\ConfigObject An instance of ConfigObject holding the routes.

setCache() public method

If you don't want the Router to cache stuff, pass boolean false.
public setCache ( boolean | CacheStorage | string $cache )
$cache boolean | Webiny\Component\Cache\CacheStorage | string Cache object, boolean false or name of a registered Cache service.

setRouteCollection() public method

Overwrite the current route collection with the defined one.
public setRouteCollection ( RouteCollection $routeCollection )
$routeCollection Webiny\Component\Router\Route\RouteCollection RouteCollection to install.