mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-03 05:52:48 +08:00
改进Request类支持静态调用
This commit is contained in:
@@ -195,7 +195,7 @@ class Request
|
||||
* @param string $url URL地址
|
||||
* @return string
|
||||
*/
|
||||
public function domain($domain = '')
|
||||
protected function domain($domain = '')
|
||||
{
|
||||
if (!empty($domain)) {
|
||||
$this->domain = $domain;
|
||||
@@ -213,7 +213,7 @@ class Request
|
||||
* @param bool $domain 是否需要域名
|
||||
* @return string
|
||||
*/
|
||||
public function url($url = '')
|
||||
protected function url($url = '')
|
||||
{
|
||||
if (is_string($url) && !empty($url)) {
|
||||
$this->url = $url;
|
||||
@@ -234,7 +234,7 @@ class Request
|
||||
* @param string $url URL地址
|
||||
* @return string
|
||||
*/
|
||||
public function baseUrl($url = '')
|
||||
protected function baseUrl($url = '')
|
||||
{
|
||||
if (is_string($url) && !empty($url)) {
|
||||
$this->baseUrl = $url;
|
||||
@@ -252,7 +252,7 @@ class Request
|
||||
* @param string $file 当前执行的文件
|
||||
* @return string
|
||||
*/
|
||||
public function baseFile($file = '')
|
||||
protected function baseFile($file = '')
|
||||
{
|
||||
if (is_string($file) && !empty($file)) {
|
||||
$this->baseFile = $file;
|
||||
@@ -284,7 +284,7 @@ class Request
|
||||
* @param string $url URL地址
|
||||
* @return string
|
||||
*/
|
||||
public function root($url = '')
|
||||
protected function root($url = '')
|
||||
{
|
||||
if (is_string($url) && !empty($url)) {
|
||||
$this->root = $url;
|
||||
@@ -304,7 +304,7 @@ class Request
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function pathinfo()
|
||||
protected function pathinfo()
|
||||
{
|
||||
if (is_null($this->pathinfo)) {
|
||||
if (isset($_GET[Config::get('var_pathinfo')])) {
|
||||
@@ -336,7 +336,7 @@ class Request
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function path()
|
||||
protected function path()
|
||||
{
|
||||
if (is_null($this->path)) {
|
||||
// 去除正常的URL后缀
|
||||
@@ -350,7 +350,7 @@ class Request
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function ext()
|
||||
protected function ext()
|
||||
{
|
||||
return pathinfo($this->pathinfo(), PATHINFO_EXTENSION);
|
||||
}
|
||||
@@ -361,7 +361,7 @@ class Request
|
||||
* @param bool $float 是否使用浮点类型
|
||||
* @return integer|float
|
||||
*/
|
||||
public function time($float = false)
|
||||
protected function time($float = false)
|
||||
{
|
||||
return $float ? $_SERVER['REQUEST_TIME_FLOAT'] : $_SERVER['REQUEST_TIME'];
|
||||
}
|
||||
@@ -371,7 +371,7 @@ class Request
|
||||
* @access public
|
||||
* @return false|string
|
||||
*/
|
||||
public function type()
|
||||
protected function type()
|
||||
{
|
||||
$accept = isset($this->server['HTTP_ACCEPT']) ? $this->server['HTTP_ACCEPT'] : $_SERVER['HTTP_ACCEPT'];
|
||||
if (empty($accept)) {
|
||||
@@ -396,7 +396,7 @@ class Request
|
||||
* @param string $val 资源类型
|
||||
* @return void
|
||||
*/
|
||||
public function mimeType($type, $val = '')
|
||||
protected function mimeType($type, $val = '')
|
||||
{
|
||||
if (is_array($type)) {
|
||||
$this->mimeType = array_merge($this->mimeType, $type);
|
||||
@@ -411,7 +411,7 @@ class Request
|
||||
* @param string $method 请求类型
|
||||
* @return string
|
||||
*/
|
||||
public function method($method = '')
|
||||
protected function method($method = '')
|
||||
{
|
||||
if ($method) {
|
||||
$this->method = $method;
|
||||
@@ -427,7 +427,7 @@ class Request
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function isGet()
|
||||
protected function isGet()
|
||||
{
|
||||
return $this->method() == 'GET';
|
||||
}
|
||||
@@ -437,7 +437,7 @@ class Request
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function isPost()
|
||||
protected function isPost()
|
||||
{
|
||||
return $this->method() == 'POST';
|
||||
}
|
||||
@@ -447,7 +447,7 @@ class Request
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function isPut()
|
||||
protected function isPut()
|
||||
{
|
||||
return $this->method() == 'PUT';
|
||||
}
|
||||
@@ -457,7 +457,7 @@ class Request
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function isDelete()
|
||||
protected function isDelete()
|
||||
{
|
||||
return $this->method() == 'DELETE';
|
||||
}
|
||||
@@ -467,7 +467,7 @@ class Request
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function isCli()
|
||||
protected function isCli()
|
||||
{
|
||||
return PHP_SAPI == 'cli';
|
||||
}
|
||||
@@ -477,7 +477,7 @@ class Request
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function isCgi()
|
||||
protected function isCgi()
|
||||
{
|
||||
return strpos(PHP_SAPI, 'cgi') === 0;
|
||||
}
|
||||
@@ -489,7 +489,7 @@ class Request
|
||||
* @param mixed $default 默认值
|
||||
* @return mixed
|
||||
*/
|
||||
public function param($name = '', $default = null)
|
||||
protected function param($name = '', $default = null)
|
||||
{
|
||||
if (empty($this->param)) {
|
||||
$method = $this->method();
|
||||
@@ -524,7 +524,7 @@ class Request
|
||||
* @param bool $checkEmpty 是否检测空值
|
||||
* @return mixed
|
||||
*/
|
||||
public function has($name, $checkEmpty = false)
|
||||
protected function has($name, $checkEmpty = false)
|
||||
{
|
||||
if (empty($this->param)) {
|
||||
$param = $this->param();
|
||||
@@ -544,7 +544,7 @@ class Request
|
||||
* @param string|array $name 变量名
|
||||
* @return mixed
|
||||
*/
|
||||
public function only($name)
|
||||
protected function only($name)
|
||||
{
|
||||
$param = $this->param();
|
||||
if (is_string($name)) {
|
||||
@@ -565,7 +565,7 @@ class Request
|
||||
* @param string|array $name 变量名
|
||||
* @return mixed
|
||||
*/
|
||||
public function except($name)
|
||||
protected function except($name)
|
||||
{
|
||||
$param = $this->param();
|
||||
if (is_string($name)) {
|
||||
@@ -585,7 +585,7 @@ class Request
|
||||
* @param string $name 变量名
|
||||
* @return mixed
|
||||
*/
|
||||
public function session($name = '')
|
||||
protected function session($name = '')
|
||||
{
|
||||
if (PHP_SESSION_DISABLED == session_status()) {
|
||||
session_start();
|
||||
@@ -599,7 +599,7 @@ class Request
|
||||
* @param string $name 变量名
|
||||
* @return mixed
|
||||
*/
|
||||
public function cookie($name = '')
|
||||
protected function cookie($name = '')
|
||||
{
|
||||
return Input::data($this->cookie ?: $_COOKIE, $name);
|
||||
}
|
||||
@@ -610,7 +610,7 @@ class Request
|
||||
* @param string $name 变量名
|
||||
* @return mixed
|
||||
*/
|
||||
public function server($name = '')
|
||||
protected function server($name = '')
|
||||
{
|
||||
return Input::data($this->server ?: $_SERVER, $name);
|
||||
}
|
||||
@@ -621,7 +621,7 @@ class Request
|
||||
* @param string $name 名称
|
||||
* @return null|array|\think\File
|
||||
*/
|
||||
public function file($name = '')
|
||||
protected function file($name = '')
|
||||
{
|
||||
return Input::file($name, $this->file ?: $_FILES);
|
||||
}
|
||||
@@ -631,7 +631,7 @@ class Request
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function isSsl()
|
||||
protected function isSsl()
|
||||
{
|
||||
$server = array_merge($_SERVER, $this->server);
|
||||
if (isset($server['HTTPS']) && ('1' == $server['HTTPS'] || 'on' == strtolower($server['HTTPS']))) {
|
||||
@@ -645,22 +645,32 @@ class Request
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前是否ajax请求
|
||||
* 当前是否Ajax请求
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function isAjax()
|
||||
protected function isAjax()
|
||||
{
|
||||
return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前是否Pjax请求
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
protected function isPjax()
|
||||
{
|
||||
return (isset($_SERVER['HTTP_X_PJAX']) && $_SERVER['HTTP_X_PJAX']) ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取客户端IP地址
|
||||
* @param integer $type 返回类型 0 返回IP地址 1 返回IPV4地址数字
|
||||
* @param boolean $adv 是否进行高级模式获取(有可能被伪装)
|
||||
* @return mixed
|
||||
*/
|
||||
public function ip($type = 0, $adv = false)
|
||||
protected function ip($type = 0, $adv = false)
|
||||
{
|
||||
$type = $type ? 1 : 0;
|
||||
static $ip = null;
|
||||
@@ -696,7 +706,7 @@ class Request
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function scheme()
|
||||
protected function scheme()
|
||||
{
|
||||
return $this->isSsl() ? 'https' : 'http';
|
||||
}
|
||||
@@ -706,7 +716,7 @@ class Request
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function query()
|
||||
protected function query()
|
||||
{
|
||||
return $this->server('QUERY_STRING');
|
||||
}
|
||||
@@ -716,7 +726,7 @@ class Request
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function host()
|
||||
protected function host()
|
||||
{
|
||||
return $this->server('HTTP_HOST');
|
||||
}
|
||||
@@ -726,7 +736,7 @@ class Request
|
||||
* @access public
|
||||
* @return integer
|
||||
*/
|
||||
public function port()
|
||||
protected function port()
|
||||
{
|
||||
return $this->server('SERVER_PORT');
|
||||
}
|
||||
@@ -736,7 +746,7 @@ class Request
|
||||
* @access public
|
||||
* @return integer
|
||||
*/
|
||||
public function protocol()
|
||||
protected function protocol()
|
||||
{
|
||||
return $this->server('SERVER_PROTOCOL');
|
||||
}
|
||||
@@ -746,7 +756,7 @@ class Request
|
||||
* @access public
|
||||
* @return integer
|
||||
*/
|
||||
public function remotePort()
|
||||
protected function remotePort()
|
||||
{
|
||||
return $this->server('REMOTE_PORT');
|
||||
}
|
||||
@@ -757,7 +767,7 @@ class Request
|
||||
* @param array $route 路由名称
|
||||
* @return array
|
||||
*/
|
||||
public function route($route = [])
|
||||
protected function route($route = [])
|
||||
{
|
||||
if (!empty($route)) {
|
||||
$this->route = $route;
|
||||
@@ -772,7 +782,7 @@ class Request
|
||||
* @param array $dispatch 调度信息
|
||||
* @return array
|
||||
*/
|
||||
public function dispatch($dispatch = [])
|
||||
protected function dispatch($dispatch = [])
|
||||
{
|
||||
if (!empty($dispatch)) {
|
||||
$this->dispatch = $dispatch;
|
||||
@@ -780,4 +790,18 @@ class Request
|
||||
return $this->dispatch;
|
||||
}
|
||||
|
||||
public static function __callStatic($method, $params)
|
||||
{
|
||||
if (is_null(self::$instance)) {
|
||||
self::instance();
|
||||
}
|
||||
return call_user_func_array([self::$instance, $method], $params);
|
||||
}
|
||||
|
||||
public function __call($method, $params)
|
||||
{
|
||||
if (method_exists($this, $method)) {
|
||||
return call_user_func_array([$this, $method], $params);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user