How does a Dispatcher distribute incoming requests in PHP applications?

In PHP applications, a Dispatcher can distribute incoming requests by routing them to the appropriate controller based on the request URL. This can be achieved by using a routing system that maps URLs to specific controller actions. The Dispatcher parses the incoming request URL, determines the corresponding controller and action, and then calls the appropriate method to handle the request.

// Define routes
$routes = [
    '/' => 'HomeController@index',
    '/about' => 'AboutController@index',
    '/contact' => 'ContactController@index',
];

// Parse request URL
$requestUrl = $_SERVER['REQUEST_URI'];
$route = $routes[$requestUrl] ?? 'ErrorController@notFound';

// Extract controller and action
list($controllerName, $action) = explode('@', $route);

// Load controller and call action
$controller = new $controllerName();
$controller->$action();