Example #1
0
 /**
  * Create URI object which determines dispatch method and
  * perform dispatch
  *
  * @param bool $fake
  *
  * @return void
  */
 public function dispatch($fake = false)
 {
     $this->uri = new URI($this->defaultModule, $this->dynamicModule);
     $error = $this->uri->getError();
     if ($error == URI::MISSING_CLASS && isset($this->dynamicModule) && $this->dynamicModule != '') {
         $error = $this->uri->dynamicSection();
     }
     if ($error > 0) {
         if ($this->environment == 'prod' || $this->debug_mode == false) {
             if ($error == URI::MISSING_CLASS || $error == URI::MISSING_EVENT_DEF || $error == URI::ERROR_404) {
                 throw new RequestException('Not found', RequestException::NOT_FOUND);
             }
         } else {
             throw new Exception('Dispatch error ' . $error . ' : ' . $this->uri->getErrorMessage());
         }
     }
     $controller_name = $this->uri->getControllerName();
     $this->controller = new $controller_name($this);
     $this->plugin_manager->preEvent();
     if ($fake == false) {
         $event_val = $this->controller->{$_GET}['event']();
         if ($this->mvc->hasErrors()) {
             throw new ErrorException($this->mvc->errorsToString());
         } elseif ($event_val !== false) {
             if ($this->uri->getInternal()) {
                 $this->controller->setTemplate('empathy.tpl');
                 $this->display(true);
             } else {
                 $this->display(false);
             }
         }
     }
 }
Example #2
0
 /**
  * Performm request to mvc using active method.
  *
  * @param Empathy $e   MVC boot object
  * @param string  $uri URI of request 
  *
  * @return float/string/Controller
  */
 public static function request($e, $uri)
 {
     switch (self::$_reqMode) {
         case CLIMode::TIMED:
             $t_request_start = self::_realMicrotime();
             $_SERVER['REQUEST_URI'] = $uri;
             ob_start();
             $e->beginDispatch();
             $t_request_finish = self::_realMicrotime();
             ob_end_clean();
             $t_elapsed = $t_request_finish - $t_request_start;
             $t_elapsed = number_format($t_elapsed, 4);
             self::_requestEnd();
             return $t_elapsed;
             break;
         case CLIMode::CAPTURED:
             ob_start();
             $_SERVER['REQUEST_URI'] = $uri;
             $e->beginDispatch();
             $response = ob_get_contents();
             ob_end_clean();
             self::_requestEnd();
             return $response;
             break;
         case CLIMode::FAKED:
             ob_start();
             $_SERVER['REQUEST_URI'] = $uri;
             $controller = $e->beginDispatch(true);
             ob_end_clean();
             self::_requestEnd();
             return $controller;
             break;
         case CLIMode::STREAMED:
             $_SERVER['REQUEST_URI'] = $uri;
             $e->beginDispatch();
             break;
         default:
             break;
     }
 }