In this part I will explain how ProBase hands a page-request over to the right function.
ProBase, Procurios' application framework, uses the Front Page Controller pattern. That means that all page requests are handled by a single point of entry, the Core.
When the Core has established the module for which the request is intended, it sends the request to the ModuleIndex of that module. This index selects the controller class that handles the request.
The ModuleIndex uses a simple array map to map url paths to controller functions. Here is an example of such a map:
class RelationIndex extends ModuleIndex
static function root()
'' => array('RelationController', 'relationOverview'),
'add' => array('RelationController', 'add'),
'#int#' => array('RelationController', 'view'),
'#int#/edit' => array('RelationController', 'edit'),
'bulk/search' => array('RelationMigrationController', 'bulkSearch'),
'bulk/search/#string#' => array('RelationMigrationController', 'bulkSearch'),
'bulk/search/#string#/#path#' => array('RelationMigrationController', 'bulkSearch'),
When the Core processes a path like this
it first determines the module from the first section of path: relation. The module is mod_relation.
The remainder of the path
is passed to the ModuleIndex of mod_relation. This ModuleIndex then goes through all the path pattern in the url map and tries to match them against the offered path. This is done with regular expression matching. But since the patterns in the map contain user-friendly tokens like #int#, these need to be replaced first by regexp expressions, like (\d+).
The example url matches the pattern '#int#/edit' and the number 8119 matches the token #int#. The ModuleIndex then calls the static function RelationController::edit and passes the token values that were found (in this case just 8119) as distinct parameters.
This simple scheme ensures that just well-formed urls are passed to the module. It also does some minimal type checking of the arguments in the url. For example, it is not possible to pass a string value to the edit function, because it will not match the #int#. This helps to reduce application errors and hacker attacks.
Header photo: Library interior