Source for file ModulesConfig.php
Documentation is available at ModulesConfig.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>
* @copyright 2004-2007 The ZNF Development Team
* @license LGPL License 2.1 <http://www.gnu.org/copyleft/lesser.html>
* @version SVN $Id: ModulesConfig.php 43 2007-06-26 23:36:35Z aronnax $
* @link http://www.zeronotice.org
* <i>ZNF_Config_ModulesConfig</i> contains the collection of static module configuration informations.
* Returns the <i>ZNF_Config_ModulesConfig</i> object reference of a specified
* module with a singleton pattern.
* @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: ModulesConfig.php 43 2007-06-26 23:36:35Z aronnax $
* @link http://www.zeronotice.org
* The array of <i>ZNF_Config_ModulesConfig</i> object references.
* @staticvar array $_modulesConfig
* The array of the configuration file.
* Private constructor to avoid <i>ZNF_Config_ModulesConfig</i> object creation.
* @param array $appModuleConfig The module's application configuration
* Private clonator to avoid <i>ZNF_Config_ModulesConfig</i> object clonation.
* Returns the reference to the <i>ZNF_Config_ModulesConfig</i> object with a singleton pattern.
* This object is shared by all the classes that require the module
* @param array $appModuleConfig
* @return ZNF_Config_ModulesConfig
if (!(isset (self::$_modulesConfig[$appModuleConfig['name']]))) {
self::$_modulesConfig[$appModuleConfig['name']] = new ZNF_Config_ModulesConfig($appModuleConfig);
return self::$_modulesConfig[$appModuleConfig['name']];
* Parses and validates the configuration file.
* For performance reasons implements a caching mechanism that serializes the
* configuration file in an internal structure.
* @param array $appModuleConfig
$serializedTimestamp = @filemtime(ZNF::CACHE_DIR . "/{$appModuleConfig['config']}.cache");
$xmlTimestamp = filemtime(ZNF::CONFIG_DIR . "/{$appModuleConfig['config']}");
if ($xmlTimestamp <= $serializedTimestamp) {
$configXml = new DOMDocument('1.0','utf-8');
$configXml->load(ZNF::CONFIG_DIR . "/{$appModuleConfig['config']}");
// quick hack to make ZNF work as a PEAR package, to be improved
$schemaPath = substr($dirName, 0, strpos($dirName, 'Config')) . "xsd/znf-module-config.xsd";
if (!$configXml->schemaValidate($schemaPath)) {
$xpath = new DOMXPath($configXml);
$xpath->registerNamespace('mod', 'http://www.zeronotice.org/ZNF/znf-module-config');
$default = $xpath->query('/mod:znf-module-config/mod:action-mappings/mod:action[@default="true"]');
if ($default->length == 1) {
$forward = $default->item(0)->getAttribute('forward');
$type = $default->item(0)->getAttribute('type');
// check if only one of forward or type attribute is defined
// check if forward is a valid action
if ($forward && (!ereg('/', $forward) || ereg('//', $forward))) {
// TODO: add the checking of valid action in other module
if (!ereg('//', $forward)) {
$forwardAction = $xpath->query('/mod:znf-module-config/mod:action-mappings/mod:action[@path="' . $forward . '"]');
if (!$forwardAction->length) {
$config['action']['default']['forward'] = $forward;
$config['action']['default']['include'] = $default->item(0)->getAttribute('include');
$scope = $default->item(0)->getAttribute('scope');
$name = $default->item(0)->getAttribute('name');
// check if name is defined when scope is defined
// check if name refers to a valid form-bean
$form = $xpath->query('/mod:znf-module-config/mod:form-beans/mod:form-bean[@name="' . $name . '"]');
$parameter = $default->item(0)->getAttribute('parameter');
$parameterValue = $default->item(0)->getAttribute('parameterValue');
// check if only one of forward or type attribute is defined
if ($parameter && $parameterValue) {
$config['action']['default']['parameter'] = $parameter;
$config['action']['default']['parameterValue'] = $parameterValue;
$config['action']['default']['scope'] = $scope;
$config['action']['default']['name'] = $name;
$config['action']['default']['nextPath'] = $default->item(0)->getAttribute('nextPath');
$config['action']['default']['path'] = $default->item(0)->getAttribute('path');
$input = $default->item(0)->getAttribute('input');
$validate = $default->item(0)->getAttribute('validate');
// check if validate and input are both defined
if ($input && !$validate) {
} elseif (!$input && $validate) {
$config['action']['default']['input'] = $input;
$config['action']['default']['validate'] = $validate;
$config['action']['default']['roles'] = $default->item(0)->getAttribute('roles');
$config['action']['default']['type'] = $type;
// get forward elements associated with the action
$forwards = $xpath->query('/mod:znf-module-config/mod:action-mappings/mod:action[@path="' . $default->item(0)->getAttribute('path') . '"]/mod:forward');
foreach ($forwards as $forward) {
$forwardPath = $forward->getAttribute('path');
$forwardRedirect = $forward->getAttribute('redirect');
// check if redirect is required and if the path is an action
if ($forwardRedirect == 'true') {
if ($forwardPath && ereg('/', $forwardPath) && !ereg('//', $forwardPath)) {
// check if the path is a valid action
if ($forwardPath && (!ereg('/', $forwardPath) || ereg('//', $forwardPath))) {
// TODO: add the checking of valid action in other module
if (!ereg('//', $forwardPath)) {
$forwardAction = $xpath->query('/mod:znf-module-config/mod:action-mappings/mod:action[@path="' . $forwardPath . '"]');
if (!$forwardAction->length) {
$forwardName = $forward->getAttribute('name');
$config['action']['default']['forwards-config'][$forwardName]['name'] = $forwardName;
$config['action']['default']['forwards-config'][$forwardName]['path'] = $forwardPath;
$config['action']['default']['forwards-config'][$forwardName]['redirect'] = $forwardRedirect;
// check if only one default action is defined
} elseif ($default->length > 1) {
// check if at least one default action is defined
$forwards = $xpath->query('/mod:znf-module-config/mod:global-forwards/mod:forward');
foreach ($forwards as $forward) {
$forwardPath = $forward->getAttribute('path');
$forwardRedirect = $forward->getAttribute('redirect');
// check if redirect is required and if the path is an action
if ($forwardRedirect == 'true') {
if ($forwardPath && ereg('/', $forwardPath) && !ereg('//', $forwardPath)) {
// check if the path is a valid action
if ($forwardPath && (!ereg('/', $forwardPath) || ereg('//', $forwardPath))) {
// TODO: add the checking of valid action in other module
if (!ereg('//', $forwardPath)) {
$forwardAction = $xpath->query('/mod:znf-module-config/mod:action-mappings/mod:action[@path="' . $forwardPath . '"]');
if (!$forwardAction->length) {
$forwardName = $forward->getAttribute('name');
$config['global-forwards'][$forwardName]['name'] = $forwardName;
$config['global-forwards'][$forwardName]['path'] = $forward->getAttribute('path');
$config['global-forwards'][$forwardName]['redirect'] = $forward->getAttribute('redirect');
$actions = $xpath->query('/mod:znf-module-config/mod:action-mappings/mod:action');
foreach ($actions as $action) {
$path = $action->getAttribute('path');
$forward = $action->getAttribute('forward');
$type = $action->getAttribute('type');
// check if only one of forward or type attribute is defined
// check if forward is a valid action
if ($forward && (!ereg('/', $forward) || ereg('//', $forward))) {
// TODO: add the checking of valid action in other module
if (!ereg('//', $forward)) {
$forwardAction = $xpath->query('/mod:znf-module-config/mod:action-mappings/mod:action[@path="' . $forward . '"]');
if (!$forwardAction->length) {
$config['action'][$path]['forward'] = $forward;
$config['action'][$path]['include'] = $action->getAttribute('include');
$scope = $action->getAttribute('scope');
$name = $action->getAttribute('name');
// check if name is defined when scope is defined
// check if name refers to a valid form-bean
$form = $xpath->query('/mod:znf-module-config/mod:form-beans/mod:form-bean[@name="' . $name . '"]');
$parameter = $action->getAttribute('parameter');
$parameterValue = $action->getAttribute('parameterValue');
// check if only one of forward or type attribute is defined
if ($parameter && $parameterValue) {
$config['action'][$path]['parameter'] = $parameter;
$config['action'][$path]['parameterValue'] = $parameterValue;
$config['action'][$path]['scope'] = $scope;
$config['action'][$path]['name'] = $name;
$config['action'][$path]['nextPath'] = $action->getAttribute('nextPath');
$config['action'][$path]['path'] = $action->getAttribute('path');
$input = $action->getAttribute('input');
$validate = $action->getAttribute('validate');
// check if validate and input are both defined
if ($input && !$validate) {
} elseif (!$input && $validate) {
$config['action'][$path]['input'] = $input;
$config['action'][$path]['validate'] = $validate;
$config['action'][$path]['roles'] = $action->getAttribute('roles');
$config['action'][$path]['type'] = $type;
// get forward elements associated with the action
$forwards = $xpath->query('/mod:znf-module-config/mod:action-mappings/mod:action[@path="' . $path . '"]/mod:forward');
foreach ($forwards as $forward) {
$forwardPath = $forward->getAttribute('path');
$forwardRedirect = $forward->getAttribute('redirect');
// check if redirect is required and if the path is an action
if ($forwardRedirect == 'true') {
if ($forwardPath && ereg('/', $forwardPath) && !ereg('//', $forwardPath)) {
// check if the path is a valid action
if ($forwardPath && (!ereg('/', $forwardPath) || ereg('//', $forwardPath))) {
// TODO: add the checking of valid action in other module
if (!ereg('//', $forwardPath)) {
$forwardAction = $xpath->query('/mod:znf-module-config/mod:action-mappings/mod:action[@path="' . $forwardPath . '"]');
if (!$forwardAction->length) {
$forwardName = $forward->getAttribute('name');
$config['action'][$path]['forwards-config'][$forwardName]['name'] = $forwardName;
$config['action'][$path]['forwards-config'][$forwardName]['path'] = $forwardPath;
$config['action'][$path]['forwards-config'][$forwardName]['redirect'] = $forwardRedirect;
$forms = $xpath->query('/mod:znf-module-config/mod:form-beans/mod:form-bean');
foreach ($forms as $form) {
$formName = $form->getAttribute('name');
$config['form-bean'][$formName]['name'] = $formName;
$config['form-bean'][$formName]['type'] = $form->getAttribute('type');
* Returns the global forwards configuration.
return $this->_config['global-forwards'];
* Returns the action configuration for the defined <i>path</i>.
// extracts the configuration of the action requested
return $this->_config['action'][$path];
* Returns the form bean configuration for the defined <i>name</i>.
// extracts the configuration of the action requested
return $this->_config['form-bean'][$name];
* Destroys the <i>ZNF_Config_ModulesConfig</i> object.
* <i>ZNF_Config_ModulesConfigException</i> is the exception type for the <i>ZNF_Config_ModulesConfig</i> class.
* <i>ZNF_Config_ModulesConfigException</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: ModulesConfig.php 43 2007-06-26 23:36:35Z aronnax $
* @link http://www.zeronotice.org
|