Author: lanlin
Inheritance: extends CI_Controller
Exemplo n.º 1
0
 function __construct(\Swoole $swoole)
 {
     $this->swoole = $swoole;
     $this->model = $swoole->model;
     $this->config = $swoole->config;
     $this->template_dir = \Swoole::$app_path . '/templates/';
     if (!defined('TPL_PATH')) {
         define('TPL_PATH', $this->template_dir);
     }
     if ($this->if_filter) {
         Filter::request();
     }
     $swoole->__init();
 }
Exemplo n.º 2
0
 static function __callStatic($func, $params)
 {
     $id = $params[0];
     if (empty(self::$pool[$id])) {
         $objectType = substr($func, 3);
         $config = \Swoole::getInstance()->config[strtolower($objectType)][$id];
         if (empty($objectType) or empty($config['type'])) {
             throw new \Exception("config error.{$objectType}/{$id} not found");
         }
         $class = '\\Swoole\\' . $objectType . '\\' . $config['type'];
         self::$pool[$id] = new $class($config);
     }
     return self::$pool[$id];
 }
Exemplo n.º 3
0
/**
 * 开启会话
 * @param $readonly
 */
function session($readonly = false)
{
    Swoole::getInstance()->session->start($readonly);
}
Exemplo n.º 4
0
 function __construct(\Swoole $swoole, $db_key = 'master')
 {
     $this->db = $swoole->db($db_key);
     $this->dbs = new \Swoole\SelectDB($swoole->db);
     $this->swoole = $swoole;
 }
Exemplo n.º 5
0
 function handlerServer(Swoole\Request $request)
 {
     $response = new Swoole\Response();
     $request->setGlobal();
     //处理静态请求
     if (!empty($this->server->config['apps']['do_static']) and $this->server->doStaticRequest($request, $response)) {
         return $response;
     }
     $php = Swoole::getInstance();
     //将对象赋值到控制器
     $php->request = $request;
     $php->response = $response;
     try {
         ob_start();
         /*---------------------处理MVC----------------------*/
         $response->body = $php->runMVC();
         $response->body .= ob_get_contents();
         ob_end_clean();
     } catch (\Exception $e) {
         if ($request->finish != 1) {
             $this->server->httpError(404, $response, $e->getMessage());
         }
     }
     //重定向
     if (isset($response->head['Location'])) {
         $response->setHttpStatus(301);
     }
     return $response;
 }
Exemplo n.º 6
0
define('DEBUG', 'on');
define('WEBPATH', __DIR__);
if (!empty($_SERVER['SERVER_NAME'])) {
    define("WEBROOT", 'http://' . $_SERVER['SERVER_NAME']);
}
define("TABLE_PREFIX", 'st');
define("SITENAME", 'Swoole_PHP开发社区');
//define("TPL_DIR",WEBPATH.'/site/'.SITENAME.'/templates');
//模板目录
//上传文件的位置
define('UPLOAD_DIR', '/static/uploads');
//Login登录用户配置
define('LOGIN_TABLE', 'user_login');
require __DIR__ . '/libs/lib_config.php';
require __DIR__ . '/admin/func.php';
if (get_cfg_var('env.name') == 'dev') {
    require __DIR__ . '/apps/dev_config.php';
    Swoole::$php->config->setPath(APPSPATH . '/configs/dev/');
}
//Swoole\Config::$debug = true;
Swoole::$php->addHook(Swoole::HOOK_INIT, function () {
    $php = Swoole::getInstance();
    //动态配置系统
    $php->tpl->assign('_site_', '/site/' . SITENAME);
    $php->tpl->assign('_static_', $php->config['site']['static']);
});
Swoole::$php->tpl->compile_dir = WEBPATH . "/cache/";
Swoole::$php->tpl->cache_dir = WEBPATH . "/cache/";
//指定国际编码的方式
mb_internal_encoding('utf-8');
//$php->gzip();
Exemplo n.º 7
0
 /**
  * 初始化环境
  * @return unknown_type
  */
 private function __init()
 {
     #记录运行时间和内存占用情况
     $this->env['runtime']['start'] = microtime(true);
     $this->env['runtime']['mem'] = memory_get_usage();
     #捕获错误信息
     if (DEBUG == 'on') {
         set_error_handler('swoole_error_handler');
     }
     #初始化App环境
     //为了兼容老的APPSPATH预定义常量方式
     if (defined('APPSPATH')) {
         self::$app_root = str_replace(WEBPATH, '', APPSPATH);
     } elseif (empty(self::$app_root)) {
         self::$app_root = "/apps";
     }
     self::$app_path = WEBPATH . self::$app_root;
     $this->env['app_root'] = self::$app_root;
 }
Exemplo n.º 8
0
 function admin_add()
 {
     $this->_check_cms();
     $model = createModel($this->app);
     $php = Swoole::getInstance();
     if ($_POST) {
         $this->proc_upfiles();
         if (isset($_POST['cid'])) {
             $cid = (int) $_POST['cid'];
             $cate = getCategory($cid);
             $_POST['cname'] = $cate['name'];
             $_POST['fid'] = $cate['fid'];
             $fcate = getCategory($cate['fid']);
             $_POST['fname'] = $fcate['name'];
         } elseif (isset($_POST['fid'])) {
             $fid = (int) $_POST['fid'];
             $_POST['fid'] = $fid;
             $fcate = getCategory($fid);
             $_POST['fname'] = $fcate['name'];
         }
         $_POST['uptime'] = time();
         //将远程图片本地化
         Swoole_content::image_local($_POST['content']);
         if (!empty($_POST['id'])) {
             //如果得到id,说明提交的是修改的操作
             $id = (int) $_POST['id'];
             unset($_POST['id']);
             $model->set($id, $_POST);
             Swoole_js::js_back('修改成功', -2);
             if ($php->config->cms['html_static']) {
                 if (!empty($_POST['pagename'])) {
                     $this->updatePage($_POST['pagename']);
                 } else {
                     $this->updateDetail($id);
                 }
             }
         } else {
             //如果没得到id,说明提交的是添加操作
             //if(!isset($_POST['cid']) and isset($_GET['fid'])) $_POST['cid'] = $_GET['fid'];
             $_POST['uid'] = $_SESSION['admin_user_id'];
             $_POST['uname'] = $_SESSION['admin_user']['realname'];
             $id = $model->put($_POST);
             Swoole_js::js_back('添加成功');
             if ($php->config->cms['html_static']) {
                 if (!empty($_POST['pagename'])) {
                     $this->updatePage($_POST['pagename']);
                 } else {
                     $this->updateDetail($id);
                 }
             }
         }
     } else {
         //Error::dbd();
         if (empty($_GET['fid']) and empty($_GET['cid'])) {
             $cates = getCategorys($this->app);
             $this->swoole->tpl->assign('cates', $cates);
         }
         $this->swoole->plugin->load('fckeditor');
         if (isset($_GET['id'])) {
             $id = $_GET['id'];
             $det = $model->get($id)->get();
             $editor = editor("content", $det['content'], 480);
             $this->swoole->tpl->assign('det', $det);
             $this->swoole->tpl->assign('cates', false);
         } else {
             $editor = editor("content", '', 480);
         }
         $this->swoole->tpl->assign('editor', $editor);
         $this->swoole->tpl->display('admin_' . strtolower($this->app) . '_detail.html');
     }
 }
Exemplo n.º 9
0
/**
 * 开启会话
 */
function session($readonly = false)
{
    $php = Swoole::getInstance();
    if (!defined('SWOOLE_SERVER')) {
        session_start();
        return true;
    } else {
        $php->session->start($readonly);
    }
}
Exemplo n.º 10
0
 static function getInstance()
 {
     if (!self::$php) {
         self::$php = new Swoole();
     }
     return self::$php;
 }
Exemplo n.º 11
0
 function __destruct()
 {
     $this->swoole->__clean();
 }
Exemplo n.º 12
0
 function __construct($db_key = 'master')
 {
     $this->config = \Swoole::getInstance()->config['db'][$db_key];
     //不能使用长连接,避免进程内占用大量连接
     $this->config['persistent'] = false;
 }
Exemplo n.º 13
0
<?php

define('DEBUG', 'on');
require __DIR__ . '/../vendor/autoload.php';
Swoole\Loader::vendor_init();
$pkg = array("client_ip" => "127.0.0.1", "user_id" => 350749960, "level" => 1, "time" => 1398345164, "txt" => "ErrorLog Test. File=/home/htf/workspace/duowan/mostats/tests/send_log.php|num=0");
Swoole::$app_path = __DIR__ . '/../server/';
table('module_log')->put($pkg);
Exemplo n.º 14
0
<?php

define('DEBUG', 'on');
define('WEBPATH', __DIR__);
define('WEBROOT', 'http://' . $_SERVER['HTTP_HOST']);
require __DIR__ . '/../../framework/libs/lib_config.php';
require __DIR__ . '/apps/include/functions.php';
if (get_cfg_var('env.name') == 'local' or get_cfg_var('env.name') == 'dev') {
    Swoole::$php->config->setPath(__DIR__ . '/apps/configs/dev/');
}
Swoole::getInstance()->runMVC();