PHP Class PHPRouter\Router

显示文件 Open project: dannyvankooten/php-router Class Usage Examples

Public Methods

Method Description
__construct ( PHPRouter\RouteCollection $collection )
generate ( $routeName, array $params = [] ) : string Reverse route a named route
match ( string $requestUrl, string $requestMethod = 'GET' ) : boolean | Route Match given request _url and request method and see if a route has been defined for it If so, return route's target If called multiple times
matchCurrentRequest ( ) Matches the current request against mapped routes
parseConfig ( array $config ) : Router Create routes by array, and return a Router object
setBasePath ( $basePath ) Set the base _url - gets prepended to all route _url's.

Method Details

__construct() public method

public __construct ( PHPRouter\RouteCollection $collection )
$collection PHPRouter\RouteCollection

generate() public method

Reverse route a named route
public generate ( $routeName, array $params = [] ) : string
$routeName
$params array Optional array of parameters to use in URL
return string The url to the route

match() public method

Match given request _url and request method and see if a route has been defined for it If so, return route's target If called multiple times
public match ( string $requestUrl, string $requestMethod = 'GET' ) : boolean | Route
$requestUrl string
$requestMethod string
return boolean | Route

matchCurrentRequest() public method

Matches the current request against mapped routes
public matchCurrentRequest ( )

parseConfig() public static method

Create routes by array, and return a Router object
public static parseConfig ( array $config ) : Router
$config array provide by Config::loadFromFile()
return Router

setBasePath() public method

Set the base _url - gets prepended to all route _url's.
public setBasePath ( $basePath )
$basePath