Abstract mvcDistributorBase class. Provides base functionality for the MVC system. This is the main Front Controller class that will dispatch a request to an appropriate controller within the site hierarchy.
The main functions of this class are to prepare the request, create or continue a session, determine the request type (or context if you prefer) and to then dispatch the request to the most appropriate controller as defined in the controllerMap XML config file.
A concrete implementation is required of the dispatch() method.
The basic process flow of mvcDistributorBase is as follows:
Scorpio is designed to work with multiple sites with a shared code-base. Each site can inherit from a base set of functionality with specific components being overridden. Which site to use is determined by mvcDistributorBase::resolveSitePath(). This method will hunt through the /websites folder attempting to match the request domain to a folder entry, first by specific domain e.g. www.madagasgar.com and then by component separated by each . e.g. madagasgar.com. In this way, all requests for pages can be directed to a domain, and then content switched on a sub-domain. For example: all requests to wap.madagasgar.com would be serviced using the madagasgar.com site, but wap. would result in WAP content being returned to the user.
Once resolved, the site config.xml file is loaded into the mvcSiteConfig object. This contains theme and custom library information. This is processed before the request as the specific session and view classes must be pre-loaded before dispatch can continue.
For request routing please see mvcControllerMapper.
Some additional parameters of the distributor can be configured by defining constants before the base class is included. These constants control where the site folder is, what the controllers folder is called, the name of the custom libraries folder, views and the default action to be fired when no action can be located in the request e.g. launching /home or /index when the request is simply /.
The loading of the various controllers is handled via a custom spl_autoload class mvcAutoload. This will pre-load and fetch controllers, models and views for the request based on the site controllerMap.xml file.
The distributor has several options that can be specified during instantiation:
mvcDistributorBase::OPTION_DISTRIBUTOR_WEBSITES_FOLDER The full path to the main websites folder, defaults to /websites.
mvcDistributorBase::OPTION_DISTRIBUTOR_WEBSITE_CONTROLLERS_FOLDER The name of the controllers folder, defaults to "controllers". This is where the controllers can be located.
mvcDistributorBase::OPTION_DISTRIBUTOR_WEBSITE_DEFAULT_CONTROLLER The name of the default controller, defaults to "home". If no request is specified then this controller will be used.
mvcDistributorBase::OPTION_DISTRIBUTOR_WEBSITE_LIBRARIES_FOLDER The name of the libraries folder, defaults to "libraries". The libraries folder contains the mvcController, mvcSession and mvcView classes along with other custom classes for the site.
mvcDistributorBase::OPTION_DISTRIBUTOR_WEBSITE_VIEWS_FOLDER The name of the views folder, defaults to "views". The views are the templates to be used for the site.
mvcDistributorBase::OPTION_DISTRIBUTOR_ERROR_CONTROLLER Name of class implementing mvcErrorInterface, defaults to mvcErrorController.
public __construct($inRequest, [$inOptions = array()])
Returns new mvcDistributorBase instance
Resets the object to defaults
Initialises the distributor prior to request dispatch
public abstract dispatch()
Routes the request launching any controller that is needed
Finds the site path in the websites folder based on the server name
Parses the request URI for the controller, returning controllerMap object
Loads the controller from the request controllerMap
Returns the mvcRequest object
Set $_MvcRequest to $inMvcRequest
Returns the mvcResponse object, creating a default if not set
Set $_MvcResponse to $inMvcResponse
Returns the site config object by lazy load
Set the siteConfig instance
Returns the plugin set, lazy-loading it if the object does not exist
Allows the plugins to be set manually
protected buildPath([$inPath = null])
Returns a properly formed path/to/the/thing with / set to the system dir separator
Path can be a string, array or mvcControllerMap object. If $inPath is null, the current request in the controller map is used.
public includeLibraryFile($inLibraryFile, [$inPath = null])
Includes a file from the libraries folder of the site
public includeControllerFile($inControllerFile, [$inPath = null])
Includes a file from the controllers folder of the site
public includeControllerUnit($inControllerName, [$inPath = null])
Includes an entire unit based on $inControllerName
e.g. $inControllerName = 'login', $inPath = '/user/login'
Loads controller filename: loginController.class.php from /user/login Loads model filename: loginModel.class.php from /user/login Loads view filename: loginView.class.php from /user/login
public getControllerFile($inFileName, [$inPath = null])
Returns the path to the controller file located in the sites website.controllers.folder (default controllers)
public getTemplateFile($inFileName, [$inPath = null])
Returns the path to the specified template file, uses current controller path if none specified template must be located in views/controller/path. Template must be located within distributor.views.folder (default views)
public getLibraryFile($inFileName, [$inPath = null])
Returns the full path to the specified file to be included in relation to the current site and contained within the website.libraries.folder folder of that site (default libraries)
public getPluginFile($inFileName, [$inPath = null])
Returns the path to the specified plugin file, this method allows the plugin library files to be located outside of the site hierarchy. This will check the parent sites for a value, returns false if file does not exist or param not found.
Returns the instance of baseOptionsSet
public getOption([$inOption = null], [$inDefault = null])
Returns options or a specific option, null if not found
Returns the websites folder
Returns the default controller name
Returns the name of the controllers folder
Returns the name of the libraries folder
Returns the name of the views folder
Returns the error controller that will handle errors
Set options to $inOptions
$inOptions can be either an associative array or an instance of baseOptionsSet