I\'m attempting to use the FastRoute routing library and can\'t get the simple usage example to work.
Here is the basic usage example found on the GitHub page:
$r->addRoute(['GET','POST','PUT'], '/test', 'TestClass/testMethod');
Then in your dispatch method:
$routeInfo = $router->dispatch($httpMethod, $uri)
switch($routeInfo[0]) {
case FastRoute\Dispatcher::FOUND:
$handler = $routeInfo[1];
$vars = $routeInfor[2];
list($class, $method) = explode('/',$handler,2);
$controller = $container->build()->get($class);
$controller->{$method}(...array_values($vars));
break;
}
Class and method of course could be invoked by call_user_func(), but as I wanted the router to be more abstract and placed outside in the root directory I decided to use DI container, which is brilliant.