Example #1
0
 /**
  * @return APF_DB_Factory
  */
 public static function &get_instance()
 {
     if (!self::$instance) {
         self::$instance = new MPF_DB_Factory();
     }
     return self::$instance;
 }
Example #2
0
 /**
  * 框架真正的主方法。依次执行各个拦截器的before方法、控制器方法、拦截器逆序after方法,
  * 以及页面方法。最后做清理工作。
  */
 public function dispatch()
 {
     $class = $this->router->mapping();
     $controller = $this->get_controller($class);
     if (!$controller) {
         return false;
     }
     $this->current_controller = $controller;
     $interceptores = @$this->get_config($class, "interceptor");
     if ($interceptores) {
         $interceptor_classes = $this->get_interceptor_classes($class);
     } else {
         $basic_class = $controller->get_interceptor_index_name();
         $interceptor_classes = $this->get_interceptor_classes($basic_class);
     }
     $step = MPF_Interceptor::STEP_CONTINUE;
     foreach ($interceptor_classes as $interceptor_class) {
         $interceptor = $this->load_interceptor($interceptor_class);
         if (!$interceptor) {
             continue;
         }
         $interceptors[] = $interceptor;
         $this->debug("interceptor::before(): " . get_class($interceptor));
         $step = $interceptor->before();
         if ($step != MPF_Interceptor::STEP_CONTINUE) {
             break;
         }
     }
     if (!$this->is_debug_enabled()) {
         unset($this->debug_config);
         $this->trace_config = false;
     }
     if ($step != MPF_Interceptor::STEP_EXIT) {
         while (true) {
             $this->debug("controller::handle_request(): " . get_class($controller));
             $this->benchmark_begin("controller::handle_request(): " . get_class($controller));
             // 标记控制器执行开始
             $this->pf_benchmark_begin("controller");
             $result = $controller->handle_request();
             // 标记控制器执行结束
             $this->pf_benchmark_end("controller");
             $this->benchmark_end("controller::handle_request(): " . get_class($controller));
             if ($result instanceof MPF_Controller) {
                 $controller = $result;
                 continue;
             }
             break;
         }
         if (is_string($result)) {
             if (class_exists('MPF_DB_Factory', false)) {
                 MPF_DB_Factory::get_instance()->close_pdo_all();
             }
             // 标记页面开始
             $this->pf_benchmark_begin("page");
             $this->page($result);
             // 标记页面结束
             $this->pf_benchmark_end("page");
         }
     }
     $step = MPF_Interceptor::STEP_CONTINUE;
     if (isset($interceptors)) {
         $interceptors = array_reverse($interceptors);
         foreach ($interceptors as $interceptor) {
             $step = $interceptor->after();
             $this->debug("interceptor::after(): " . get_class($interceptor));
             if ($step != MPF_Interceptor::STEP_CONTINUE) {
                 break;
             }
         }
     }
     return true;
 }
Example #3
0
 protected function get_connection($con_name)
 {
     if (array_key_exists($con_name, self::$connections)) {
         return self::$connections[$con_name];
     }
     mpf_require_class("MPF_DB_Factory");
     $con = MPF_DB_Factory::get_instance()->get_pdo($con_name);
     if (self::$auto_commit === false) {
         $con->beginTransaction();
     }
     self::$connections[$con_name] = $con;
     return $con;
 }