PHP Class System\Router

Show file Open project: rwarasaurus/nano Class Usage Examples

Public Properties

Property Type Description
$actions array Actions to call before and after routes
$method str The current request method
$not_found array | closure Actions to call on not matched routes
$patterns array Array of regex patterns to subsitute in defined routes
$routes array The defined routes set by the app
$uri str The current URI

Public Methods

Method Description
__construct ( $method, $uri ) Create a new instance of the Router class and import app routes from a folder or a single routes.php file
create ( ) : object Create a new instance of the Router class for chaining
dispatch ( ) : object Match the request with a route and run it
match ( ) : object Try and match the request method and uri with defined routes
routes ( ) : array Gets array of request method routes

Method Details

__construct() public method

Create a new instance of the Router class and import app routes from a folder or a single routes.php file
public __construct ( $method, $uri )

create() public static method

Create a new instance of the Router class for chaining
public static create ( ) : object
return object

dispatch() public method

Match the request with a route and run it
public dispatch ( ) : object
return object Response instance

match() public method

Try and match the request method and uri with defined routes
public match ( ) : object
return object Return a instance of a Route

routes() public method

Gets array of request method routes
public routes ( ) : array
return array

Property Details

$actions public static property

Actions to call before and after routes
public static array $actions
return array

$method public property

The current request method
public str $method
return str

$not_found public static property

Actions to call on not matched routes
public static array|closure $not_found
return array | closure

$patterns public static property

Array of regex patterns to subsitute in defined routes
public static array $patterns
return array

$routes public static property

The defined routes set by the app
public static array $routes
return array

$uri public property

The current URI
public str $uri
return str