Centum\Router
MVC web apps can be created using Centum\Router\Router
.
Centum\Router\Router(
Centum\Interfaces\Container\ContainerInterface $container
);
Centum\Router\Router
implements Centum\Interfaces\Router\RouterInterface
.
The Router is the central component that connects incoming HTTP requests to the appropriate controller logic, and returns a HTTP response.
Essentially, its job is to convert a Centum\Interfaces\Http\RequestInterface
object into a Centum\Interfaces\Http\ResponseInterface
object:
$response = $router->handle($request);
How It Works
- The Router extracts the Request’s URI and HTTP method.
- It then iterates through the registered Routes until it finds a matching route.
- Once a match is found, the Router instantiates the corresponding Controller, injects any required dependencies via the Container, and executes the Controller’s action method.
- The Controller then returns a Response object, which the Router passes back to the client.