PHP Класс Webiny\Component\Router\Router

Наследование: 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
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
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.

Защищенные методы

Метод Описание
init ( ) Initialize based on singleton callback.
postSetConfig ( ) Post setConfig callback.

Приватные методы

Метод Описание
loadFromCache ( string $path ) : boolean | string Get a value from cache.
saveToCache ( string $path, string $value ) Save the given value into cache.

Описание методов

appendRoutes() публичный Метод

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 execute ( MatchedRoute $route ) : mixed
$route Webiny\Component\Router\Matcher\MatchedRoute
Результат mixed

generate() публичный Метод

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.
Результат string Generated url.

getCache() публичный Метод

Get the current cache parameter.
public getCache ( ) : boolean | CacheStorage
Результат boolean | Webiny\Component\Cache\CacheStorage

getRouteCollection() публичный статический Метод

public static getRouteCollection ( ) : RouteCollection
Результат Webiny\Component\Router\Route\RouteCollection

init() защищенный Метод

Initialize based on singleton callback.
protected init ( )

initialize() публичный Метод

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

match() публичный Метод

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.
Результат Webiny\Component\Router\Matcher\MatchedRoute | boolean MatchedRoute instance is returned if url was matched. Otherwise false is returned.

postSetConfig() защищенный статический Метод

Post setConfig callback.
protected static postSetConfig ( )

prependRoutes() публичный Метод

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() публичный Метод

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() публичный Метод

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