Author: liu21st (liu21st@gmail.com)
Example #1
0
 public function testInvokeMethod()
 {
     $result = App::invokeMethod(['tests\\thinkphp\\library\\think\\AppInvokeMethodTestClass', 'run'], ['thinkphp']);
     $this->assertEquals('thinkphp', $result);
     $result = App::invokeMethod('tests\\thinkphp\\library\\think\\AppInvokeMethodTestClass::staticRun', ['thinkphp']);
     $this->assertEquals('thinkphp', $result);
 }
Example #2
0
 public function testConfig()
 {
     App::run();
     $this->assertTrue(Config::has('url_route_on'));
     $this->assertEquals(1, Config::get('url_route_on'));
     Config::set('url_route_on', false);
     $this->assertEquals(0, Config::get('url_route_on'));
     Config::range('test');
     $this->assertFalse(Config::has('url_route_on'));
     Config::reset();
 }
Example #3
0
 public function testConfig()
 {
     App::run(Config::get());
     Config::parse('isTrue=1', 'test');
     Config::range('test');
     $this->assertTrue(Config::has('isTrue'));
     $this->assertEquals(1, Config::get('isTrue'));
     Config::set('isTrue', false);
     $this->assertEquals(0, Config::get('isTrue'));
     Config::reset();
 }
Example #4
0
 /**
  * REST 调用
  * @access public
  * @param string $method 方法名
  * @return mixed
  * @throws \Exception
  */
 public function _empty($method)
 {
     if (method_exists($this, $method . '_' . $this->method . '_' . $this->type)) {
         // RESTFul方法支持
         $fun = $method . '_' . $this->method . '_' . $this->type;
     } elseif ($this->method == $this->restDefaultMethod && method_exists($this, $method . '_' . $this->type)) {
         $fun = $method . '_' . $this->type;
     } elseif ($this->type == $this->restDefaultType && method_exists($this, $method . '_' . $this->method)) {
         $fun = $method . '_' . $this->method;
     }
     if (isset($fun)) {
         return App::invokeMethod([$this, $fun]);
     } else {
         // 抛出异常
         throw new \Exception('error action :' . $method);
     }
 }
Example #5
0
 /**
  * 魔术方法 有不存在的操作的时候执行
  * @access public
  * @param string $method 方法名
  * @param array $args 参数
  * @return mixed
  */
 public function __call($method, $args)
 {
     if (0 === strcasecmp($method, ACTION_NAME . C('ACTION_SUFFIX'))) {
         if (method_exists($this, $method . '_' . $this->_method . '_' . $this->_type)) {
             // RESTFul方法支持
             $fun = $method . '_' . $this->_method . '_' . $this->_type;
             App::invokeAction($this, $fun);
         } elseif ($this->_method == $this->defaultMethod && method_exists($this, $method . '_' . $this->_type)) {
             $fun = $method . '_' . $this->_type;
             App::invokeAction($this, $fun);
         } elseif ($this->_type == $this->defaultType && method_exists($this, $method . '_' . $this->_method)) {
             $fun = $method . '_' . $this->_method;
             App::invokeAction($this, $fun);
         } elseif (method_exists($this, '_empty')) {
             // 如果定义了_empty操作 则调用
             $this->_empty($method, $args);
         } elseif (file_exists_case($this->view->parseTemplate())) {
             // 检查是否存在默认模版 如果有直接输出模版
             $this->display();
         } else {
             E(L('_ERROR_ACTION_') . ':' . ACTION_NAME);
         }
     }
 }
Example #6
0
 public function __construct()
 {
     $http = new swoole_http_server("0.0.0.0", 9501);
     $http->set(array('worker_num' => 16, 'daemonize' => 0, 'max_request' => 10000, 'dispatch_mode' => 1));
     $http->on('WorkerStart', array($this, 'onWorkerStart'));
     $http->on('request', function ($request, $response) {
         if (isset($request->server)) {
             foreach ($request->server as $key => $value) {
                 unset($_SERVER[strtoupper($key)]);
                 $_SERVER[strtoupper($key)] = $value;
             }
         }
         if (isset($request->header)) {
             foreach ($request->header as $key => $value) {
                 unset($_SERVER[strtoupper($key)]);
                 $_SERVER[strtoupper($key)] = $value;
             }
         }
         unset($_GET);
         if (isset($request->get)) {
             foreach ($request->get as $key => $value) {
                 $_GET[$key] = $value;
             }
         }
         unset($_POST);
         if (isset($request->post)) {
             foreach ($request->post as $key => $value) {
                 $_POST[$key] = $value;
             }
         }
         unset($_COOKIE);
         if (isset($request->cookie)) {
             foreach ($request->cookie as $key => $value) {
                 $_COOKIE[$key] = $value;
             }
         }
         unset($_FILES);
         if (isset($request->files)) {
             foreach ($request->files as $key => $value) {
                 $_FILES[$key] = $value;
             }
         }
         /*
         			$uri = explode( "?", $_SERVER['REQUEST_URI'] );
         			$_SERVER["PATH_INFO"] = $uri[0];
         			if( isset( $uri[1] ) ) {
         				$_SERVER['QUERY_STRING'] = $uri[1];
         			}*/
         $_SERVER["PATH_INFO"] = explode('/', $_SERVER["PATH_INFO"], 3)[2];
         $_SERVER['argv'][1] = $_SERVER["PATH_INFO"];
         ob_start();
         // 记录加载文件时间
         G('loadTime');
         // 运行应用
         \Think\App::run();
         $result = ob_get_contents();
         ob_end_clean();
         $response->end($result);
     });
     $http->start();
 }
Example #7
0
File: App.php Project: GDdark/cici
 /**
  * 执行模块
  * @access public
  * @param array $result 模块/控制器/操作
  * @param array $config 配置参数
  * @param bool  $convert 是否自动转换控制器和操作名
  * @return mixed
  */
 public static function module($result, $config, $convert = null)
 {
     if (is_string($result)) {
         $result = explode('/', $result);
     }
     $request = Request::instance();
     if ($config['app_multi_module']) {
         // 多模块部署
         $module = strip_tags(strtolower($result[0] ?: $config['default_module']));
         $bind = Route::getBind('module');
         $available = false;
         if ($bind) {
             // 绑定模块
             list($bindModule) = explode('/', $bind);
             if ($module == $bindModule) {
                 $available = true;
             }
         } elseif (!in_array($module, $config['deny_module_list']) && is_dir(APP_PATH . $module)) {
             $available = true;
         }
         // 模块初始化
         if ($module && $available) {
             // 初始化模块
             $request->module($module);
             $config = self::init($module);
         } else {
             throw new HttpException(404, 'module not exists:' . $module);
         }
     } else {
         // 单一模块部署
         $module = '';
         $request->module($module);
     }
     // 当前模块路径
     App::$modulePath = APP_PATH . ($module ? $module . DS : '');
     // 是否自动转换控制器和操作名
     $convert = is_bool($convert) ? $convert : $config['url_convert'];
     // 获取控制器名
     $controller = strip_tags($result[1] ?: $config['default_controller']);
     $controller = $convert ? strtolower($controller) : $controller;
     // 获取操作名
     $actionName = strip_tags($result[2] ?: $config['default_action']);
     $actionName = $convert ? strtolower($actionName) : $actionName;
     // 设置当前请求的控制器、操作
     $request->controller($controller)->action($actionName);
     // 监听module_init
     Hook::listen('module_init', $request);
     try {
         $instance = Loader::controller($controller, $config['url_controller_layer'], $config['controller_suffix'], $config['empty_controller']);
         if (is_null($instance)) {
             throw new HttpException(404, 'controller not exists:' . $controller);
         }
         // 获取当前操作名
         $action = $actionName . $config['action_suffix'];
         if (!preg_match('/^[A-Za-z](\\w)*$/', $action)) {
             // 非法操作
             throw new \ReflectionException('illegal action name:' . $actionName);
         }
         // 执行操作方法
         $call = [$instance, $action];
         Hook::listen('action_begin', $call);
         $data = self::invokeMethod($call);
     } catch (\ReflectionException $e) {
         // 操作不存在
         if (method_exists($instance, '_empty')) {
             $method = new \ReflectionMethod($instance, '_empty');
             $data = $method->invokeArgs($instance, [$action, '']);
             self::$debug && Log::record('[ RUN ] ' . $method->__toString(), 'info');
         } else {
             throw new HttpException(404, 'method not exists:' . (new \ReflectionClass($instance))->getName() . '->' . $action);
         }
     }
     return $data;
 }
Example #8
0
 public function testRun()
 {
     \think\App::run();
     // todo...
 }
Example #9
0
<?php

// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2015 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <*****@*****.**>
// +----------------------------------------------------------------------
// 应用入口文件
// 定义项目路径
define('APP_PATH', __DIR__ . '/../application/');
// 开启调试模式
define('APP_DEBUG', true);
define('APP_AUTO_BUILD', true);
//开启自动生成
// 加载框架引导文件
require __DIR__ . '/../thinkphp/start.php';
// 执行应用
\think\App::run();
Example #10
0
 /**
  * 远程调用模块的操作方法 参数格式 [模块/控制器/]操作
  * @param string       $url          调用地址
  * @param string|array $vars         调用参数 支持字符串和数组
  * @param string       $layer        要调用的控制层名称
  * @param bool         $appendSuffix 是否添加类名后缀
  * @return mixed
  */
 public static function action($url, $vars = [], $layer = 'controller', $appendSuffix = false)
 {
     $info = pathinfo($url);
     $action = $info['basename'];
     $module = '.' != $info['dirname'] ? $info['dirname'] : Request::instance()->controller();
     $class = self::controller($module, $layer, $appendSuffix);
     if ($class) {
         if (is_scalar($vars)) {
             if (strpos($vars, '=')) {
                 parse_str($vars, $vars);
             } else {
                 $vars = [$vars];
             }
         }
         return App::invokeMethod([$class, $action . Config::get('action_suffix')], $vars);
     }
 }
Example #11
0
 /**
  * 执行模块
  * @access public
  * @param array $result 模块/控制器/操作
  * @param array $config 配置参数
  * @param bool  $convert 是否自动转换控制器和操作名
  * @return mixed
  */
 public static function module($result, $config, $convert = null)
 {
     if (is_string($result)) {
         $result = explode('/', $result);
     }
     $request = Request::instance();
     if ($config['app_multi_module']) {
         // 多模块部署
         $module = strip_tags(strtolower($result[0] ?: $config['default_module']));
         $bind = Route::getBind('module');
         $available = false;
         if ($bind) {
             // 绑定模块
             list($bindModule) = explode('/', $bind);
             if (empty($result[0])) {
                 $module = $bindModule;
                 $available = true;
             } elseif ($module == $bindModule) {
                 $available = true;
             }
         } elseif (!in_array($module, $config['deny_module_list']) && is_dir(APP_PATH . $module)) {
             $available = true;
         }
         // 模块初始化
         if ($module && $available) {
             // 初始化模块
             $request->module($module);
             $config = self::init($module);
         } else {
             throw new HttpException(404, 'module not exists:' . $module);
         }
     } else {
         // 单一模块部署
         $module = '';
         $request->module($module);
     }
     // 当前模块路径
     App::$modulePath = APP_PATH . ($module ? $module . DS : '');
     // 是否自动转换控制器和操作名
     $convert = is_bool($convert) ? $convert : $config['url_convert'];
     // 获取控制器名
     $controller = strip_tags($result[1] ?: $config['default_controller']);
     $controller = $convert ? strtolower($controller) : $controller;
     // 获取操作名
     $actionName = strip_tags($result[2] ?: $config['default_action']);
     $actionName = $convert ? strtolower($actionName) : $actionName;
     // 设置当前请求的控制器、操作
     $request->controller(Loader::parseName($controller, 1))->action($actionName);
     // 监听module_init
     Hook::listen('module_init', $request);
     $instance = Loader::controller($controller, $config['url_controller_layer'], $config['controller_suffix'], $config['empty_controller']);
     if (is_null($instance)) {
         throw new HttpException(404, 'controller not exists:' . Loader::parseName($controller, 1));
     }
     // 获取当前操作名
     $action = $actionName . $config['action_suffix'];
     if (is_callable([$instance, $action])) {
         // 执行操作方法
         $call = [$instance, $action];
     } elseif (is_callable([$instance, '_empty'])) {
         // 空操作
         $call = [$instance, '_empty'];
     } else {
         // 操作不存在
         throw new HttpException(404, 'method not exists:' . get_class($instance) . '->' . $action . '()');
     }
     Hook::listen('action_begin', $call);
     $data = self::invokeMethod($call);
     return $data;
 }
Example #12
0
 public function testRun()
 {
     \think\App::run();
     $this->expectOutputString('<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} body{ background: #fff; font-family: "微软雅黑"; color: #333;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.8em; font-size: 36px }</style><div style="padding: 24px 48px;"> <h1>:)</h1><p>欢迎使用 <b>ThinkPHP5</b>!</p></div><script type="text/javascript" src="http://tajs.qq.com/stats?sId=9347272" charset="UTF-8"></script><script type="text/javascript" src="http://ad.topthink.com/Public/static/client.js"></script><thinkad id="ad_bd568ce7058a1091"></thinkad>');
     // todo...
 }
Example #13
0
 /**
  * 加载运行时所需要的文件
  * 检查调试模式创建目录
  *
  * @return void
  */
 public static function load_runtime_file()
 {
     try {
         // 载入临时的Helper文件,将重构
         include CORE_PATH . 'Library/Helper' . EXT;
         // 调试模式下检查路径和文件
         if (APP_DEBUG) {
             // 创建项目目录结构
             if (!is_dir(LIB_PATH)) {
                 throw new Exception("不存在项目目录结构");
             }
             // 检查缓存目录
             if (!is_dir(CACHE_PATH)) {
                 // 如果不存在Runtime则创建
                 if (!is_dir(RUNTIME_PATH)) {
                     mkdir(RUNTIME_PATH);
                 } else {
                     if (!is_writeable(RUNTIME_PATH)) {
                         throw new Exception(RUNTIME_PATH . "is no writeable");
                     }
                 }
                 // 检查并创建Runtime下的缓存目录
                 foreach (array(CACHE_PATH, LOG_PATH, TEMP_PATH, DATA_PATH) as $key => $value) {
                     if (!is_dir($value)) {
                         mkdir($value);
                     }
                 }
             }
         }
         // 记录文件加载时间
         Debug::mark('loadTime');
         // 启动
         App::run();
     } catch (Exception $error) {
         exit($error->getMessage());
     }
 }
Example #14
0
<?php

// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2015 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <*****@*****.**>
// +----------------------------------------------------------------------
// 应用入口文件
// 定义项目路径
define('APP_PATH', __DIR__ . '/../application/');
// 开启调试模式
define('APP_DEBUG', true);
// 加载框架引导文件
require __DIR__ . '/../thinkphp/start.php';
// 执行应用
\think\App::run(\think\Config::get());
Example #15
0
 /**
  * Ajax方式返回数据到客户端
  * @access protected
  * @param mixed $data 要返回的数据
  * @param String $type AJAX返回数据格式
  * @return void
  */
 protected function ajaxReturn($data, $type = '')
 {
     App::returnData($data, $type);
 }
Example #16
0
}
if (@$_GET['v'] == 1) {
    define('ZMLTPL', 'wap');
} else {
    define('ZMLTPL', 'www');
}
//如果是手机设备 定义常量
//if(is_mobile_request()==true){
//	define('ZMLTPL','wap');
//}else{
//	define('ZMLTPL','default');
//}
// 开启调试模式 建议开发阶段开启 部署阶段注释或者设为false
define('APP_DEBUG', True);
define('ZHIMALE_V', '1.03');
// 定义应用目录
define('APP_PATH', './App/');
// 定义模版目录
define('TMPL_PATH', './Template/');
define('RUNTIME_PATH', './Runtime/');
//定义网站物理路径
define('ROOT_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR);
// 引入ThinkPHP入口文件
$file = ROOT_PATH . "Common/Conf/install.lock'";
if (is_file(APP_PATH . 'Common/Conf/install.lock') == false) {
    define('BIND_MODULE', 'Install');
}
require './Inc/ThinkPHP.php';
// 亲^_^ 后面不需要任何代码了 就是如此简单
\Think\App::run();