Пример #1
0
 public function __construct()
 {
     $dispatcher = Conf::get('global.dispatcher_path', PI_CORE . 'RouteDispatcher.php');
     if (!is_readable($dispatcher) || !Pi::inc($dispatcher)) {
         throw new Exception('can not find the dispatcher config : global.dispatcher_path', 1032);
     }
 }
Пример #2
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);
     }
 }
Пример #3
0
function _pi_autoloader_core($class)
{
    if (($pos = strpos($class, '_')) !== false) {
        $class = explode('_', $class);
        if (empty($class)) {
            return false;
        }
        $first_dir = strtolower($class[0]);
        $fileName = array_pop($class);
        $class = array_map('strtolower', $class);
        $root = $first_dir == 'util' ? PI_ROOT : COM_ROOT;
        $file = $root . implode(DOT, $class) . DOT . $fileName . '.php';
        if (is_readable($file)) {
            Pi::inc($file);
        }
    } else {
        //优先加载工程中的lib,其次加载框架中的util
        if (is_readable(PI_UTIl . $class . '.php')) {
            Pi::inc(PI_UTIl . $class . '.php');
        } else {
            if (is_readable(COM_ROOT . 'lib/' . $class . '.php')) {
                Pi::inc(COM_ROOT . 'lib/' . $class . '.php');
            }
        }
    }
}
Пример #4
0
 public function execute(App $app)
 {
     $argv = $app->argv;
     $script = $app->task_name;
     $script = explode('_', $script);
     $cls_file = ucfirst(strtolower(array_pop($script)));
     if (empty($cls_file)) {
         throw new Exception('task.err for run the task for :' . $this->task_name, 1033);
     }
     $path = '';
     $class = '';
     if (!empty($script)) {
         foreach ($script as $p) {
             $p = strtolower($p);
             $path .= $p . DOT;
             $class .= ucfirst($p);
         }
     }
     $class .= $cls_file;
     $path = TASK_PATH . $path;
     $file = $path . $cls_file . '.php';
     Pi::inc(PI_CORE . 'BaseTask.php');
     if (!Pi::inc($file)) {
         throw new Exception('task.err can not load the file :' . $file, 1034);
     }
     if (!class_exists($class)) {
         throw new Exception('task.err can not find the class :' . $class, 1035);
     }
     $cls = new $class();
     if (!is_subclass_of($cls, 'BaseTask')) {
         throw new Exception('task.err the class ' . $class . ' is not the subclass of BaseTask ', 1036);
     }
     $cls->execute($argv);
 }
Пример #5
0
 public function __construct()
 {
     $dispatcher = Conf::get('global.dispatcher_path', PI_CORE . 'RouteDispatcher.php');
     if (file_exists($dispatcher)) {
         Pi::inc($dispatcher);
     } else {
         throw new Exception('can not find the dispatcher config : global.dispatcher_path', 1032);
     }
 }
Пример #6
0
 protected function _initTemplate()
 {
     $views = Conf::get('global.view_lib_path');
     if (!is_readable(PI_ROOT . $views)) {
         die('can not find the web view libs ');
     }
     Pi::inc(PI_ROOT . $views);
     $cls = Conf::get('global.view_engine');
     if (!class_exists($cls)) {
         die('can not init the template engine class');
     }
 }
Пример #7
0
Файл: Web.php Проект: 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');
     }
 }
Пример #8
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;
 }
Пример #9
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)) {
                     throw new Exception('error format mod:' . $m, 1005);
                 }
                 unset($mod[$k]);
             }
             $mod[$k] = strtolower($m);
             $class .= ucfirst($mod[$k]);
         }
     }
     if (empty($mod)) {
         throw new Exception('empty api mod:' . $mod, 1006);
     }
     if (empty($func) || !is_string($func) || !preg_match($pattern, $func)) {
         throw new Exception("empty api func:" . $func, 1007);
     }
     $file = $api_path . implode(DOT, $mod) . DOT . $class . '.api.php';
     if (!is_readable($file)) {
         throw new Exception('api router can not load file:' . $file, 1008);
     }
     Pi::inc(PI_CORE . 'BaseApi.php');
     Pi::inc($file);
     if (!class_exists($class)) {
         throw new Exception('api router not find class:' . $class, 1009);
     }
     $cls = new $class();
     if (!is_subclass_of($cls, 'BaseApi')) {
         throw new Exception('api.err is not the subclass of BaseApi ', 1010);
     }
     $res = $this->_call_method($cls, $func);
     if ($res === false) {
         throw new Exception('api class:' . $class . ' call method ' . $func . ' err ', 1011);
     }
 }
Пример #10
0
 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);
 }
Пример #11
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);
     }
 }
Пример #12
0
 public function execute(PiApp $app)
 {
     $this->app = $app;
     $router = Conf::get('global.router_file', 'ApiRouter.php');
     $router_class = Conf::get('global.router_class', 'PiApiRouter');
     if (is_readable(PI_CORE . $router)) {
         Pi::inc(PI_CORE . $router);
     } else {
         throw new Exception('api.router can not find the api router : ' . $router, 1030);
     }
     if (class_exists($router_class)) {
         $cls = new $router_class($app);
         $cls->dispatch();
     } else {
         throw new Exception('api.router can not find the router class : ' . $router_class, 1031);
     }
 }
Пример #13
0
Файл: Api.php Проект: 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();
     }
 }
Пример #14
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);
         }
     }
 }
Пример #15
0
 static function get($key, $default = null)
 {
     if (isset(self::$saConfData[$key])) {
         return self::$saConfData[$key];
     }
     //没有的自动加载文件和配置项
     if (defined("APP_CONF_PATH") && strpos($key, '.') !== false) {
         $file = explode('.', $key);
         if (!empty($file)) {
             array_pop($file);
             $file_name = array_pop($file);
             $file = count($file) == 0 ? '' : implode(DOT, $file) . DOT;
             $file = APP_CONF_PATH . $file . $file_name . '.inc.php';
             if (Pi::inc($file) && isset(self::$saConfData[$key])) {
                 return self::$saConfData[$key];
             }
         }
     }
     return $default;
 }
Пример #16
0
<?php

Pi::inc(dirname(__FILE__) . DOT . 'PICacheAbstract.php');
class PRedis extends PICacheAbstract
{
    public $options = array('persistent' => true, 'host' => '127.0.0.1', 'port' => 6379, 'timeout' => 3, 'ttl' => 0);
    public $optionKeys = array(Redis::OPT_SERIALIZER, Redis::OPT_PREFIX);
    /**
     * Constructor
     *
     * @param array $options
     */
    public function __construct($options = array())
    {
        parent::__construct($options);
        $this->conn = new Redis();
        if (empty($this->options['persistent'])) {
            $this->conn->connect($this->options['host'], $this->options['port'], $this->options['timeout']);
        } else {
            $this->conn->pconnect($this->options['host'], $this->options['port'], $this->options['timeout']);
        }
        foreach ($this->optionKeys as $key) {
            if (isset($this->options[$key])) {
                $this->conn->setOption($key, $this->options[$key]);
            }
        }
    }
    /**
     * Set cache
     *
     * @param string $key
Пример #17
0
Файл: db.php Проект: hihus/pi
<?php

/**
 * @file db.php
 * @author wanghe (hihu@qq.com)
 **/
//实现框架自己的db功能
Pi::inc(dirname(__FILE__) . DOT . 'db' . DOT . 'Medoo.php');
class PiDb
{
    private static $instance = null;
    public static function init($name = 's')
    {
        if (empty($name) && !is_string($name)) {
            return null;
        }
        $conf = self::getConfig($name);
        if ($conf == null) {
            throw new Exception("check your db config fordabase :" . $name, 6001);
        }
        if (!isset(self::$instance[$name])) {
            self::$instance[$name] = new InnerPiDb($conf);
        }
        return self::$instance[$name];
    }
    public static function delDb($name)
    {
        if (isset(self::$instance[$name])) {
            unset(self::$instance[$name]);
        }
    }
Пример #18
0
Файл: Pi.php Проект: 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'));
     }
 }
Пример #19
0
<?php

/**
 * @file db.php
 * @author wanghe (hihu@qq.com)
 **/
//实现框架自己的db功能
Pi::inc(PI_CORE . 'db/medoo.php');
class Db
{
    private static $instance = null;
    public static function init($name = 's')
    {
        if (empty($name) && !is_string($name)) {
            return null;
        }
        $conf = self::getConfig($name);
        if ($conf == null) {
            return null;
        }
        if (!isset(self::$instance[$name])) {
            self::$instance[$name] = new PiDb($conf);
        }
        return self::$instance[$name];
    }
    public static function delDb($name)
    {
        if (isset(self::$instance[$name])) {
            unset(self::$instance[$name]);
        }
    }
Пример #20
0
<?php

/**
 * @file Log.php
 * @author wanghe (hihu@qq.com)
 * @date 2015/12/08
 * @version 1.0 
 **/
if (!function_exists('posix_getpid')) {
    function posix_getpid()
    {
        return getmypid();
    }
}
Pi::inc(dirname(__FILE__) . '/Logger.php');
final class Log
{
    //日志缓冲
    const PAGE_SIZE = 4096;
    //monitor日志特征串
    const MONTIR_STR = '---LOG_MONITOR---';
    const SMS_MONTIR_STR = '<<<SMS_LOG_MONITOR>>>';
    static $LOG_NAME = array(Logger::LOG_FATAL => 'FATAL', Logger::LOG_WARNING => 'WARNING', Logger::LOG_NOTICE => 'NOTICE', Logger::LOG_TRACE => 'TRACE', Logger::LOG_DEBUG => 'DEBUG');
    private $log_name = '';
    private $log_path = '';
    private $log_str = '';
    private $wflog_str = '';
    private $basic_info = '';
    private $notice_str = '';
    private $log_level = 16;
    private $arr_basic = null;
Пример #21
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;
     }
 }