/**
 Static function to use to init database layer. Returns a object extending
 dbLayer.
 
 @param	driver		<b>string</b>		Driver name
 @param	host			<b>string</b>		Database hostname
 @param	database		<b>string</b>		Database name
 @param	user			<b>string</b>		User ID
 @param	password		<b>string</b>		Password
 @param	persistent	<b>boolean</b>		Persistent connection (false)
 @return	<b>object</b>
 */
 public static function init($driver, $host, $database, $user = '', $password = '', $persistent = false)
 {
     $driver = Camelizer::firstToUpper($driver);
     if (file_exists(dirname(__FILE__) . '/' . $driver . 'TransConnection.class.php')) {
         require_once dirname(__FILE__) . '/' . $driver . 'TransConnection.class.php';
         $driver_class = $driver . 'TransConnection';
     } else {
         trigger_error('Unable to load DB layer for ' . $driver, E_USER_ERROR);
         exit(1);
     }
     return new $driver_class($host, $database, $user, $password, $persistent);
 }
 public function execute()
 {
     // get the controller
     $controllerClass = $this->getControllerClass();
     if (class_exists($controllerClass)) {
         // namespaced?
         $module = new $controllerClass();
     } else {
         if (($str = substr($controllerClass, 1)) && class_exists($str)) {
             // non namespaced?
             $module = new $str();
         } else {
             throw new ActionEnforcingException('Controller "' . $controllerClass . '" could not be loaded.', $this->context->getModuleName(), $this->context->getActionName());
         }
     }
     // get the action, module, extension of the action
     $extensionId = $this->context->getExtensionName();
     $moduleName = $this->context->getModuleName() ? Camelizer::firstToUpper($this->context->getModuleName()) : DEFAULT_MODULE_NAME;
     $action = $this->context->getActionName() ? Camelizer::firstToLower($this->context->getActionName()) : DEFAULT_ACTION_NAME;
     // Are we authorized to execute this action?
     $requestParameters = $this->context->getRequest()->getParameters();
     if (!tao_models_classes_accessControl_AclProxy::hasAccess($action, $moduleName, $extensionId, $requestParameters)) {
         $userUri = common_session_SessionManager::getSession()->getUserUri();
         throw new tao_models_classes_AccessDeniedException($userUri, $action, $moduleName, $extensionId);
     }
     // if the method related to the specified action exists, call it
     if (method_exists($module, $action)) {
         $this->context->setActionName($action);
         // search parameters method
         $reflect = new ReflectionMethod($module, $action);
         $parameters = $reflect->getParameters();
         $tabParam = array();
         foreach ($parameters as $param) {
             $tabParam[$param->getName()] = $this->context->getRequest()->getParameter($param->getName());
         }
         // Action method is invoked, passing request parameters as
         // method parameters.
         common_Logger::d('Invoking ' . get_class($module) . '::' . $action, array('GENERIS', 'CLEARRFW'));
         call_user_func_array(array($module, $action), $tabParam);
         // Render the view if selected.
         if ($module->hasView()) {
             $renderer = $module->getRenderer();
             echo $renderer->render();
         }
     } else {
         throw new ActionEnforcingException("Unable to find the action '" . $action . "' in '" . get_class($module) . "'.", $this->context->getModuleName(), $this->context->getActionName());
     }
 }
 /**
  * Constructor. Please use only getInstance to retrieve the single instance.
  * 
  * @see Context#getInstance
  */
 private function __construct()
 {
     $this->request = new Request();
     $this->response = new Response();
     $this->viewData = array();
     $this->behaviors = array();
     if (PHP_SAPI != 'cli') {
         try {
             $resolver = new Resolver();
             $this->extensionName = $resolver->getExtensionFromURL();
             $this->moduleName = Camelizer::firstToUpper($resolver->getModule());
             $this->actionName = Camelizer::firstToLower($resolver->getAction());
         } catch (ResolverException $re) {
             $this->extensionName = 'tao';
         }
     }
 }
Example #4
0
 public function __construct()
 {
     if (PHP_SAPI != 'cli') {
         try {
             $resolver = new Resolver();
             $this->extension = $resolver->getExtensionFromURL();
             $this->module = Camelizer::firstToUpper($resolver->getModule());
             $this->action = Camelizer::firstToLower($resolver->getAction());
         } catch (ResolverException $re) {
             $this->extension = 'tao';
         }
     }
     $this->epoch = time();
     $this->user = common_session_SessionManager::getSession()->getUserUri();
     $this->script = $_SERVER['PHP_SELF'];
     $this->system = new common_profiler_System();
 }
 /**
  * Load module
  */
 function loadModule()
 {
     $action = $this->httpRequest->getAction();
     $module = $this->httpRequest->getModule();
     # load default module
     if ($module === null && $action === null) {
         $defaut = new Defaut();
         $defaut->index();
         exit;
     }
     $action = Camelizer::firstToUpper($action);
     $module = Camelizer::firstToUpper($module);
     // if module exist include the class
     if ($module !== null) {
         if (($path = $this->getPath($module)) !== null) {
             require_once $path . $module . ".class.php";
         } else {
             throw new Exception(__("No file found"));
         }
         $moduleController = new $module();
     } else {
         throw new Exception(__("No module"));
     }
     // if method exist call it
     if (method_exists($moduleController, $action)) {
         // search parameters method
         $reflect = new ReflectionMethod($module, $action);
         $parameters = $reflect->getParameters();
         $tabParam = array();
         foreach ($parameters as $param) {
             $tabParam[$param->getName()] = $this->httpRequest->getArgument($param->getName());
         }
         call_user_func_array(array(new $module(), $action), $tabParam);
     } else {
         throw new Exception(__("No action"));
     }
 }
 public function execute()
 {
     $module = $this->context->getModuleName();
     $action = $this->context->getActionName();
     // if module exist include the class
     if ($module !== null) {
         //    		//check if there is a specified context first
         //			$isSpecificContext = false;
         //    		if(count($this->context->getSpecifiers()) > 0){
         //				foreach($this->context->getSpecifiers() as $specifier){
         //
         //					$expectedPath = DIR_ACTIONS . $specifier . '/class.' . $module . '.php';
         //
         //					//if we find the view in the specialized context, we load it
         //					if (file_exists($expectedPath)){
         //						require_once ($expectedPath);
         //						$isSpecificContext = true;
         //						break;
         //					}
         //				}
         //			}
         //
         //			//if there is none, we look at the global context
         //			if(!$isSpecificContext){
         $exptectedPath = DIR_ACTIONS . 'class.' . $module . '.php';
         if (file_exists($exptectedPath)) {
             require_once $exptectedPath;
         } else {
             throw new ActionEnforcingException("Module '" . Camelizer::firstToUpper($module) . "' does not exist in {$exptectedPath}.", $this->context->getModuleName(), $this->context->getActionName());
         }
         //			}
         if (defined('ROOT_PATH')) {
             $root = realpath(ROOT_PATH);
         } else {
             $root = realpath($_SERVER['DOCUMENT_ROOT']);
         }
         if (preg_match("/^\\//", $root) && !preg_match("/\\/\$/", $root)) {
             $root .= '/';
         } else {
             if (!preg_match("/\\\$/", $root)) {
                 $root .= '\\';
             }
         }
         $relPath = str_replace($root, '', realpath(dirname($exptectedPath)));
         $relPath = str_replace('/', '_', $relPath);
         $relPath = str_replace('\\', '_', $relPath);
         $className = $relPath . '_' . $module;
         if (!class_exists($className)) {
             throw new ActionEnforcingException("Unable to load  {$className} in {$exptectedPath}", $this->context->getModuleName(), $this->context->getActionName());
         }
         // File gracefully loaded.
         $this->context->setModuleName($module);
         $this->context->setActionName($action);
         $moduleInstance = new $className();
     } else {
         throw new ActionEnforcingException("No Module file matching requested module.", $this->context->getModuleName(), $this->context->getActionName());
     }
     // if the method related to the specified action exists, call it
     if (method_exists($moduleInstance, $action)) {
         // search parameters method
         $reflect = new ReflectionMethod($className, $action);
         $parameters = $reflect->getParameters();
         $tabParam = array();
         foreach ($parameters as $param) {
             $tabParam[$param->getName()] = $this->context->getRequest()->getParameter($param->getName());
         }
         // Action method is invoked, passing request parameters as
         // method parameters.
         common_Logger::d('Invoking ' . get_class($moduleInstance) . '::' . $action, array('GENERIS', 'CLEARRFW'));
         call_user_func_array(array($moduleInstance, $action), $tabParam);
         // Render the view if selected.
         if ($view = $moduleInstance->getView()) {
             $renderer = new Renderer();
             $renderer->render($view);
         }
     } else {
         throw new ActionEnforcingException("Unable to find the appropriate action for Module '{$module}'.", $this->context->getModuleName(), $this->context->getActionName());
     }
 }