The bootstrap file is the entry point of your application (
index.php). It contains code in the global scope (and this is the only place, where that should be the case). In an outline, it does
- create a request object from the request
- create a response object according to the requested resource type
- ask the router for the responsible controller for the current request
- create the controller and call its main method, providing it with the request and respond objects (this often is called dispatching)
- echo the response
The request object is used to abstract from the web environment. In the end, it is just a data container (often a copy of
$_REQUEST) that allows you make subsequent calls to other controllers (see HMVC).
The response object is managing the output. You may have different response classes for XHTML, HTML5, PDF, JSON, ..., you_name_it with an identical interface. It is responsible for messaging warnings and errors to the user, too.
The router knows, which controller is assigned to which kind of URL. Given the request, it makes a decision about the controller and returns that to the bootstrap.
A dispatcher is used in different situations. You may think of it like a map and call thingest. For our case, the bootstrap file and the router together make up a dispatcher. A dispatcher is also used to map events to the various event handlers (plugins) and execute them (often using the Observer pattern).
A dispatcher mapping URLs to controllers and executing them dependend on the request is also called a front controller.
the event mechanism is used to decouple systems. You can for example create plugins that take influence on the result of the router. The only thing you have to do for that is to dispatch some events (eg.
onAfterRoute) in the routing method.
onBeforeRoute would get the request and could change it, before the router even looks at it;
onAfterRoute would be able to change the router's output. This is just a small example of whjat you can do with events.