php - MVC routing using Symfony routing

one text

Solution:

In your front controller you are just defining the routes, but not actually processing the request, matching it to a controller or invoking it.

There is a section on this topic in the manual, it uses more symfony components, but can be of help.

You'd have to determine the requested route directly from PATH_INFO instead of using the HttpFoundation component, and then try to match the request to a route.

Here is a very crude implementation:

$collection = new RouteCollection();
$collection->add('index', new Route('/', array(
    '_controller' => [IndexController::class, 'IndexAction']
)));

$matcher = new UrlMatcher($collection, new RequestContext());

// Matcher will throw an exception if no route found
$match = $matcher->match($_SERVER['PATH_INFO']);

// If the code reaches this point, a route was found, extract the corresponding controller
$controllerClass = $match['_controller'][0];
$controllerAction = $match['_controller'][1];

// Instance the controller
$controller = new $controllerClass();
// Execute it
call_user_func([$controller, $controllerAction]);

Source