composer require weew/router-routes-invoker-container-aware
This package is meant to be used in combination with weew/router. It's job is to invoke routes that have been successfully matched by the router. It uses the weew/container package to provide dependency injection.
Lets say you have successfully matched a route:
$route = $router->match(HttpRequestMethod::GET, new Url('foo-bar'));
Now you have to invoke the matched route:
$routesInvoker = new RoutesInvoker(new Container());
$response = $routesInvoker->invoke($route);
$response->send();
If response object implements either the IHttpResponseHolder
or IHttpResponseable
interface, invoker will extract the http response and return it instead.
Router returns null
whenever a route could not be matched. In this case, RoutesInvoker
will return a 404 HttpResponse
object instead.