Source for file RequestProcessor.php
Documentation is available at RequestProcessor.php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
* This source file is subject to version 2.1 of the GNU Lesser General Public
* License, that is bundled with this package in the file COPYING, available
* through the world wide web at the following URI:
* http://www.gnu.org/copyleft/lesser.html.
* @author Alessandro Rossini <http://www.alessandrorossini.org>
* @author Graziano Liberati <http://www.liberati.org>
* @author Tomasz Kuter <evolic@interia.pl>
* @copyright 2004-2007 The ZNF Development Team
* @license LGPL License 2.1 <http://www.gnu.org/copyleft/lesser.html>
* @version SVN $Id: RequestProcessor.php 44 2007-07-22 23:55:30Z evolic $
* @link http://www.zeronotice.org
require_once('ZNF/Action/Action.php');
require_once('ZNF/Action/ActionErrors.php');
require_once('ZNF/Action/ActionForm.php');
require_once('ZNF/Action/ActionForward.php');
require_once('ZNF/Action/ActionMapping.php');
* <i>ZNF_Action_RequestProcessor</i> contains the processing logic flow.
* Subclasses can customize the request processing behavior overriding the
* methods for which they wish to provide modified functionality.
* @author Alessandro Rossini <http://www.alessandrorossini.org>
* @author Graziano Liberati <http://www.liberati.org>
* @author Tomasz Kuter <evolic@interia.pl>
* @copyright 2004-2007 The ZNF Development Team
* @license LGPL License 2.1 <http://www.gnu.org/copyleft/lesser.html>
* @version SVN $Id: RequestProcessor.php 44 2007-07-22 23:55:30Z evolic $
* @link http://www.zeronotice.org
* The configuration of the module in the application configuration file.
* @var array $_appModuleConfig
* Constructs a new <i>ZNF_Action_RequestProcessor</i> object.
* @param String $module Name of the module requested
// gets the app module config
* Instruction executed before the execution of the process method.
* Instruction executed after the execution of the process method.
* Processes the action requested with the default processing flow.
// constructs the mapping object
// validates the user authorization
// constructs the form object
// populates the form object with the input data
// validates the input data if requested by the configuration file
// checks if in the configuration file is specified to forward to another action
// constructs the action object
// performs the action by the execute method of the action class
// finds forward by the result of the action
// end of the processing logic flow
* Extracts the mapping of the action requested from the configuration file.
* @return ZNF_Action_ActionMapping
// gets the module configuration
$actionConfig = $moduleConfig->findActionConfig($path);
$globalForwardsConfig = $moduleConfig->getGlobalForwardsConfig();
* Validates the authorization of the user to access to the action requested.
* @param ZNF_Action_ActionMapping $mapping
$roles = $mapping->getRoles();
// for this action is not required a role
if(isset ($_SESSION['znf']['roles'])) {
$rolesArray = explode(',', $roles);
foreach ($_SESSION['znf']['roles'] as $current) {
// the user has a role to execute this action
// there are no default roles associated to anonymous user or the roles
// are not matched, authentication is required
if ($_SESSION['znf']['authenticated'] == false) {
// force to recreateURL after successfull login
$_SESSION['znf']['recreateURL'] = true;
$_SESSION['znf']['requestURL'] = $_SERVER['REQUEST_URI'];
// gets the authentication configuration
$authConfig = $appConfig->findAuthConfig();
if (ereg('//', $authConfig['path'])) {
// authentication path is set to an action of another module
// extract module and action name
$moduleAction = explode('//', $authConfig['path']);
// update module and action in the request
$znf->updateModule($moduleAction[0]);
$znf->updateAction($moduleAction[1]);
} else if (ereg('/', $authConfig['path'])) {
// authentication path is set to a view
$authConfig['path'] = ZNF::MODULES_DIR . '/' . $authConfig['path'];
require_once($authConfig['path']);
// authentication path is set to an action
$this->process($authConfig['path']);
// gets the wrong authentication configuration
$wrongAuthConfig = $appConfig->findWrongAuthConfig();
if (ereg('//', $wrongAuthConfig['path'])) {
// wrong authentication path is set to an action of another module
// extract module and action name
$moduleAction = explode('//', $wrongAuthConfig['path']);
// update module and action in the request
$znf->updateModule($moduleAction[0]);
$znf->updateAction($moduleAction[1]);
} else if (ereg('/', $wrongAuthConfig['path'])) {
// authentication path is set to a view
$wrongAuthConfig['path'] = ZNF::MODULES_DIR . '/' . $wrongAuthConfig['path'];
require_once($wrongAuthConfig['path']);
// wrong authentication path is set to an action
$this->process($wrongAuthConfig['path']);
// the user is authenticated and he has not a role to execute this
* If the <i>name</i> property of the <i>ZNF_Action_ActionMapping</i> is found constructs a <i>ZNF_Action_ActionForm</i> object to process the input data.
* If the package of which the <i>ZNF_Action_ActionForm</i> class belongs is
* not found a <i>ZNF_Action_RequestProcessorException</i> is raised.
* @param ZNF_Action_ActionMapping $mapping
* @return ZNF_Action_ActionForm
// gets the name of the form
$name = $mapping->getName();
// gets the module configuration
// extracts the configuration of the form
$formBeanConfig = $moduleConfig->findFormBeanConfig($name);
// no form configuration found
$scope = $mapping->getScope();
// try to load a pre-existing form from the request or session
if ($scope == 'request') {
$form = $_REQUEST['znf']['form'];
} elseif ($scope == 'session') {
$form = $_SESSION['znf']['form'];
// constructs the ZNF_Action_ActionForm object
$type = $formBeanConfig['type'];
// requires the file of the of the ZNF_Action_ActionForm
if ($scope == 'request') {
$_REQUEST['znf']['form'] = $form;
} elseif ($scope == 'session') {
$_SESSION['znf']['form'] = $form;
* Populates internal properties of the <i>ZNF_Action_ActionForm</i> object with the input data.
* @param ZNF_Action_ActionForm $form
return $form->populate();
* @param ZNF_Action_ActionForm $form
* @param ZNF_Action_ActionMapping $mapping
if ($form && $mapping->getValidate() == 'true') {
$errors = $form->validate();
if ($errors->getNumErrors()) {
$_REQUEST['errors'] = $errors;
$input = $mapping->getInput();
if (ereg('//', $input)) {
// forward is set to an action of another module
// extract module and action name
$moduleAction = explode('//', $input);
// update module and action in the request
$znf->updateModule($moduleAction[0]);
$znf->updateAction($moduleAction[1]);
} else if (ereg('/', $input)) {
// forward is set to a view
$input = ZNF::MODULES_DIR . '/' . $input;
// forward is set to an action
* If the <i>forward</i> attribute for the current action is found calls <i>ZNF_Action_RequestProcessor->process()</i> with the forward found and break the current proccess flow.
* @param ZNF_Action_ActionMapping $mapping
$forward = $mapping->getForward();
if (ereg('//', $forward)) {
// forward is set to an action of another module
// extract module and action name
$moduleAction = explode('//', $forward);
// update module and action in the request
$znf->updateModule($moduleAction[0]);
$znf->updateAction($moduleAction[1]);
} else if (ereg('/', $forward)) {
// forward is set to a view
$forward = ZNF::MODULES_DIR . '/' . $forward;
// forward is set to an action
* Finds the <i>ZNF_Action_Action</i> class to handle the action.
* Constructs an instance and returns it to the
* <i>ZNF_Action_RequestProcessor->process()</i> method.
* @param ZNF_Action_ActionMapping $mapping
* @return ZNF_Action_Action
$type = $mapping->getType();
// requires the file of the controller of the action
* Calls the <i>ZNF_Action_Action->execute()</i> method and returns the result to the <i>ZNF_Action_RequestProcessor->process()</i> method.
* @param ZNF_Action_Action $action
* @param ZNF_Action_ActionForm $form
* @param ZNF_Action_ActionMapping $mapping
* @return ZNF_Action_ActionForward
return $action->execute($form, $mapping);
* Forwards or redirects to the specified destination, by the specified mechanism.
* @param ZNF_Action_ActionForward $forward
* @param ZNF_Action_ActionForm $form
* @param ZNF_Action_ActionMapping $mapping
$path = $forward->getPath();
// check if the forward refer to an action of another module
$redirect = $forward->getRedirect();
if ($redirect == 'true') {
// checks if https was used
if (isset ($_SERVER['HTTPS'])) {
$location .= "{ $_SERVER['SERVER_NAME']}";
if ($_SERVER['SERVER_PORT'] != '80' && $_SERVER['SERVER_PORT'] != '443') {
$location .= ":{$_SERVER['SERVER_PORT']}";
$location .= $_SERVER['SCRIPT_NAME'];
// makes the browser reloads the new url
header('Location: ' . "{ $location}? " . ZNF::MODULE_INDEX . "={$pathArray[0]}" . "&" . ZNF::ACTION_INDEX . "={$pathArray[1]}");
header('Location: ' . "{ $location}? " . ZNF::ACTION_INDEX . "={$path}");
} elseif (ereg('//', $path)) {
// forward is set to an action of another module
// update module and action in the request
$znf->updateModule($pathArray[0]);
$znf->updateAction($pathArray[1]);
} elseif (ereg('/', $path)) {
$path = ZNF::MODULES_DIR . '/' . $path;
* @param ZNF_Action_ActionForm $form
* @param ZNF_Action_ActionMapping $mapping
* Destroys the <i>ZNF_Action_RequestProcessor</i> object.
* <i>ZNF_Action_RequestProcessorException</i> is the exception type for the <i>ZNF_Action_RequestProcessor</i> class.
* <i>ZNF_Action_RequestProcessorException</i> extends the <i>Exception</i> class of PHP5.
* @author Alessandro Rossini <http://www.alessandrorossini.org>
* @author Graziano Liberati <http://www.liberati.org>
* @copyright 2004-2007 The ZNF Development Team
* @license LGPL License 2.1 <http://www.gnu.org/copyleft/lesser.html>
* @version SVN $Id: RequestProcessor.php 44 2007-07-22 23:55:30Z evolic $
* @link http://www.zeronotice.org
|