Skip to content

Routing component designed for ease of use and speed, for Trident.

License

Notifications You must be signed in to change notification settings

strident/Router

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#Router Build Status Coverage Code Climate

Routing component designed for ease of use and speed. Built for Trident.

##Installation

Installation is available via Composer. Add the package to your composer.json:

$ composer require strident/router ~2.0

##Usage

The Strident Router package is flexible and allows you to swap out components to extend it easier. To create a Router, do the following:

use Strident\Router\RouteFactory;
use Strident\Router\RouteMatcher;
use Strident\Router\Router;

$factory = new RouteFactory();
$matcher = new RouteMatcher();
$router  = new Router($factory, $matcher);

From there, you can define routes like so:

$router->route("route_name", "/route/path/{parameter}/{placeholders}")
    ->target("GET", "FooController::getAction")
    ->target("POST", "FooController::postAction")
;

The route() method of the Router returns the instance of a the created Route. The Route can then define it's targets for specific HTTP methods by using the target() method.

To dispatch the current request in the Router, use the dispatch() method of the Router.

$matched = $router->dispatch("GET", "/route/path/1/2");

The return value of dispatch() is an array containing information about the matched route. This includes the name of the route, the request method, the path, and the parameters (by name, and index).

About

Routing component designed for ease of use and speed, for Trident.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages