PHP Class Aerys\Router

Inheritance: implements aerys\Bootable, implements aerys\Middleware, implements SplObserver
Show file Open project: amphp/aerys

Public Methods

Method Description
__call ( string $method, array $args ) : Router Allow shortcut route registration using the called method name as the HTTP method verb
__invoke ( aerys\Request $request, aerys\Response $response ) Route a request
boot ( Server $server, Psr\Log\LoggerInterface $logger )
do ( InternalRequest $ireq ) Execute router middleware functionality
monitor ( ) : array
prefix ( string $prefix ) : self Prefix all the (already defined) routes with a given prefix
route ( string $method, string $uri, $actions ) : Router Define an application route
setOption ( string $key, mixed $value ) Set a router option
update ( Server $server ) : Promise React to server state changes
use ( callable | aerys\Middleware | aerys\Bootable | aerys\Monitor $action ) : self Import a router or attach a callable, Middleware or Bootable.

Private Methods

Method Description
bootRouteTarget ( $actions ) : array
buildRouter ( RouteCollector $rc, Server $server )
cacheDispatchResult ( string $toMatch, array $routeArgs, array $action )

Method Details

__call() public method

HTTP method verbs -- though case-sensitive -- are used in all-caps for most applications. Shortcut method verbs will automatically be changed to all-caps. Applications wishing to define case-sensitive methods should use Router::route() to specify the desired method directly.
public __call ( string $method, array $args ) : Router
$method string
$args array
return Router

__invoke() public method

Route a request
public __invoke ( aerys\Request $request, aerys\Response $response )
$request aerys\Request
$response aerys\Response

boot() public method

public boot ( Server $server, Psr\Log\LoggerInterface $logger )
$server Server
$logger Psr\Log\LoggerInterface

do() public method

Execute router middleware functionality
public do ( InternalRequest $ireq )
$ireq InternalRequest

monitor() public method

public monitor ( ) : array
return array

prefix() public method

Prefix all the (already defined) routes with a given prefix
public prefix ( string $prefix ) : self
$prefix string
return self

route() public method

The variadic ...$actions argument allows applications to specify multiple separate handlers for a given route URI. When matched these action callables will be invoked in order until one starts a response. If the resulting action fails to send a response the end result is a 404. Matched URI route arguments are made available to action callables as an array in the following Request property: $request->locals->routeArgs array. Route URIs ending in "/?" (without the quotes) allow a URI match with or without the trailing slash. Temporary redirects are used to redirect to the canonical URI (with a trailing slash) to avoid search engine duplicate content penalties.
public route ( string $method, string $uri, $actions ) : Router
$method string The HTTP method verb for which this route applies
$uri string The string URI
$actions The action(s) to invoke upon matching this route
return Router

setOption() public method

Set a router option
public setOption ( string $key, mixed $value )
$key string
$value mixed

update() public method

Here we generate our dispatcher when the server notifies us that it is ready to start (Server::STARTING).
public update ( Server $server ) : Promise
$server Server
return Promise

use() public method

Router imports do *not* import the options
public use ( callable | aerys\Middleware | aerys\Bootable | aerys\Monitor $action ) : self
$action callable | aerys\Middleware | aerys\Bootable | aerys\Monitor
return self