Example #1
0
 public function __construct()
 {
     $dispatcher = Pcf::get('global.dispatcher_path', PIPE_HELPER . 'RouteDispatcher.php');
     if (!Pi::inc($dispatcher)) {
         throw new Exception('can not find the dispatcher config : global.dispatcher_path', 1032);
     }
 }
Example #2
0
File: Web.php Project: hihus/pi
 protected function initTemplate()
 {
     $views = Pcf::get('global.view_lib_path');
     $views = PI_UTIL . $views;
     if (!Pi::inc($views)) {
         die('can not find the web view libs ');
     }
     $cls = Pcf::get('global.view_engine');
     if (!class_exists($cls)) {
         die('can not init the template engine class');
     }
 }
Example #3
0
 public function dispatch()
 {
     if (!$this->checkSign()) {
         $this->output('api.err sign', 7099);
     }
     $mod_name = Pcf::get("global.mod", 'mod');
     $func_name = Pcf::get("global.func", 'func');
     $mod_seg = Pcf::get("global.mod_seg", '/');
     $api_path = Pcf::get("global.base_path", PI_APP_ROOT . PI_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 (!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, 'PiBaseApi')) {
         $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::piCallMethod($cls, $func);
     return $res;
 }
Example #4
0
 public function execute(PiApp $app)
 {
     $this->app = $app;
     $router = Pcf::get('global.router_file', 'ApiRouter.php');
     $router_class = Pcf::get('global.router_class', 'PiApiRouter');
     if (!Pi::inc(PIPE_HELPER . $router)) {
         throw new Exception('api.router can not find the api router : ' . $router, 1030);
     }
     if (class_exists($router_class)) {
         $cls = new $router_class($app);
         $res = $cls->dispatch();
         //线上环境请处理输出做加密
         $cls->output($res);
     } else {
         throw new Exception('api.router can not find the router class : ' . $router_class, 1031);
     }
 }
Example #5
0
File: Api.php Project: hihus/pi
 public function __construct($argv = array())
 {
     if (!defined("PI_APP_NAME")) {
         die("app.err please define PI_APP_NAME const \n");
     }
     $this->mode = 'api';
     $this->app_env = Pi::get('app_env', '');
     $this->com_env = Pi::get('com_env', '');
     $data_type = Pcf::get("global.data_type", 'json');
     if (isset($this->data_types[$data_type])) {
         $this->data_type = $data_type;
     }
     parent::__construct();
     if (true === $this->debug && php_sapi_name() == 'cli') {
         $mod_name = Pcf::get("global.mod", 'mod');
         $func_name = Pcf::get("global.func", 'func');
         Comm::setReq($mod_name, $argv[1]);
         Comm::setReq($func_name, $argv[2]);
     }
 }
Example #6
0
File: Task.php Project: hihus/pi
 public function run()
 {
     //初始化pipe
     $default_pipe = array('TaskProcessPipe' => 'default');
     $pipes = Pcf::get('global.pipes', array());
     if (empty($pipes)) {
         $pipes = $default_pipe;
     }
     $this->pipeLoadContainer = $pipes;
     //后台脚本方便日志记录,把所有输出全部定位到日志目录
     ob_start();
     echo "\n---------------------" . date("Y-m-d H:i:s") . "--------------------\n";
     echo "\nrun result:\n";
     $this->timer->begin('task_run');
     parent::run();
     $this->timer->end('task_run');
     $time = $this->timer->getResult();
     echo "\nrun time : " . $time[0]['1'] / 1000 . " s \n";
     echo "\n---------------------" . date("Y-m-d H:i:s") . "--------------------\n";
     $res = ob_get_clean();
     Logger::trace("%s", var_export($res, true));
 }
Example #7
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(Pcf::get('global.main_page', 'index'));
         $this->func = Pcf::get('global.main_func', 'index');
     } else {
         if (count($uri) == 1 && !empty($uri[0])) {
             $this->mod = array($uri[0]);
             $this->func = Pcf::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 (!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();
     if (!is_subclass_of($class, 'PiPageCtr')) {
         throw new Exception('router.err class : ' . $cls . 'is not the subclass of PiPageCtr', 1023);
     }
     try {
         Pi::piCallMethod($class, '_p_before');
         Pi::piCallMethod($class, 'initTmpl');
         Pi::piCallMethod($class, 'setRouter', array($this));
         if ($this->class_pre === 'Ajax') {
             Pi::piCallMethod($class, 'setAjax', array(true));
         }
         Pi::piCallMethod($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::piCallMethod($class, $this->func);
         Pi::piCallMethod($class, '_after');
         Pi::piCallMethod($class, '_p_after');
     } catch (Exception $ex) {
         Pi::piCallMethod($class, '_after');
         Pi::piCallMethod($class, '_p_after');
         throw $ex;
     }
 }
Example #8
0
File: PageCtr.php Project: hihus/pi
 public function initTmpl()
 {
     $view_path = Pcf::get('global.view_path', PI_APP_ROOT . 'view/views/');
     $view_cache_path = Pcf::get('global.view_cache_path', PI_APP_ROOT . 'view/cache/');
     $view_compile_path = Pcf::get('global.view_compile_path', PI_APP_ROOT . 'view/views_c/');
     if (null == $this->tpl) {
         $cls = Pcf::get('global.view_engine');
         $this->tpl = new $cls();
         $this->tpl->setTemplateDir($view_path);
         $this->tpl->setCompileDir($view_compile_path);
         $this->tpl->setCacheDir($view_cache_path);
         $this->tpl->left_delimiter = '<{';
         $this->tpl->right_delimiter = '}>';
     }
 }
Example #9
0
File: Pi.php Project: hihus/pi
 protected function needToLog($code)
 {
     $core_no_need_log_code = Pcf::get('global.nolog_exception', array());
     $app_no_need_log_code = Pi::get('global.nolog_exception', array());
     if (isset($core_no_need_log_code[$code]) || isset($app_no_need_log_code[$code])) {
         return false;
     }
     return true;
 }
Example #10
0
<?php

//路由名字的首尾不加下划线!
Pcf::set('route.custom_router', array('login/(:p)' => array('url' => 'login/index', 'p' => array('userid')), 'index/(:p)' => array('url' => 'index/index', 'p' => array('userid')), '(:p)' => array('url' => 'index/index', 'p' => array('userid')), 'search/login/(:p)/new' => array('url' => 'index/index', 'p' => array('userid'))));
Example #11
0
<?php

//全局web配置
Pcf::set('global.view_lib_path', 'views/smarty-3.1.27/libs/Smarty.class.php');
Pcf::set('global.view_engine', 'Smarty');
Pcf::set('global.view_path', PI_APP_ROOT . PI_APP_NAME . '/views/');
//Pcf::set('global.dispatcher_path',PI_CORE.'RouteDispatcher.php');
Pcf::set('global.nolog_exception', array(1022 => 1, 1025 => 1));