Serve folder content using PHP route (SSI) (dynamic includes)
Thanks for your example.  It kind of validates my concern on how you are thinking about routing.

I like that you are thinking about the routing problem and trying to move away from legacy ways of having each URL going directly to a physical file for processing.  I would however challenge you to take this a step further, as what you have now really only gets partially away from the legacy web application, a script-for-every controller/action line of thinking, in that you still have scripts that you are redirecting to rather then using your router to instantiate an appropriate controller object in order to satisfy the request.

Most modern frameworks that utilize a front-controller routing pattern like you are trying to achieve have gone the route of auto-loading a controller (ideally auto-loaded in a PSR-4 compliant way) to handle the request passed to it by the router, not having the router just include some specific script file.

So you might see a pattern like:

$controller = Router::getController($request);
$controller-&gt;execute();


That's it.  The router is basically used on a single line in your main execution path.

Here all the information about the HTTP request (including URI) could be injected into a controller object, which then takes over application control.  In this case, the router needs to know absolutely nothing about what dependencies that controller has. It typically just needs to know how to map the 
 request (oftentimes just the first segment of the URI) to a controller to be instantiated and hand off the request information and application control over to the controller.

In your case, your router actually does the following:


It parses the request (something better handled in its own class such that a request object can be passed around as a dependency to consuming code).
It uses information from the request to map the request to an action to be performed (the only thing a router should truly do).
It has to understand where dependencies for a particular action are located in the filesystem.
It actually loads/executes those dependencies.


If you are striving to adhere to the single responsibility principle, you will quickly understand that the router has too much responsibility in your application. It should own just routing the request to an appropriate controller and then get out of the way.