Location: PHPKode > projects > web.framework > web.framework-1.0.0/web.framework/WebFramework.class.php
<?php
/**
 * Project:     web.framework: the PHP5 MVC framework
 * File:		WebFramework.class.php
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * You may contact the authors of web.framework by e-mail at:
 * hide@address.com
 *
 * The latest version of web.framework can be obtained from:
 * http://sourceforge.net/projects/webframework
 *
 * @link http://sourceforge.net/projects/webframework
 * @copyright 2005 Marcin Staniszczak
 * @author Marcin Staniszczak <hide@address.com>
 * @version 1.0.0
 */


/**
 * The main class
 *
 * @name WebFramework
 * @version 1.0.0
 * @package web.framework
 * @todo WEBFRAMEWORK_ prefix - maja dzialac stare i nowe stale!!
 *
 * @author Marcin Staniszczak
 * @copyright 2005 Marcin Staniszczak
 */
class WebFramework {
	public static
		$strLanguage = 'ENGLISH';

	public static
		$intMajorVersion = 1,
		$intMinorVersion = 0,
		$intUpdateVersion = 0;

	private
		$objConfiguration = null,
		$arrConfiguration = array();

	private
		$objValidator = null;

	/**
	 * @access private
	 * @var array
	 */
	private $arrActionsResponses = array();

	/**
	 * @access private
	 * @var array
	 */
	//private $objActionForm = null;

	/**
	 * @access private
	 * @var IRouter
	 */
	private $objRouter = null;

	/**
	 * @access private
	 * @var IHTTPResponse
	 */
	private $objHTTPResponse = null;

	/**
	 * @access private
	 * @var HTTPRequest
	 */
	private $objHTTPRequest = null;

	/**
	 * @access private
	 * @var Session
	 */
	private $objSession = null;

	/**
	 * @access private
	 * @var ActionSharedData
	 */
	private $objActionsSharedData = null;

	/**
	 * @access private
	 * @var ITemplate
	 */
	private $objTemplate = null;

	/**
	 * @access private
	 * @var IToken
	 */
	private $objToken = null;

	/**
	 * @access private
	 * @var IAuthorization
	 */
	private $objAuthorization = null;

	/**
	 * @access private
	 * @var boolean
	 */
	private $blnTokenRespone = false;

	/**
	 * @access private
	 * @var string
	 */
	private $strNewToken = null;

	/**
	 * The class constructor
	 *
	 * @access public
	 */
	public function __construct() {
		/*
		 * Configuration reading - it's this place web.framework can discard ill-looking (PHP standard) throw
		 */
		if (defined('WEBFRAMEWORK_CONFIGURATION_PARSER')) {
			$this->objConfiguration = Configuration::construct(WEBFRAMEWORK_CONFIGURATION_PARSER, WEBFRAMEWORK_CONFIGURATION_FILE_DIR, WEBFRAMEWORK_CONFIGURATION_FILE_EXTENSION);
		} else {
			$this->objConfiguration = Configuration::construct('DefaultConfigurationParser', WEBFRAMEWORK_CONFIGURATION_FILE_DIR, WEBFRAMEWORK_CONFIGURATION_FILE_EXTENSION);
		}

		$this->arrConfiguration = $this->objConfiguration->getConfiguration();
	}

	/**
	 * Application start
	 *
	 * @access public
	 * @throws WF_Exception
	 */
	public function run() {
		try {
			if (!isset($this->arrConfiguration['settings']['URL'])) {
				throw new WF_Exception(Languages::$MESSAGES[self::$strLanguage]['EXCEPTIONS']['URL_PARAMETER']);
			}

			if (isset($this->arrConfiguration['settings']['defaultLanguage'])) {
				self::$strLanguage = $this->arrConfiguration['settings']['defaultLanguage'];
			}

			/*
			 * Router
			 */
			if (isset($this->arrConfiguration['settings']['router'])) {
				require_once(WEBFRAMEWORK_CORE_DIR.'Context'.DIRECTORY_SEPARATOR.'Router'.DIRECTORY_SEPARATOR.'Routers'.DIRECTORY_SEPARATOR.$this->arrConfiguration['settings']['router'].'class.php');
				$this->objRouter = new $this->arrConfiguration['settings']['router']($this->arrConfiguration['settings']['URL'], self::$strLanguage);
				if(!($this->objRouter instanceof IRouter ))
					throw new WF_Exception(Languages::$MESSAGES[self::$strLanguage]['EXCEPTIONS']['ROUTER_INTERFACE']);
			} else {
				$this->objRouter = new DefaultRouter($this->arrConfiguration['settings']['URL'], self::$strLanguage);
			}

			/*
			 * Session
			 */
			$objSessionHandler = null;
			if (isset($this->arrConfiguration['settings']['sessionHandler'])) {
				require_once(WEBFRAMEWORK_CORE_DIR.'Context'.DIRECTORY_SEPARATOR.'Session'.DIRECTORY_SEPARATOR.'SessionHandlers'.DIRECTORY_SEPARATOR.$this->arrConfiguration['settings']['sessionHandler'].'.class.php');
				$objSessionHandler = new $this->arrConfiguration['settings']['sessionHandler']($this->arrConfiguration);
			}
			$this->objSession = new Session($objSessionHandler);

			/*
			 * session start
			 */
			if (isset($this->arrConfiguration['settings']['autoStartSession']) && strcmp($this->arrConfiguration['settings']['autoStartSession'], 'true')==0) {
				$this->objSession->start();
			}

			/*
			 * HTTPResponse
			 */
			if (isset($this->arrConfiguration['settings']['HTTPResponse'])) {
				require_once(WEBFRAMEWORK_CORE_DIR.'Context'.DIRECTORY_SEPARATOR.'Response'.DIRECTORY_SEPARATOR.'Responses'.DIRECTORY_SEPARATOR.$this->arrConfiguration['settings']['HTTPResponse'].'.class.php');
				$this->objHTTPResponse = new $this->arrConfiguration['settings']['HTTPResponse']($this->objSession);
			} else {
				$this->objHTTPResponse = new GZipResponse($this->objSession);
			}

			/*
			 * HTTPRequest
			 */
			$this->objHTTPRequest = new HTTPRequest($this->objRouter);

			/*
			 * ActionsSharedData
			 */
			$this->objActionsSharedData = ActionsSharedData::construct();


			/*
			 * Token
			 */
			$this->objToken = null;
			if (isset($this->arrConfiguration['token'])) {

				$strTokenFormName = (isset($this->arrConfiguration['token']['tokenName'])) ?
										$this->arrConfiguration['token']['tokenName'] :
										'webframework_token_ID_name';

				if (isset($this->arrConfiguration['token']['method'])) {
					$intTokenSendMethod = (strcmp($this->arrConfiguration['token']['method'], 'POST')==0) ? HTTPRequest::POST : HTTPRequest::GET;
				} else {
					$intTokenSendMethod = HTTPRequest::POST;
				}

				if (isset($this->arrConfiguration['token']['tokenDriver'])) {
					$this->objToken = new Token($strTokenFormName, $intTokenSendMethod, $this->objHTTPRequest, $this->objSession, $this->arrConfiguration['token']['tokenDriver']);
				} else {
					$this->objToken = new Token($strTokenFormName, $intTokenSendMethod, $this->objHTTPRequest, $this->objSession);
				}
			}

			/*
			 * Authorization
			 */
			if (isset($this->arrConfiguration['authorization']) &&
				isset($this->arrConfiguration['authorization']['driver']) &&
				(isset($this->arrConfiguration['authorization']['accessDeniedView']) ||
				 isset($this->arrConfiguration['authorization']['accessDeniedAction']) ||
				 isset($this->arrConfiguration['authorization']['accessDeniedActionChain']))) {

				$strDriverPath = isset($this->arrConfiguration['authorization']['driverPath']) ?
									$this->arrConfiguration['authorization']['driverPath'] :
									WEBFRAMEWORK_CORE_DIR.'Authorization'.DIRECTORY_SEPARATOR.'AuthorizationDrivers'.DIRECTORY_SEPARATOR;

				require_once($strDriverPath.$this->arrConfiguration['authorization']['driver'].'.class.php');
				$this->objAuthorization = new $this->arrConfiguration['authorization']['driver']($this->objHTTPRequest, $this->objSession);

				if (!($this->objAuthorization instanceof IAuthorization)) {
					throw new WF_Exception(Languages::$MESSAGES[self::$strLanguage]['EXCEPTIONS']['AUTHORIZATION_INTERFACE']);
				}
			}

			/*
			 * Templates
			 */
			if (isset($this->arrConfiguration['template'])
				&& isset($this->arrConfiguration['template']['templateDir'])
				&& isset($this->arrConfiguration['template']['cacheDir'])
				&& isset($this->arrConfiguration['template']['compileDir'])) {

				$strTplClass = 'WebTemplate_File';
				if (isset($this->arrConfiguration['template']['template'])) {
					$strTplClass = $this->arrConfiguration['template']['template'];
				}

				$this->objTemplate = new $strTplClass($this->arrConfiguration['template']['templateDir'], $this->arrConfiguration['template']['cacheDir'], $this->arrConfiguration['template']['compileDir']);
				//echo 'in';
			}


			/*
			 * pre-actions
			 */
			if (isset($this->arrConfiguration['preactions']['actions']) && $this->chackPrePostAction(1)) {
				foreach ($this->arrConfiguration['preactions']['actions'] as $strActionName=>$arrAction) {
					$this->executeAction($strActionName, $arrAction);
				}
			}

			/*
			 * main action or action-chain handling
			 */
			if ($this->objRouter->getAJAX()!==null) {
				define('WEBFRAMEWORK_DISPLAY_STATS_OFF', true);
				$objAJAX = new WebAJAX($this->arrConfiguration['ajax'], $this->arrConfiguration['settings']['URL']);
				//print_r($this->objRouter->getAll());

				$arrAJAX = $this->objRouter->getAJAX();

				$strClass = $arrAJAX['class'];
				$strMethod = $arrAJAX['method'];
				$arrArgs = $arrAJAX['margs'];

				$objAJAX->callMethod($strClass, $strMethod, $arrArgs);
			} elseif (($this->objRouter->getAction()!==null) &&
					  (!isset($this->arrConfiguration['actions'][$this->objRouter->getAction()]['visible']) ||
					  (strcmp($this->arrConfiguration['actions'][$this->objRouter->getAction()]['visible'], 'false')!==0))) { /* Action */

				$strActionName = $this->objRouter->getAction();
				if (isset($this->arrConfiguration['actions'][$strActionName])) {
					$this->executeAction($strActionName, $this->arrConfiguration['actions'][$strActionName]);
				} else {
					throw new WF_Exception404(sprintf(Languages::$MESSAGES[self::$strLanguage]['EXCEPTIONS']['NO_ACTION'], $strActionName));
				}
			} elseif (($this->objRouter->getActionChain()!==null) &&
					  (!isset($this->arrConfiguration['actionchain'][$this->objRouter->getActionChain()]['visible']) ||
					  (strcmp($this->arrConfiguration['actionchain'][$this->objRouter->getActionChain()]['visible'], 'false')!==0))) { /* ActionChain */

				$strActionChain = $this->objRouter->getActionChain();

				/* authorization chcek */
				if (isset($this->arrConfiguration['actionchain'][$strActionChain]['authorization'])) {
					if (!$this->checkAuthorization(null, $strActionChain, $this->arrConfiguration['actionchain'][$strActionChain]['authorization'])) {
						return;
					}
				}

				if(isset($this->arrConfiguration['actionchain'][$strActionChain])) {
						$this->executeActionChain($strActionChain, $this->arrConfiguration['actionchain'][$strActionChain]);
				} else {
					throw new WF_Exception404(sprintf(Languages::$MESSAGES[self::$strLanguage]['EXCEPTIONS']['NO_ACTION_CHAIN'], $strActionChain));
				}
			} elseif (($this->objRouter->getWTCall()!==null) &&
					  (!isset($this->arrConfiguration['wtcalls'][$this->objRouter->getWTCall()]['visible']) ||
					  (strcmp($this->arrConfiguration['wtcalls'][$this->objRouter->getWTCall()]['visible'], 'false')!==0))) { /* wt-call */

				$strWTName = $this->objRouter->getWTCall();
				$this->executeWTCall($strWTName, $this->arrConfiguration['wtcalls'][$strWTName]);
			} elseif (isset($this->arrConfiguration['settings']['defaultAction'])) { /* Default action */
				$strActionName = $this->arrConfiguration['settings']['defaultAction'];
				if (isset($this->arrConfiguration['actions'][$strActionName])) {
					$this->executeAction($strActionName, $this->arrConfiguration['actions'][$strActionName]);
				} else {
					throw new WF_Exception404(sprintf(Languages::$MESSAGES[self::$strLanguage]['EXCEPTIONS']['NO_ACTION'], $strActionName));
				}
			} elseif(isset($this->arrConfiguration['settings']['defaultActionChain'])) { /* Default action */
				$strActionChain = $this->arrConfiguration['settings']['defaultActionChain'];
				if (isset($this->arrConfiguration['actionchain'][$strActionChain])) {
						$this->executeActionChain($strActionChain, $this->arrConfiguration['actionchain'][$strActionChain]);
				} else {
					throw new WF_Exception(sprintf(Languages::$MESSAGES[self::$strLanguage]['EXCEPTIONS']['NO_ACTION_CHAIN'], $strActionChain));
				}
			} elseif (isset($this->arrConfiguration['settings']['defaultWTCall'])) { /* Default web.template call */
				$strWTName = $this->arrConfiguration['settings']['defaultWTCall'];
				$this->executeWTCall($strWTName, $this->arrConfiguration['wtcalls'][$strWTName]);
			} else {
				throw new WF_Exception(Languages::$MESSAGES[self::$strLanguage]['EXCEPTIONS']['REQUIRED_ACTION_OR_ACTIONCHAIN']);
			}

			/*
			 * post-actions
			 */
			if (isset($this->arrConfiguration['postactions']['actions']) && $this->chackPrePostAction(2)) {
				foreach ($this->arrConfiguration['postactions']['actions'] as $strActionName=>$arrAction) {
					$this->executeAction($strActionName, $arrAction);
				}
			}
		} catch (Exception $e) {
			if (isset($this->arrConfiguration['settings']['applicationErrorAction']) && isset($this->arrConfiguration['actions'][$this->arrConfiguration['settings']['applicationErrorAction']])) {
				$this->objActionsSharedData->addData('exception', $e);
				$this->executeAction($this->arrConfiguration['settings']['applicationErrorAction'], $this->arrConfiguration['actions'][$this->arrConfiguration['settings']['applicationErrorAction']]);
			} else {
				$this->objHTTPResponse->cleanOutput();
				echo 'Exception '.$e->getMessage().' in file '.$e->getFile().' at line '.$e->getLine().'.<br>';
			}
		}

		$this->objHTTPResponse->flush();
	}

	/**
	 * This method check if can execute pre- or post- action for current action or current action-chain
	 *
	 * @access private
	 * @param integer 1 - pre-actions, 2 - post-actions
	 * @return true - execute post- or pre- action is allowed, false - execute post- or pre- action is forbid
	 * @throws WF_Exception
	 */
	private function chackPrePostAction($intPrePost) {
		$strPrePost = $intPrePost==1 ? 'preactions' : 'postactions';

		if (!isset($this->arrConfiguration[$strPrePost]['excepts'])) {
			return true;
		}

		$strACName = '';
		$strActionOrChain = '';
		if ($this->objRouter->getAction()!==null) {
			$strACName = $this->objRouter->getAction();
			$strActionOrChain = 'actions';
		} elseif ($this->objRouter->getActionChain()!==null) {
			$strACName = $this->objRouter->getActionChain();
			$strActionOrChain = 'actionchain';
		} elseif (isset($this->arrConfiguration['settings']['defaultAction'])) {
			$strACName = $this->arrConfiguration['settings']['defaultAction'];
			$strActionOrChain = 'actions';
		} elseif (isset($this->arrConfiguration['settings']['defaultActionChain'])) {
			$strACName = $this->arrConfiguration['settings']['defaultActionChain'];
			$strActionOrChain = 'actionchain';
		} else {
			throw new WF_Exception(Languages::$MESSAGES[self::$strLanguage]['EXCEPTIONS']['REQUIRED_ACTION_OR_ACTIONCHAIN']);
		}

		if (isset($this->arrConfiguration[$strPrePost]['excepts'][$strActionOrChain][$strACName])) {
			return false;
		} else {
			return true;
		}
	}

	/**
	 * Execute action-chain
	 *
	 * @access private
	 * @param string action-chain name
	 * @param array array with action-chain configuration
	 * @throws WF_Exception
	 */
	private function executeActionChain($strName, $arrAChain) {
		if (!isset($arrAChain['actions']) && !isset($arrAChain['calls'])) {
			throw new WF_Exception(printf(Languages::$MESSAGES[self::$strLanguage]['EXCEPTIONS']['NO_ACTION_IN_AC'], $strName));
		}

		if (isset($arrAChain['actions'])) {
			foreach ($arrAChain['actions'] as $strAction=>$arrAction) {
				$this->executeAction($strAction, $arrAction, $strName);
			}
		} /*else {
			throw new WF_Exception(printf(Languages::$MESSAGES[self::$strLanguage]['EXCEPTIONS']['URL_PARAMETER'], $strName));
		}*/

		if (isset($arrAChain['calls'])) {
			foreach ($arrAChain['calls'] as $strCall=>$arrCall) {
				if (isset($arrCall['action-chain'])) {
					if (isset($this->arrConfiguration['actionchain'][$arrCall['action-chain']])) {
						$this->executeActionChain($arrCall['action-chain'], $this->arrConfiguration['actionchain'][$arrCall['action-chain']]);
					} else {
						throw new WF_Exception(sprintf(Languages::$MESSAGES[self::$strLanguage]['EXCEPTIONS']['NO_ACTION_CHAIN'], $arrCall['action-chain']));
					}
				} elseif(isset($arrCall['action'])) {
					if (isset($this->arrConfiguration['actions'][$arrCall['action']])) {
						$this->executeAction($arrCall['action'], $this->arrConfiguration['actions'][$arrCall['action']], $strName);
					} else {
						throw new WF_Exception(sprintf(Languages::$MESSAGES[self::$strLanguage]['EXCEPTIONS']['NO_ACTION'], $arrCall['action']));
					}
				} elseif (isset($arrCall['wtcall'])) {
					if (isset($this->arrConfiguration['wtcalls'][$arrCall['wtcall']])) {
						$this->executeWTCall($arrCall['wtcall'], $this->arrConfiguration['wtcalls'][$arrCall['wtcall']]);
					} else {
						throw new WF_Exception(sprintf(Languages::$MESSAGES[self::$strLanguage]['EXCEPTIONS']['NO_WTCALL'], $arrCall['wtcall']));
					}
				}
			}
		}

		if (isset($arrAChain['wtcalls'])) {
			foreach ($arrAChain['wtcalls'] as $strCall=>$arrCall) {
				$this->executeWTCall($strCall, $arrCall);
			}
		}
	}

	/**
	 * Execute action
	 *
	 * @access private
	 * @param string action name
	 * @param array array with action configuration
	 * @param string name of action-chain which execute this action (or null)
	 * @throws WF_Exception
	 */
	private function executeAction($strName, $arrAction, $strAChain=null) {
		$strActionPath = WEBFRAMEWORK_ACTIONS_DIR;
		if (isset($arrAction['classpath'])) {
			$strActionPath .= $arrAction['classpath'];
		}

		if (!file_exists($strActionPath.$arrAction['type'].'.class.php')) {
			throw new WF_Exception(sprintf(Languages::$MESSAGES[self::$strLanguage]['EXCEPTIONS']['NO_ACTION_FILE'], $strName));
		}

		// W akcji!!
		// - sprawdzenei czy akcja wymaga autoryzacji
		// - jeśli tak sprawdzenie czy user ma dostęp do danej akcji

		/*
		 * Authorization chceck
		 */
		if (isset($arrAction['authorization'])) {
			if (!$this->checkAuthorization($strName, $strAChain, $arrAction['authorization'])) {
				return;
			}
		}

		require_once($strActionPath.$arrAction['type'].'.class.php');

		/*
		 * validators - read settings and execute
		 */
		$arrValidatorsResults = array();
		if (isset($arrAction['validators'])) {
			foreach ($arrAction['validators'] as $strValidator=>$arrValidator) {
				$mixResult = $this->executeValidator($strValidator, $arrValidator);
				if ($mixResult!==null) {
					$arrValidatorsResults[$strValidator] = $mixResult;
				}
			}
		} else {
			$arrValidatorsResults = null;
		}

		/*
		 * Execute action
		 */
		$strInfo = null;
		if(isset($arrAction['info'])) {
			$strInfo = $arrAction['info'];
		}

		$arrAJAX = null;
		if (isset($arrAction['ajax']) && isset($this->arrConfiguration['ajax'])) {
			$arrAJAX = $arrAction['ajax'];
		}

		$objAction = new $arrAction['type']($strName, $this->objActionsSharedData, $this->objToken, $arrValidatorsResults, $this->objConfiguration, $this->objTemplate, $strInfo, $strAChain, $arrAJAX);

		if (!($objAction instanceof Action)) {
			throw new WF_Exception(Languages::$MESSAGES[self::$strLanguage]['EXCEPTIONS']['ACTION_INTERFACE']);
		}

		//	abstract public function execute(HTTPRequest $objRequest, IHTTPResponse $objResponse, Session $objSession);
		/*
		RETURN:
			array(
				'View'		=> 'name of view from forward - see configuration file',
				'Response'	=> 'response from action to view',
				'Action'	=> 'action name to execute after this action or null', // not suuport jet
				'Errors'	=> 'array with exception to display in view' // not suuport jet
			);
		 */
		$arrResult = $objAction->execute($this->objHTTPRequest, $this->objHTTPResponse, $this->objSession);

		/*
		 * execute View
		 */
		if (isset($arrResult['View'])) {
			if (isset($arrAction['forwards'][$arrResult['View']])) {
				$this->executeView($strName, $arrResult['View'], $arrAction['forwards'][$arrResult['View']], isset($arrResult['Response']) ? $arrResult['Response'] : null);
			} else {
				throw new WF_Exception(sprintf(Languages::$MESSAGES[self::$strLanguage]['EXCEPTIONS']['UNKNOWN_VIEW'], $arrResult['View']));
			}
		} elseif (isset($arrResult['Template'])) {
			$strRetTemplate = is_array($arrResult['Template']) ? $arrResult['Template'][0] : $arrResult['Template'];
			$strID = is_array($arrResult['Template']) ? $arrResult['Template'][1] : null;

			if (isset($arrAction['templates'][$strRetTemplate])) {
				if ($this->objTemplate===null) {
					throw new WF_Exception(Languages::$MESSAGES[self::$strLanguage]['EXCEPTIONS']['TEMPLATE_REQUIRED']);
				}

				$strTemplate = $arrAction['templates'][$strRetTemplate]['tpl'];

				if (isset($arrAction['templates'][$strRetTemplate]['caching']) && strcmp($arrAction['templates'][$strRetTemplate]['tpl'], 'true')!==0) {
					$this->objTemplate->setCaching(false);
				}

				$this->objTemplate->display($strTemplate, $strID);
			} else {
				throw new WF_Exception(sprintf(Languages::$MESSAGES[self::$strLanguage]['EXCEPTIONS']['UNKNOWN_TEMPLATE'], $arrResult['Template']));
			}
		}

		/*
		 * Call another action
		 */
		if (isset($arrResult['Action'])) {
			if (isset($this->arrConfiguration['actions'][$arrResult['Action']])) {
				$this->executeAction($arrResult['Action'], $this->arrConfiguration['actions'][$arrResult['Action']], $strAChain);
			} else {
				throw new WF_Exception(sprintf(Languages::$MESSAGES[self::$strLanguage]['EXCEPTIONS']['NO_ACTION'], $arrCall['action']));
			}
		}
	}

	/**
	 * Execute validator
	 *
	 * @access private
	 * @param string validator name
	 * @param array array with validator configuration
	 */
	private function executeValidator($strName, $arrSettings) {
		if (is_null($this->objValidator)) {
			if(defined('WEBFRAMEWORK_VALIDATORS_PARSER')) {
				$this->objValidator = Validator::construct($this->objHTTPRequest, WEBFRAMEWORK_VALIDATORS_PARSER, $this->arrConfiguration, WEBFRAMEWORK_VALIDATORS_FILE_EXTENSION);
			} else {
				$this->objValidator = Validator::construct($this->objHTTPRequest, 'DefaultValidatorsParser', $this->arrConfiguration, WEBFRAMEWORK_VALIDATORS_FILE_EXTENSION);
			}
		}

		$strValidatorsSubPath = '';
		if(isset($arrSettings['configpath'])) {
			$strValidatorsSubPath = $arrSettings['configpath'];
		}

		return $this->objValidator->validate(WEBFRAMEWORK_VALIDATORS_DIR.$strValidatorsSubPath.$strName);
	}

	/**
	 * Execute view
	 *
	 * @access private
	 * @param string name of action which execute this view
	 * @param string view name
	 * @param array array with view configuration
	 * @param mixed action execute result
	 * @throws WF_Exception
	 */
	private function executeView($strActionName, $strNameView, $arrView, $mixActionResult) {
		//echo "<br><br>$strActionName, $strView, $mixActionResult<br><br>";
		//print_r($arrView);
		$strViewPath = WEBFRAMEWORK_VIEWS_DIR;
		if (isset($arrView['classpath'])) {
			$strViewPath .= $arrView['classpath'];
		}

		if (!file_exists($strViewPath.$arrView['view'].'.class.php')) {
				throw new WF_Exception(sprintf(Languages::$MESSAGES[self::$strLanguage]['EXCEPTIONS']['VIEW_NOT_FOUND'], $arrView['view']));
		}

		require_once($strViewPath.$arrView['view'].'.class.php');

		$objView = new $arrView['view']();
		$objView->display($strActionName, $strNameView, $mixActionResult, $this->objTemplate);
	}

	/**
	 * Execute template
	 *
	 * @access private
	 * @param string WTCall name
	 * @param array array with WTCall configuration
	 * @throws WF_Exception
	 */
	private function executeWTCall($strWTName, $arrSettings) {
		if ($this->objTemplate===null) {
			throw new WF_Exception(Languages::$MESSAGES[self::$strLanguage]['EXCEPTIONS']['TEMPLATE_REQUIRED']);
		}

		$objTemplate = $this->objTemplate->getInstance();

		if (isset($arrSettings['classes'])) {
			foreach ($arrSettings['classes'] as $strWTClassName=>$arrWTClass) {
				//echo 'Add varclass: '.$strWTClassName.' ('.$arrWTClass['type'].')';
				$objTemplate->addVarClass($strWTClassName, array($arrWTClass['type'], $arrWTClass['classpath']));
			}
		}

		if (isset($arrSettings['caching'])) {
			$blnCaching = strcmp($arrSettings['caching'], 'false') === 0 ? false : true;
			$objTemplate->setCaching($blnCaching);
		}

		$strCacheID = isset($arrSettings['cacheid']) ? $arrSettings['cacheid'] : null;

		$objTemplate->display($arrSettings['template'], $strCacheID);
	}

	private function checkAuthorization($strName, $strAChain, $strAuthorization) {
		/*
		 * Authorization chceck
		 */
		if (!$this->objAuthorization->check($strName, $strAChain, $strAuthorization)) {
			if (isset($this->arrConfiguration['authorization']['accessDeniedView'])) {
				$arrViewConfiguration = array();
				if (isset($this->arrConfiguration['authorization']['accessDeniedViewPath'])) {
					$arrViewConfiguration['classpath'] = $this->arrConfiguration['authorization']['accessDeniedViewPath'];
				}
				$arrViewConfiguration['view'] = $this->arrConfiguration['authorization']['accessDeniedView'];

				$this->executeView($strName, $this->arrConfiguration['authorization']['accessDeniedView'], $arrViewConfiguration, $strAuthorization);
				return false;
			} elseif (isset($this->arrConfiguration['authorization']['accessDeniedAction'])) {
				$strActionName = $this->arrConfiguration['authorization']['accessDeniedAction'];
				$this->executeAction($strActionName, $this->arrConfiguration['actions'][$strActionName]);
				return false;
			} elseif (isset($this->arrConfiguration['authorization']['accessDeniedActionChain'])) {
				$strAChainName = $this->arrConfiguration['authorization']['accessDeniedActionChain'];
				$this->executeActionChain($strAChainName, $this->arrConfiguration['actionchain'][$strAChainName]);
				return false;
			}
		}

		return true;
	}

}


/**
 * Exception of web.framework
 * @package web.framework
 * @subpackage exceptions
 */
class WF_Exception extends Exception {}

/**
 * Exception of web.framework - no page (404)
 * @subpackage exceptions
 */
class WF_Exception404 extends Exception {}
?>
Return current item: web.framework