One of the big changes on this new version of the framework is that everything is built around events. That's why the dispatchers in just an event listener waiting for the EVENT_DISPATCH
event.
When this event is triggered, it will be captured by DispatchListener
and this will lead to a few things. Let us see the following code snippet step-by-step to fully understand the dispatch flow:
$routeMatch = $e->getRouteMatch(); $controllerName = $routeMatch->getParam('controller', 'not-found'); $application = $e->getApplication(); $events = $application->getEventManager(); $controllerLoader = $application->getServiceManager()->get('ControllerLoader');
First the listener will retrieve information from the event itself, such as controller, route matched, and the application, and will try to load the controller. Notice that we are passing a second parameter to the
$routeMatch->getParam()
method; if for any reason the parameter does not exists on the route, this...