The most important pre-requisite needed to use objective-php/router is PHP7.
If you don't have it installed yet, please take a look at Official PHP website and read instruction about PHP7 installation on your development machine.
The easiest way to include a project with Objective PHP is to use composer's "require" feature.
The following command assumes composer is available in your current PATH:
composer require objective-php/routerA meta router is a simple middleware on which actual routers can be registered. When executed, this middleware will loop on all registered routers, and stop looping as soon as one of the registered routers matches a route.
$metaRouter = new MetaRouter();
$metaRouter->register(new CustomRouter);Routers have to implement ObjectivePHP\Router\RouterInterface to be allowed to get registered on the meta router.
This simple interface requires routers to implement route(ServerRequestInterface $request, RequestHandlerInterface $handler): RoutingResult and url($route, $params) methods, the first one to test current request against declared routes, the latter to build a URL from a route name and params.
Method route(ServerRequestInterface $request, RequestHandlerInterface $handler): RoutingResult is expected to return an instance of RoutingResult while url($route, $params) has to return a string.
The MetaRouter knows when a Router actually matched a route if the didMatch() method of the RoutingResult object returns true.
A RoutingResult that did match is able to return a MatchedRoute instance, that will let know the rest of the application about what route matched, what action this means, what params comes with and what Router did match the route.
Using several routers can help dealing with performance issue, since it allows to use advanced routes when needed only. Please note that the later a Router is registered, the higher is its priority in the routing loop.