use Dispatcher\DispatcherInstance; // Create a new dispatcher instance $dispatcher = new DispatcherInstance(); // Define routes $dispatcher->addRoute('/', 'home_controller@index'); $dispatcher->addRoute('/about', 'about_controller@index'); // Dispatch request $dispatcher->dispatch($_SERVER['REQUEST_URI']);
use Dispatcher\DispatcherInstance; // Create a new dispatcher instance $dispatcher = new DispatcherInstance(); // Add middleware $dispatcher->addMiddleware(function ($request, $response, $next) { // Perform some action before the controller $response->write('Before controllerIn this example, we use the `addMiddleware` method to add middleware that executes before and after the controller. The `$next` function is used to pass control to the next middleware or controller. The package library for PHP Dispatcher Instance is `dispatcher/dispatcher`.
'); $next($request, $response); // Perform some action after the controller $response->write('After controller'); }); // Dispatch request $dispatcher->dispatch($_SERVER['REQUEST_URI']);