All requests to a FlowBasis site are routed through the route.php file (via mod_rewrite) which sets up the FlowBasis environment and hands off the request to the routing manager (FlowBasis_Routing_RoutingManager). The routing manager finds the appropriate request handler for the request URI and passes off the processing to it.
The three basic types of request handlers are:
- Basic file handler
- Page request handler
- Site path request handler (extensible handler model used by modules)
The basic file handler is for requests that map to a static file (html, png, gif, javascript, css, etc) and just returns the file contents.
The page request handler kicks off the page processing model (see a future post for details on that).
The site path request handler system is used by modules (blog, wiki, etc) to register for requests to particular URIs. Custom site path request handlers can also be created by developers interested in doing something completely different with a request.
The process of selecting the appropriate request handler goes through a series of steps, which essentially boils down to picking the request handler that is interested in the longest prefix of the request uri.
Consider the following scenario, where a user makes a request to get http://test.calevinci.com/flowbasis/someblog/img/hello.png.
Let's assume the following:
- FlowBasis is installed in /var/www/flowbasis (and test.calevinci.com maps to /var/www). This means that /someblog/img/hello.png is the site path. /flowbasis is the request URI root.
- The file /var/www/flowbasis/pages/someblog/img/hello.png exists.
- A blog module is set up and registered with the site path someblog.
The routing manager will look in several places for possible matches. It will look in the pages and core-pages directories for files and pages (core-pages is for the FlowBasis infrastructure, and sites built on FlowBasis should use pages). The routing manager will also look at registered site path handlers.
The basic file request handler will want to process the request with a matching site path of /someblog/img/hello.png. The module site path handler will want to process the request with a matching site path of /someblog (with an extended site path of /img/hello.png). The basic file request handler has a longer matching site path, so it wil get to process the request.
Now's let assume the user makes a request to get http://test.calevinci.com/flowbasis/someblog/tags/trees.
No file exists at either /var/www/flowbasis/core-pages/someblog/tags/trees or /var/www/flowbasis/pages/someblog/tags/trees, so the module request handler will get the request with a matching site path of /someblog and can map the extended site path of /tags/trees to a page with recent posts tagged with trees.



Add Comment