About : libVSC [2.1]
In the light of the last article, I'll try to do a followup in which I'm going to talk about the folder structure of a web application based on libVSC.
The application folder structure.
htdocs/
static/
style.css
index.php
lib/
application/
processors/
lformprocessor.class.php
domain/
models/
userpassmodel.class.php
presentation/
res/
map.php
login/
config/
map.php
application/
processors/
loginprocessor.class.php
logoutprocessor.class.php
changepasswordprocessor.class.php
domain/
models/
loginmodel.class.php
changepasswordmodel.class.php
templates/
html5/
logintpl.php
logouttpl.php
changepasswordtpl.php
json/
logintpl.php
changepasswordtpl.php
As an example I'll use a very basic authentication module, and I'll describe a bit the different sections of the code.
Beside the two folders I have already stressed about in the previous post, at the top level we have the web server root, the htdocs folder. The default request processor of libVSC deals with URL rewritten paths, so we have only one point of entry, the index.php file. The static folder from here, is off course publicly accessible and can contain static resources.
Coming back to the lib/ and res/ folders, in the case of the application, they have slightly different uses. The libraries refer to generic objects used throughout the application and the resources can follow either the structure of libVSC (in the case of simpler applications) or have different modules as direct subfolders (as in my example) and then the aforementioned structure.
The map.php files contain the logic of URL mapping of our application. Here's an example:
// res/map.php
// mapping the http://app.local/login/ to the login module
$oMap = $this->map ('login/', LOCAL_RES_PATH . 'login/config/map.php');
// the res/login/map.php
// mapping url http://app.local/login/ to the login processor
$oMap = $this->map ('$' ,$sCurPath . 'application/processors/loginprocessor.class.php');
$oMap->setTemplate ('logintpl.php');
// mapping url http://app.local/login/logout/ to the logout processor
$oMap = $this->map ('logout/+$' ,$sCurPath . 'application/processors/logoutprocessor.class.php');
$oMap->setTemplate ('logouttpl.php');
// mapping url http://app.local/login/changepw/ to the change password processor
$oMap = $this->map ('changepw/+$' ,$sCurPath . 'application/processors/changepasswordprocessor.class.php');
$oMap->setTemplate ('changepasswordtpl.php');
// 404 controller - matching everything else to the standard 404 processor
$oMap = $this->map ('(.+)$', VSC_RES_PATH . 'application/processors/vscerrorprocessor.class.php');
$oMap->setTemplatePath(VSC_RES_PATH . 'templates');
$oMap->setTemplate ('404.php');
However the nice part of import() is that you can use whatever structure suits you and your project, libVSC not being dependent on a rigid naming scheme or folder structure. The only requirements are that classes are to be found in files having the .class.php suffix and the name lowercase of the class name.
- [ permalink ]
