Overview of Application Execution Flow
Agavi handles user requests and organizes the execution flow of an application. This chapter gives a brief overview what happens when a web request lands in the Agavi dispatcher. Understanding Agavi architecture is key to write efficient and durable applications.
Request Dispatching
The first stage of execution is called the dispatch stage. The dispatcher script - typically index.php for web applications — boots the framework and commands the Agavi controller to dispatch the web request.
The controller looks up the request using the routing map to find out the identity of the action that should be executed. If no route matches, or the specified action can not be found, a substitute system action is executed instead to indicate an error condition.
When the requested action is discovered, the controller creates a special envelope object, called the execution container. Actions and views execute inside the execution container which isolates them from the outside world and provides them with shared space.
As soon as the initial action is loaded into the execution container, the controller creates the global filter chain (FC) which governs the execution of actions. The execution container is fed into the filter chain. One of the filters in the chain executes the container, and the resulting response is returned to the outside world — most often as an HTTP response.
Running the Execution Container
The execution container encapsulates an action-view chain. It sets up the environment, runs both the action and one of its views and then invokes the rendering mechanism to apply templates if needed. The output of the view is collected and returned.
Internally, actions/views are executed inside another filter chain, which is called the "actions" filter chain. Unlike the global FC which is executed once per request, the actions FC is executed once for every action. Thus, filters of the "actions" FC would be applied to every action ever called, and the ones in the "global" chain will be applied globally.
The action itself is invoked through the Execution Filter, which is the last filter in the "actions" chain. Output caching is performed at this stage.
If the action requests input validation, the request data is checked by Agavi according to the rules laid out by developers. If the data does not conform to the specified constraints, execution of the action is aborted and error handling procedure begins instead.
After the validation and caching checks are finished, the action will be executed. This is where your code comes into play: the action interacts with models and tells Agavi which view should be executed.
The appointed view's respectable executeXXX() method is called. The view sets up the configuration for output rendering and prepares any data needed by the rendering mechanism, again querying models if needed.
After the view has finished executing, the rendering mechanism executes the rendering procedure. This procedure may involve calling other actions, which in turn get their own Execution Containers and action filter chains. Alternatively, a view may choose to skip the rendering step and compose the response itself (for example, encoding API response into JSON would not require any sort of external templates.)
The resulting output is collected and sent back to the client.

