Pluf : PHP 5 Framework   Download | Bug Tracking | Source | Documentation | Forum | Latest Changes | Home

Overview of the Dispatch Loop

If you have read the introduction, you know that Pluf is a MVT framework aka. Model, View, Template framework. People use to talk about MVC framework or Model, View, Controller. The fact is, I never understood where the controller is in those frameworks, the closest thing to a controller I can find in Pluf is the dispatch loop.

The dispatch loop is the framework logic to handle the user agent request, find the corresponding view based on the URL definition and returns the response to the user agent.

We could name it controller in the sens that it is controlling which view is called based on the requested URL. But, anyway, this is just plumbing and you do not care about it when using Pluf.

Pluf has one of the fastest dispatch loop so here is the dispatch loop sequence:

  1. From the query string, generate a request object.
  2. Load the list of middleware from the middleware_classes configuration variable.
  3. For each middleware, if the middleware has a process_request method, process the request. If the process_request method returns a response object, skip steps 4, 5 and 6.
  4. Match the query string against the URL definition to find the matching view.
  5. Execute the potential preconditions for the view.
  6. Execute the view which returns a response object.
  7. Reverse the list of middleware.
  8. For each middleware, if the middleware has a process_response method, process the response.
  9. Render the response to the agent.

The code of the dispatcher is really simple, just take a look at it.

Why So Fast?

  1. Very low level of nesting in the function calls.
  2. Duck typing to have the simplest possible objects.
  3. By default, the framework does nearly nothing:
    • Wrap the request in a simple object.
    • Find and execute the view (a simple method of a class).
    • Echo the response of the view back to the agent.
  4. No text, XML or YAML files for the configuration, all pure PHP.

Report issues in the documentation

If you find errors or issues in the documentation, report a bug. We will update the documentation accordingly.

Pluf © 2005-2008 Loïc d'Anterroches, supported by Céondo Ltd.