Ejemplo n.º 1
0
 /**
  * initialize the given request and some properties of the coordinator
  *
  * It extracts information for the request to set the module name and the
  * action name. It doesn't verify if the corresponding controller does
  * exist or not.
  * It enables also the error handler of Jelix, if needed.
  * Does not call this method directly in entry points. Prefer to call
  * process() instead (that will call setRequest). 
  * setRequest is mostly used for tests or specific contexts.
  * @param  jRequest  $request the request object
  * @throw jException if the module is unknown or the action name format is not valid
  * @see jCoordinator::process()
  */
 protected function setRequest($request)
 {
     $config = jApp::config();
     $this->request = $request;
     if ($config->enableErrorHandler) {
         set_error_handler(array($this, 'errorHandler'));
         set_exception_handler(array($this, 'exceptionHandler'));
         // let's log messages appeared during init
         foreach (jBasicErrorHandler::$initErrorMessages as $msg) {
             jLog::log($msg, $msg->getCategory());
         }
     }
     $this->request->init();
     list($this->moduleName, $this->actionName) = $request->getModuleAction();
     jApp::pushCurrentModule($this->moduleName);
     $this->action = $this->originalAction = new jSelectorActFast($this->request->type, $this->moduleName, $this->actionName);
     if ($config->modules[$this->moduleName . '.access'] < 2) {
         throw new jException('jelix~errors.module.untrusted', $this->moduleName);
     }
 }
Ejemplo n.º 2
0
 /**
  * main method : launch the execution of the action.
  *
  * This method should be called in a entry point.
  * @param  jRequest  $request the request object
  */
 public function process($request)
 {
     global $gJConfig;
     $this->request = $request;
     // let's log messages appeared during init
     foreach ($this->initErrorMessages as $msg) {
         jLog::log($msg, $msg->getCategory());
     }
     $this->request->init();
     jSession::start();
     $this->moduleName = $request->getParam('module');
     $this->actionName = $request->getParam('action');
     if (empty($this->moduleName)) {
         $this->moduleName = $gJConfig->startModule;
     }
     if (empty($this->actionName)) {
         if ($this->moduleName == $gJConfig->startModule) {
             $this->actionName = $gJConfig->startAction;
         } else {
             $this->actionName = 'default:index';
         }
     }
     jContext::push($this->moduleName);
     try {
         $this->action = new jSelectorActFast($this->request->type, $this->moduleName, $this->actionName);
         if ($gJConfig->modules[$this->moduleName . '.access'] < 2) {
             throw new jException('jelix~errors.module.untrusted', $this->moduleName);
         }
         $ctrl = $this->getController($this->action);
     } catch (jException $e) {
         if ($gJConfig->urlengine['notfoundAct'] == '') {
             throw $e;
         }
         try {
             $this->action = new jSelectorAct($gJConfig->urlengine['notfoundAct']);
             $ctrl = $this->getController($this->action);
         } catch (jException $e2) {
             throw $e;
         }
     }
     if (count($this->plugins)) {
         $pluginparams = array();
         if (isset($ctrl->pluginParams['*'])) {
             $pluginparams = $ctrl->pluginParams['*'];
         }
         if (isset($ctrl->pluginParams[$this->action->method])) {
             $pluginparams = array_merge($pluginparams, $ctrl->pluginParams[$this->action->method]);
         }
         foreach ($this->plugins as $name => $obj) {
             $result = $this->plugins[$name]->beforeAction($pluginparams);
             if ($result) {
                 $this->action = $result;
                 jContext::pop();
                 jContext::push($result->module);
                 $this->moduleName = $result->module;
                 $this->actionName = $result->resource;
                 $ctrl = $this->getController($this->action);
                 break;
             }
         }
     }
     $this->response = $ctrl->{$this->action->method}();
     if ($this->response == null) {
         throw new jException('jelix~errors.response.missing', $this->action->toString());
     }
     foreach ($this->plugins as $name => $obj) {
         $this->plugins[$name]->beforeOutput();
     }
     $this->response->output();
     foreach ($this->plugins as $name => $obj) {
         $this->plugins[$name]->afterProcess();
     }
     jContext::pop();
     jSession::end();
 }