run() public static method

执行应用程序
public static run ( think\Request $request = null ) : Response
$request think\Request Request对象
return Response
Example #1
0
 public function testRun()
 {
     $response = App::run(Request::create("http://www.example.com"));
     $expectOutputString = '<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }</style><div style="padding: 24px 48px;"> <h1>:)</h1><p> ThinkPHP V5<br/><span style="font-size:30px">十年磨一剑 - 为API开发设计的高性能框架</span></p><span style="font-size:22px;">[ V5.0 版本由 <a href="http://www.qiniu.com" target="qiniu">七牛云</a> 独家赞助发布 ]</span></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>';
     $this->assertEquals($expectOutputString, $response->getContent());
     $this->assertEquals(200, $response->getCode());
     $this->assertEquals(true, function_exists('lang'));
     $this->assertEquals(true, function_exists('config'));
     $this->assertEquals(true, function_exists('input'));
     $this->assertEquals(Config::get('default_timezone'), date_default_timezone_get());
 }
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
 public function testRun()
 {
     Config::set('root_namespace', ['/path/']);
     App::run();
     $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>';
     $this->expectOutputString($expectOutputString);
     $rc = new ReflectionClass('\\think\\Loader');
     $ns = $rc->getProperty('namespace');
     $ns->setAccessible(true);
     $this->assertEquals(true, in_array('/path/', $ns->getValue()));
     $this->assertEquals(true, function_exists('L'));
     $this->assertEquals(true, function_exists('C'));
     $this->assertEquals(true, function_exists('I'));
     $this->assertEquals(Config::get('default_timezone'), date_default_timezone_get());
 }
Example #5
0
 public function testRun()
 {
     Config::set('root_namespace', ['/path/']);
     App::run();
     $expectOutputString = '<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }</style><div style="padding: 24px 48px;"> <h1>:)</h1><p> ThinkPHP V5<br/><span style="font-size:30px">十年磨一剑 - 为API开发设计的高性能框架</span></p><span style="font-size:22px;">[ V5.0 版本由 <a href="http://www.qiniu.com" target="qiniu">七牛云</a> 独家赞助发布 ]</span></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>';
     $this->expectOutputString($expectOutputString);
     $rc = new ReflectionClass('\\think\\Loader');
     $ns = $rc->getProperty('namespace');
     $ns->setAccessible(true);
     $this->assertEquals(true, in_array('/path/', $ns->getValue()));
     $this->assertEquals(true, function_exists('L'));
     $this->assertEquals(true, function_exists('C'));
     $this->assertEquals(true, function_exists('I'));
     $this->assertEquals(Config::get('default_timezone'), date_default_timezone_get());
 }
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
 public function testRun()
 {
     \think\App::run();
     // todo...
 }
Example #8
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 #9
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 #10
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 #11
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 #12
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();