コード例 #1
0
ファイル: dao.init.php プロジェクト: superbogy/initphp
 /**
  * 运行nosql
  * $this->getNosql()
  */
 public function run_nosql()
 {
     if ($this->nosql == NULL) {
         $this->nosql = InitPHP::loadclass('NosqlInit');
     }
     return $this->nosql;
 }
コード例 #2
0
ファイル: dao.init.php プロジェクト: pwstrick/grape
 /**
  * 运行search
  */
 public function run_search()
 {
     if ($this->search == NULL) {
         require INITPHP_PATH . "/core/dao/search/search.init.php";
         $this->search = InitPHP::loadclass('searchInit');
     }
     return $this->search;
 }
コード例 #3
0
ファイル: dao.init.php プロジェクト: peterlevel1/haha-9
 /**
  * 运行nosql
  * $this->getNosql()
  */
 public function run_nosql()
 {
     if ($this->nosql == NULL) {
         require INITPHP_PATH . "/core/dao/nosql/nosql.init.php";
         $this->nosql = InitPHP::loadclass('nosqlInit');
     }
     return $this->nosql;
 }
コード例 #4
0
ファイル: InterceptorInit.php プロジェクト: superbogy/initphp
 /**
  * 具体解析
  * @param unknown_type $isPre
  */
 private function parse($isPre = true)
 {
     $InitPHP_conf = InitPHP::getConfig();
     $interceptor = $InitPHP_conf['interceptor'];
     $filePath = $interceptor['path'];
     //文件路径
     $return = true;
     if (is_array($interceptor['rule']) && count($interceptor['rule']) > 0) {
         foreach ($interceptor['rule'] as $k => $v) {
             $file = ltrim($filePath, "/") . "/" . $v['file'] . $interceptor['postfix'] . '.php';
             $class = $v['file'] . $interceptor['postfix'];
             //处理正则匹配
             $regular = $v['regular'];
             if ($regular['m'] != "" && $regular['m'] != '*') {
                 if (!preg_match($regular['m'], $this->m)) {
                     continue;
                 }
             }
             if ($regular['c'] != "" && $regular['c'] != '*') {
                 if (!preg_match($regular['c'], $this->c)) {
                     continue;
                 }
             }
             if ($regular['a'] != "" && $regular['a'] != '*') {
                 if (!preg_match($regular['a'], $this->a)) {
                     continue;
                 }
             }
             if (file_exists(InitPHP::getAppPath($file))) {
                 InitPHP::import($file);
                 $obj = InitPHP::loadclass($class);
                 if ($isPre == true) {
                     $ret = $obj->preHandle();
                     if ($ret == false) {
                         $return = false;
                         break;
                     }
                 } else {
                     $obj->postHandle();
                 }
             }
         }
     }
     return $return;
 }
コード例 #5
0
ファイル: dbhandler.init.php プロジェクト: superbogy/initphp
 /**
  * 获取数组引擎对象
  * @param string $driver  暂时只支持mysql
  * @return object
  */
 private function get_db_driver($driver)
 {
     $file = $driver . '.Init.php';
     $class = $driver . 'Init';
     require INITPHP_PATH . '/core/Dao/Db/Driver/' . $file;
     return InitPHP::loadclass($class);
 }
コード例 #6
0
ファイル: initphp.php プロジェクト: peterlevel1/haha-9
 /**
  * 调用其它Controller中的方法
  * 1. 一般不建议采用Controller调用另外一个Controller中的方法
  * 2. 该函数可以用于接口聚集,将各种接口聚集到一个接口中使用
  * 全局使用方法:InitPHP::getController($controllerName, $functionName)
  * @param $controllerName 控制器名称
  * @param $functionName   方法名称
  * @param $params         方法参数
  * @param $controllerPath 控制器文件夹名称,例如在控制器文件夹目录中,还有一层目录,user/则,该参数需要填写
  * @return
  */
 public static function getController($controllerName, $functionName, $params = array(), $controllerPath = '')
 {
     $InitPHP_conf = InitPHP::getConfig();
     $controllerPath = $controllerPath == '' ? '' : rtrim($controllerPath, '/') . '/';
     $path = rtrim($InitPHP_conf['controller']['path'], '/') . '/' . $controllerPath . $controllerName . '.php';
     if (!InitPHP::import($path)) {
         $controllerName = ucfirst($controllerName);
         $path = rtrim($InitPHP_conf['controller']['path'], '/') . '/' . $controllerPath . $controllerName . '.php';
         InitPHP::import($path);
     }
     $controller = InitPHP::loadclass($controllerName);
     if (!$controller) {
         return InitPHP::initError('can not loadclass : ' . $controllerName);
     }
     if (!method_exists($controller, $functionName)) {
         return InitPHP::initError('function is not exists : ' . $controllerName);
     }
     if (!$params) {
         $controller->{$functionName}();
     } else {
         call_user_func_array(array($controller, $functionName), $params);
     }
 }
コード例 #7
0
 /**
  *	获取运行的service
  *  @return object
  */
 private function get_service_obj()
 {
     $InitPHP_conf = InitPHP::getConfig();
     $test_file_name = $this->classname . $InitPHP_conf['service']['service_postfix'];
     if (InitPHP::import("{$test_file_name}" . ".php", array($InitPHP_conf['service']['path']))) {
         return InitPHP::loadclass($test_file_name);
     }
     return false;
 }
コード例 #8
0
ファイル: run.init.php プロジェクト: pwstrick/grape
 /**
  * 验证请求是否合法
  * 1. 如果请求参数m,c,a都为空,则走默认的
  */
 private function checkRequest()
 {
     $InitPHP_conf = InitPHP::getConfig();
     $controller = isset($_GET['c']) ? $_GET['c'] : '';
     $action = isset($_GET['a']) ? $_GET['a'] : '';
     if ($InitPHP_conf['ismodule'] == true) {
         $module = isset($_GET['m']) ? $_GET['m'] : '';
         if ($module == "" && $controller == "" && $action == "") {
             $module = $_GET['m'] = $this->default_module;
             $controller = $_GET['c'] = $this->default_controller;
             $action = $_GET['a'] = $this->default_action;
         }
         //如果module不在白名单中,则直接返回404
         if (!in_array($module, $this->module_list) || empty($module)) {
             return InitPHP::return404();
         }
         $module = $module . '/';
     } else {
         if ($controller == "" && $action == "") {
             $controller = $_GET['c'] = $this->default_controller;
             $action = $_GET['a'] = $this->default_action;
         }
         $module = '';
     }
     //controller处理,如果导入Controller文件失败,则返回404
     $path = rtrim($InitPHP_conf['controller']['path'], '/') . '/';
     $controllerClass = $controller . $this->controller_postfix;
     $controllerFilePath = $path . $module . $controllerClass . '.php';
     if (!InitPHP::import($controllerFilePath)) {
         //如果开启了首字母大写,例如请求c=my,则类名为MyController
         $controllerClass = ucfirst($controller) . $this->controller_postfix;
         //改成大写
         $controllerFilePath = $path . $module . $controllerClass . '.php';
         if (!InitPHP::import($controllerFilePath)) {
             return InitPHP::return404();
         }
     }
     $controllerObj = InitPHP::loadclass($controllerClass);
     //处理Action,如果方法不存在,则直接返回404
     list($whiteList, $methodList) = $this->parseWhiteList($controllerObj->initphp_list);
     if ($action != $this->default_action) {
         if (!in_array($action, $whiteList)) {
             return InitPHP::return404();
             //如果Action不在白名单中
         } else {
             if ($methodList[$action]) {
                 $method = strtolower($_SERVER['REQUEST_METHOD']);
                 if (!in_array($method, $methodList[$action])) {
                     //检查提交的HTTP METHOD
                     return InitPHP::return405();
                     //如果请求Method不正确,则返回405
                 }
             }
         }
     }
     return $controllerObj;
 }