改进Request类

This commit is contained in:
thinkphp
2016-06-01 21:19:07 +08:00
parent dd906ccaf2
commit 357d5c0e00
2 changed files with 9 additions and 8 deletions

View File

@@ -271,9 +271,7 @@ class App
// 设置当前请求的模块、控制器、操作 // 设置当前请求的模块、控制器、操作
$request = Request::instance(); $request = Request::instance();
$request->module($module); $request->module($module)->controller($controller)->action($actionName);
$request->controller($controller);
$request->action($actionName);
// 监听module_init // 监听module_init
Hook::listen('module_init', $request); Hook::listen('module_init', $request);

View File

@@ -203,7 +203,7 @@ class Request
{ {
if (!empty($domain)) { if (!empty($domain)) {
$this->domain = $domain; $this->domain = $domain;
return; return $this;
} elseif (!$this->domain) { } elseif (!$this->domain) {
$this->domain = $this->scheme() . '://' . $this->host(); $this->domain = $this->scheme() . '://' . $this->host();
} }
@@ -220,7 +220,7 @@ class Request
{ {
if (is_string($url) && !empty($url)) { if (is_string($url) && !empty($url)) {
$this->url = $url; $this->url = $url;
return; return $this;
} elseif (!$this->url) { } elseif (!$this->url) {
if (IS_CLI) { if (IS_CLI) {
$this->url = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : ''; $this->url = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : '';
@@ -247,7 +247,7 @@ class Request
{ {
if (is_string($url) && !empty($url)) { if (is_string($url) && !empty($url)) {
$this->baseUrl = $url; $this->baseUrl = $url;
return; return $this;
} elseif (!$this->baseUrl) { } elseif (!$this->baseUrl) {
$str = $this->url(); $str = $this->url();
$this->baseUrl = strpos($str, '?') ? strstr($str, '?', true) : $str; $this->baseUrl = strpos($str, '?') ? strstr($str, '?', true) : $str;
@@ -265,7 +265,7 @@ class Request
{ {
if (is_string($file) && !empty($file)) { if (is_string($file) && !empty($file)) {
$this->baseFile = $file; $this->baseFile = $file;
return; return $this;
} elseif (!$this->baseFile) { } elseif (!$this->baseFile) {
$url = ''; $url = '';
if (!IS_CLI) { if (!IS_CLI) {
@@ -297,7 +297,7 @@ class Request
{ {
if (is_string($url) && !empty($url)) { if (is_string($url) && !empty($url)) {
$this->root = $url; $this->root = $url;
return; return $this;
} elseif (!$this->root) { } elseif (!$this->root) {
$file = $this->baseFile(); $file = $this->baseFile();
if ($file && 0 !== strpos($this->url(), $file)) { if ($file && 0 !== strpos($this->url(), $file)) {
@@ -922,6 +922,7 @@ class Request
{ {
if (!is_null($module)) { if (!is_null($module)) {
$this->module = $module; $this->module = $module;
return $this;
} else { } else {
return $this->module ?: ''; return $this->module ?: '';
} }
@@ -937,6 +938,7 @@ class Request
{ {
if (!is_null($controller)) { if (!is_null($controller)) {
$this->controller = $controller; $this->controller = $controller;
return $this;
} else { } else {
return $this->controller ?: ''; return $this->controller ?: '';
} }
@@ -952,6 +954,7 @@ class Request
{ {
if (!is_null($action)) { if (!is_null($action)) {
$this->action = $action; $this->action = $action;
return $this;
} else { } else {
return $this->action ?: ''; return $this->action ?: '';
} }