Exemple #1
0
 public function __call($method, $args)
 {
     //在远程调用配置里面的接口走远程调用
     if (isset($this->conf['#all']) || isset($this->conf[$method])) {
         $conf = isset($this->conf['#all']) ? $this->conf['#all'] : $this->conf[$method];
         $rpc = new PI_RPC();
         return $rpc->call($method, $args, $this->mod, $this->add, $conf);
     } else {
         pi_load_export_file($this->mod, $this->add);
         if (!is_callable(array($this->instance, $method))) {
             throw new Exception("proxy.err {$mod} {$add} no method {$method}", 5009);
         }
         return pi_call_method($this->instance, $method, $args);
     }
 }
Exemple #2
0
 public function dispatch()
 {
     $mod_name = Conf::get("global.mod", 'mod');
     $func_name = Conf::get("global.func", 'func');
     $mod_seg = Conf::get("global.mod_seg", '/');
     $api_path = Conf::get("global.base_path", APP_ROOT . APP_NAME . DOT . 'logic' . DOT);
     $mod = Comm::Req($mod_name);
     $func = Comm::Req($func_name);
     $mod = explode($mod_seg, $mod);
     $pattern = '/^[0-9a-zA-Z\\/]*$/';
     $class = '';
     if (!empty($mod)) {
         foreach ($mod as $k => $m) {
             if (empty($m) || !is_string($m)) {
                 if (!preg_match($pattern, $m)) {
                     $this->output('api.err error format mod:' . $m, 1005);
                 }
                 unset($mod[$k]);
             }
             $mod[$k] = strtolower($m);
             $class .= ucfirst($mod[$k]);
         }
     }
     if (empty($mod)) {
         $this->output('api.err empty api mod:' . $mod, 1006);
     }
     if (empty($func) || !is_string($func) || !preg_match($pattern, $func)) {
         $this->output('api.err empty or error api func:' . $func, 1007);
     }
     Pi::inc(PI_CORE . 'BaseApi.php');
     $file = $api_path . implode(DOT, $mod) . DOT . $class . '.api.php';
     if (!is_readable($file) || !Pi::inc($file)) {
         $this->output('api.err api router can not load file:' . $file, 1008);
     }
     if (!class_exists($class)) {
         $this->output('api.err api router not find class:' . $class, 1009);
     }
     $cls = new $class();
     if (!is_subclass_of($cls, 'BaseApi')) {
         $this->output('api.err is not the subclass of BaseApi', 1010);
     }
     if (!is_callable(array($cls, $func))) {
         $this->output('api.err api class:' . $class . ' can not call method:' . $func, 1011);
     }
     $res = pi_call_method($cls, $func);
     $this->output($res);
 }
Exemple #3
0
 public function dispatch($url = null, $domain = '')
 {
     //正常逻辑保证按照目录逻辑加载,需要美化url用path_info传递参数的需要自定义路由配置(保持高效)
     //ajax自动去掉第一层,然后按照路径加载,二级域名去掉第一层,给域名定义alias配置,否则按照二级域名寻找
     if ($url != null) {
         $this->customRouter($url, $domain);
     }
     $uri = empty($this->uri) ? array() : explode('/', $this->uri);
     //如果没有任何path info,走默认配置,没有配置改成index
     if (empty($uri)) {
         $this->mod = array(Conf::get('global.main_page', 'index'));
         $this->func = Conf::get('global.main_func', 'index');
     } else {
         if (count($uri) == 1 && !empty($uri[0])) {
             $this->mod = array($uri[0]);
             $this->func = Conf::get('global.main_func', 'index');
         } else {
             $this->func = array_pop($uri);
             $this->mod = $uri;
         }
     }
     //保护不让访问的页面
     if (isset($this->prtected[$this->func])) {
         throw new Exception('router.err can not reach the protected ctr', 1021);
     }
     $mod_path = '';
     $cls = '';
     foreach ($this->mod as $mod) {
         $mod_path = $mod_path . $mod . DOT;
         $cls = $cls . ucfirst($mod);
     }
     $cls = $this->class_pre . $cls . "Ctr";
     $file_path = $this->base_path . $mod_path . $cls . '.php';
     if (!is_readable($file_path) || !Pi::inc($file_path)) {
         throw new Exception('router.err not found the router file : ' . $file_path, 1022);
     }
     if (!class_exists($cls)) {
         throw new Exception('router.err not found the router class: ' . $cls, 1023);
     }
     //执行
     $class = new $cls();
     try {
         pi_call_method($class, '_p_before');
         pi_call_method($class, 'initTmpl');
         pi_call_method($class, 'setRouter', array($this));
         if ($this->class_pre === 'Ajax') {
             pi_call_method($class, 'setAjax', array(true));
         }
         pi_call_method($class, '_before');
         if (substr($this->func, 0, 1) == '_' || !is_callable(array($class, $this->func))) {
             throw new Exception('router.err not ' . $cls . ' can not call : ' . $this->func, 1025);
         }
         pi_call_method($class, $this->func);
         pi_call_method($class, '_after');
         pi_call_method($class, '_p_after');
     } catch (Exception $ex) {
         pi_call_method($class, '_after');
         pi_call_method($class, '_p_after');
         throw $ex;
     }
 }