4. How a Request is Processed

If you call an URL that is handled by pub/index.php, Agavi will bootstrap the specified (or default) Environment and then create an instance of the specified (or default) Context (this instantiation sets up all of the core components of the framework). Finally, the request is dispatched from the Context's Controller instance.

The dispatch method first executes the routing (if enabled) to determine the Module/Action that are to be executed. The routing returns an Execution Container for the first action. Then, a filter chain containing all Global Filters is created, and the DispatchFilter is added to that chain as the last element. Each filter will be called in nested sequence, with the last filter being the DispatchFilter, which executes the first Execution Container with the requested Action. After that, the control passes back through the filters to the dispatch method, which sends the Response contents and exits. Filters are given the global Response as a parameter to work with, so they can modify content, send Cookies and so on.

When an Execution Container is run, Agavi does some checks to determine if the requested Module/Action exists, if the Module the Action belongs to is enabled and so on. Then, a filter chain is created, with the first filter being the Security Filter if security is enabled. This filter will forward unauthenticated users to the default "Login Action" if a requested Action requires authentication, and also prevent access of Actions an user doesn't have sufficient credentials for by forwarding to the default "Secure Action". After that, the Action Filters are added to the chain, followed by the Action Filters defined by the Action's Module. The last filter in the chain is the Execution Filter. Again, each filter in the chain is called and may do modifications to the Response instance, which is a new one for each Action that is processed and will be merged to the global Response by the Controller once control returns to the forward method.

The Execution Filter, once reached, will handle Validation, run the Action (or skip execution if the Action doesn't serve the Request method), determine the View to execute and then execute the View and, after that, start the rendering of the output.