About : libVSC [4]
One of the most important components of the libVSC stack, and the one that the MVC pattern is based on are the URL mappings objects. Their ramifications extend in the whole presentation layer, being the main state exchange mechanism between the separate View, Controller and Processor objects.
A first advantage over other similar URL mapping ideas, is the usage of plain regular expressions instead of framework specific grammars.
This way we can take advantage of the sub-pattern mechanism to create path specific URL variables, which are latter available implicitly in the corresponding Processor by defining a protected property called $aLocalVars. The reasoning behind this this is that ideally there will be a one-to-one relationship between URLs and Processors, and at the development time of the later, we will know what parameters we expect. This permits us to have unnamed variables in the URL, but named in the Processor. If you will, this is syntactic sugar for ordered variables, as it relies on the regular expression matching order.
One way to take advantage of this is through the global vscHttpRequest wrapper object, as they get artificially injected into it, and the other, is through the vscProcessorA::getVar('var_name'). See an example below:
// this would match a url like http://localhost/something_or_other/123/
$oModuleMap = $this->map ('/(.+)/(d+)/?Z', 'application/processors/mainprocessor.class.php');
/**
*
* In the Main Processor Class we have the following protected member
* which gives some names to the variables in the URL regular expression.
*
*/
class MainProcessor extends vscProcessorA {
protected $aLocalVars = array (
'name' => null,
'number' => null
);
....
public function test(vscHttpRequest $oRequest) {
// we can get the values as
$this->getVar ('name'); // returns 'something_or_other'
$oRequest->getVar ('number'); // returns 123
/* with the caveat that if there's a CGPS variable with the same name, it will override the one from the URL */
}
}
- [ permalink ]

Today was pretty bad. It was also a Sunday.