Exemplo n.º 1
0
Arquivo: Web.php Projeto: xtzlyp/newpi
 public function run()
 {
     //初始化pipe
     $default_pipe = array('WebReqPipe' => 'default', 'WebRouterPipe' => 'default');
     $pipes = Pi::get('global.pipes', array());
     if (empty($pipes)) {
         $pipes = $default_pipe;
     }
     $this->pipeLoadContainer = $pipes;
     parent::run();
 }
Exemplo n.º 2
0
 public static function getConfig($name)
 {
     $conf = Pi::get('cache.' . $name, array());
     if (empty($conf)) {
         return null;
     }
     foreach ($conf as $server) {
         if (!isset($server['host']) || !isset($server['port']) || !isset($server['port']) || !isset($server['pconnect'])) {
             return null;
         }
     }
     return $conf;
 }
Exemplo n.º 3
0
Arquivo: Task.php Projeto: hihus/newpi
 protected function _initLogger()
 {
     //获得log path
     if (!defined("LOG_PATH")) {
         define("LOG_PATH", Pi::get('log.path', ''));
     }
     if (!is_dir(LOG_PATH)) {
         die('pi.err can not find the log path');
     }
     Pi::inc(Pi::get('LogLib'));
     $logFile = $this->task_name;
     $logLevel = $this->debug === true ? Logger::LOG_DEBUG : Pi::get('log.level', Logger::LOG_TRACE);
     $roll = Pi::get('log.roll', Logger::DAY_ROLLING);
     $basic = array('logid' => $this->appId);
     Logger::init(LOG_PATH, $logFile, $logLevel, array(), $roll);
     Logger::addBasic($basic);
 }
Exemplo n.º 4
0
Arquivo: db.php Projeto: xtzlyp/newpi
 private static function getConfig($name)
 {
     $c = Pi::get('db.' . $name, null);
     $conf = array();
     if (empty($c) || !is_array($c)) {
         return null;
     }
     if (!isset($c['master']) && isset($c['slave'])) {
         $conf['master'] = $c['slave'];
     } else {
         if (!isset($c['master']) && !isset($c['slave'])) {
             $conf['master'] = $c;
         } else {
             $conf = $c;
         }
     }
     foreach ($conf as $k => $v) {
         if ($k != 'master' && $k != 'slave') {
             unset($conf[$k]);
             continue;
         }
         //端口默认 3306
         if (!isset($conf[$k]['port'])) {
             $conf[$k]['port'] = 3306;
         }
         //类型默认 mysql
         if (!isset($conf[$k]['database_type'])) {
             $conf[$k]['database_type'] = 'mysql';
         }
         //默认字符集
         if (!isset($conf[$k]['charset'])) {
             $conf[$k]['charset'] = 'utf8';
         }
         if (!isset($conf[$k]['prefix'])) {
             $conf[$k]['prefix'] = '';
         }
     }
     if (empty($conf)) {
         return null;
     }
     return $conf;
 }
Exemplo n.º 5
0
Arquivo: Api.php Projeto: hihus/pi
 public function run()
 {
     //内网api调用
     if ($this->checkInnerApi()) {
         //如果有其他调试输出忽略
         ob_start();
         define("USE_INNER_API", 1);
         Pi::inc(PI_CORE . 'Proxy.php');
         PiProxyServer::Server();
     } else {
         //初始化pipe
         $default_pipe = array('ApiReqPipe' => 'default', 'ApiHttpRouterPipe' => 'default');
         $pipes = Pi::get('global.pipes', array());
         if (empty($pipes)) {
             $pipes = $default_pipe;
         }
         $this->pipeLoadContainer = $pipes;
         parent::run();
     }
 }
Exemplo n.º 6
0
function picom($mod, $add = '', $is_server = false)
{
    $mod = strtolower($mod);
    $add = strtolower($add);
    //服务器端自身模块不再远程调用
    static $rpc_mod = array();
    if ($is_server !== false) {
        $rpc_mod[$mod] = 1;
    }
    //客户端是否走远程加载
    $rpc_conf = Pi::get('proxy.' . $mod, array());
    if (!empty($rpc_conf) && $is_server === false && !isset($rpc_mod[$mod])) {
        Pi::inc(PI_CORE . 'Proxy.php');
        $rpc = new PI_PRC($mod, $add, $rpc_conf);
        return $rpc;
    }
    if ($add == '') {
        $cls = ucfirst($mod) . 'Export';
        $file = EXPORT_ROOT . $mod . DOT . $cls . '.php';
    } else {
        if (is_string($add)) {
            $cls = ucfirst($mod) . ucfirst($add) . 'Export';
            $file = EXPORT_ROOT . $mod . DOT . $cls . '.php';
        } else {
            throw new Exception('picom can not find mod:' . $mod, ',add:' . $add, 1001);
        }
    }
    if (is_readable($file)) {
        Pi::inc($file);
        if (class_exists($cls)) {
            $class = new $cls();
            if (!is_subclass_of($class, 'Export')) {
                throw new Exception('the class ' . $cls . ' is not the subclass of Export', 1002);
            }
            return $class;
        } else {
            throw new Exception('can not find picom class ' . $cls . ' from ' . $file, 1003);
        }
    }
    throw new Exception('can not read mod file: ' . $file . ' from picom func', 1004);
}
Exemplo n.º 7
0
function picom($mod, $add = '', $is_server = false)
{
    $mod = strtolower($mod);
    $add = strtolower($add);
    //加载一次
    static $loaded_mod = array();
    if (isset($loaded_mod[$mod . $add])) {
        return $loaded_mod[$mod . $add];
    }
    //先检测有没有远程配置,如果没有直接加载类,提高效率
    $conf_add = $add == '' ? '' : '#' . $add;
    $conf_name = 'proxy.' . strtolower($mod) . $conf_add;
    $proxy_conf = Pi::get($conf_name, array());
    if ($is_server === false && !empty($proxy_conf)) {
        //proxy代理类,根据更详细的配置选择哪个接口走远程
        $class = new Proxy($mod, $add, $proxy_conf);
        $loaded_mod[$mod . $add] = $class;
    } else {
        //直接加载本地逻辑接口
        $loaded_mod[$mod . $add] = pi_load_export_file($mod, $add);
    }
    return $loaded_mod[$mod . $add];
}
Exemplo n.º 8
0
 function loadPipes($pipes = null, $root = null)
 {
     //pipe 数组格式 path => class_name
     //加载默认的处理管道
     if ($pipes == null) {
         $pipes = array();
         $input = Pi::get('DefaultInputPipe');
         $output = Pi::get('DefaultOutputPipe');
         $pipes = array($input => PI_PIPE . $input . '.php', $output => PI_PIPE . $output . '.php');
     } else {
         if (is_string($pipes)) {
             $pipes = array($pipes);
         }
         if (empty($pipes)) {
             return false;
         }
         //加载管道位置
         $root = $root == 'default' ? PI_ROOT : COM_ROOT;
         foreach ($pipes as $k => $cls) {
             $pipes[$cls] = $root . 'pipe' . DOT . $cls . '.php';
             unset($pipes[$k]);
         }
     }
     foreach ($pipes as $cls => $path) {
         if (isset($this->arr_pipe[$cls])) {
             continue;
         }
         if (is_readable($path)) {
             Pi::inc($path);
             if (class_exists($cls)) {
                 $this->arr_pipe[$cls] = new $cls();
             }
         } else {
             throw new Exception('the pipe ' . $cls . ' can not load,check pipe file', 1020);
         }
     }
 }
Exemplo n.º 9
0
 public function call($method, $params, $mod, $add, $conf)
 {
     $sign = Pi::get('global.innerapi_sign', '');
     $sign_name = Pi::get('global.innerapi_sign_name', '_pi_inner_nm');
     if (isset($conf['ip']) && isset($conf['net']) && $conf['net'] == 'http') {
         $args = array();
         $args['mod'] = $mod;
         $args['add'] = $add;
         $args['method'] = $method;
         $args['param'] = $params;
         $args[$sign_name] = $sign;
         try {
             $curl = new HttpClient();
             $timeout = isset($conf['timeout']) ? intval($conf['timeout']) : 10;
             $res = $curl->sendPostData($conf['ip'], $args, $timeout);
             if ($curl->hasError() === false) {
                 $data = unserialize($res);
                 $data = isset($data[INNER_RES_PACK]) ? $data[INNER_RES_PACK] : $data;
                 return $data;
             } else {
                 throw new Exception('curl error', 5011);
             }
         } catch (Exception $e) {
             return array(INNER_ERR => 5011, 'msg' => $curl->getErrorMsg());
         }
     }
     throw new Exception('inner api err conf : ' . var_export($conf), 5004);
 }
Exemplo n.º 10
0
Arquivo: App.php Projeto: xtzlyp/newpi
 protected function needToLog($code)
 {
     $core_no_need_log_code = Conf::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;
 }
Exemplo n.º 11
0
 public function __construct()
 {
     //包含controller需要继承的父类
     Pi::inc(Pi::get('PageCtr'));
 }
Exemplo n.º 12
0
Arquivo: Pi.php Projeto: hihus/pi
 protected function initCache()
 {
     $is_enable_memcache = Pi::get('global.enable_memcache', true);
     $is_enable_redis = Pi::get('global.enable_redis', true);
     if ($is_enable_memcache) {
         Pi::inc(Pi::get('MemcacheLib'));
     }
     if ($is_enable_redis) {
         Pi::inc(Pi::get('RedisLib'));
     }
 }
Exemplo n.º 13
0
Arquivo: Proxy.php Projeto: hihus/pi
 static function checkSign($mod, $sign)
 {
     $sign = explode('_', $sign);
     if (!isset($sign[1])) {
         return false;
     }
     $salt = Pi::get('global.inner_tmp_salt', 'ks92pi');
     if ($sign[0] == md5($mod . $salt . $sign[1])) {
         return true;
     }
     return false;
 }
Exemplo n.º 14
0
 public function run()
 {
     //test com autoload
     // $login = new Logic_Login_Login();
     // $login->login();
     // //test model autoload
     // $log_table = new Model_login_UserLogin();
     // $log_table->doLogin();
     // //test the extend picom
     // $com_login = picom("login","find");
     // $com_login->find();
     // //test picom load
     // $com_login = picom("login");
     // $com_login->dologin();
     // //pipe可以定义成配置数组。方便上下线
     // $this->pipe->loadPipes('WebTestPipe');
     // $this->pipe->loadPipes('DTestPipe','default');
     // $this->pipe->execute('WebTestPipe');
     // $this->pipe->execute('DTestPipe');
     // //test util
     // $xz = new Xcrypt();
     // $num = rand(10000,20000).rand(10000,20000).rand(10000,20000);
     // $res = $xz->encode($num);
     // echo $res;
     //初始化pipe
     $default_pipe = array('WebReqPipe' => 'default', 'WebRouterPipe' => 'default');
     $pipes = Pi::get('global.pipes', array());
     if (empty($pipes)) {
         $pipes = $default_pipe;
     }
     $this->pipeLoadContainer = $pipes;
     parent::run();
 }