请求处理
namespace ginkgo;
class Request {
// 属性
public $route = array(
'mod' => 'index',
'ctrl' => 'index',
'act' => 'index',
);
public $routeOrig = array(
'mod' => 'index',
'ctrl' => 'index',
'act' => 'index',
);
public $param = array();
public $mimeType = array(
'json' => array(
'application/json',
'text/x-json',
'application/jsonrequest',
'text/json',
),
'html' => array(
'text/html',
'application/xhtml+xml',
'*/*',
),
'xml' => array(
'application/xml',
'text/xml',
'application/x-xml',
),
'js' => array(
'text/javascript',
'application/javascript',
'application/x-javascript',
),
'css' => array(
'text/css',
),
'rss' => array(
'application/rss+xml',
),
'yaml' => array(
'application/x-yaml',
'text/yaml',
),
'atom' => array(
'application/atom+xml',
),
'pdf' => array(
'application/pdf',
),
'text' => array(
'text/plain',
),
'image' => array(
'image/png',
'image/jpg',
'image/jpeg',
'image/pjpeg',
'image/gif',
'image/webp',
'image/*',
),
'csv' => array(
'text/csv',
),
);
protected static $instance;
// 方法
public static instance() : object
public setRoute( string $name [, string $value ] )
public setRouteOrig( string $name [, string $value ] )
public setParam( string $name [, string $value ] )
public route( [ mixed $name = false ] ) : mixed
public routeOrig( [ mixed $name = false ] ) : mixed
public param( [ mixed $name = true [, string $type = 'str' [, mixed $default [, bool $htmlmode = false ]]]] ) : mixed
public get( [ mixed $name = true [, string $type = 'str' [, mixed $default [, bool $htmlmode = false ]]]] ) : mixed
public post( [ mixed $name = true [, string $type = 'str' [, mixed $default [, bool $htmlmode = false ]]]] ) : mixed
public request( [ mixed $name = true [, string $type = 'str' [, mixed $default [, bool $htmlmode = false ]]]] ) : mixed
public server( [ string $name ] ) : mixed
public session( [ string $name ] ) : mixed
public cookie( [ string $name ] ) : mixed
public accept() : string
public type() : string
public mimeType( mixed $type [, mixed $value ] )
public ip() : string
public method() : string
public isGet() : bool
public isPost() : bool
public isAjax() : bool
public isPjax() : bool
public isSsl() : bool
public isMobile() : bool
public root( [ bool $with_domain = false ] ) : string
public url( [ bool $with_domain = false ] ) : string
public domain() : string
public host( [ bool $strict = false ] ) : string
public scheme() : string
public header( [ string $name [, string $separator = '-' ]] ) : mixed
public token() : array
public checkDuplicate( [ string $method = 'POST' ] ) : bool
public setDuplicate( [ string $method = 'POST' ] )
public baseFile() : string
public baseUrl( [ bool $with_domain = false [, string $route_type ]] ) : string
public fillParam( array $data, array $param ) : array
public pagination( int $count [, int $perpage = 0 [, mixed $current = 'get' [, string $pageparam = 'page' [, int $pergroup = 0 ]]]] ) : array
public input( [ mixed $name = true [, string $type = 'str' [, mixed $default [, bool $htmlmode = false ]]]] ) : mixed
protected __construct()
protected __clone()
private duplicateProcess( [ string $method = 'POST' ] ) : string
private varProcessR( [ mixed $name = true [, string $type = 'str' [, mixed $default [, bool $htmlmode = false [, array $var = array() ]]]]] ) : mixed
private varProcessS( [ mixed $name = true [, array $var = array() ]] ) : mixed
}
- | 权限 | 类型 | 描述 |
---|---|---|---|
属性 | - | - | - |
$route |
public | string | 路由 |
$routeOrig |
public | string | 原始路由 |
$param |
public | array | 参数 |
$mimeType |
public | array | 常用 MIME 类型 |
$instance |
protected | object static | 本类实例 |
方法 | - | - | - |
instance() | public | static | 实例化 |
setRoute() | public | 设置路由 | |
setRouteOrig() | public | 设置原始路由 | |
setParam() | public | 设置参数 | |
route() | public | 取得路由 | |
routeOrig() | public | 取得原始路由 | |
param() | public | 取得路由参数 | |
get() | public | get 方法取得变量 | |
post() | public | post 方法取得变量 | |
request() | public | request 方法取得变量 | |
server() | public | 取得服务器变量 | |
session() | public | 取得会话变量 | |
cookie() | public | 取得 Cookie | |
accept() | public | 取得请求类型 | |
type() | public | 取得输出类型 | |
mimeType() | public | 设置 $mimeType |
|
ip() | public | 取得 IP 地址 | |
method() | public | 取得请求方法 | |
isGet() | public | 是否 get 请求 | |
isPost() | public | 是否 post 请求 | |
isAjax() | public | 是否 ajax 请求 | |
isPjax() | public | 是否 pjax 请求 | |
isSsl() | public | 是否 ssl 请求 | |
isMobile() | public | 客户端是否移动设备 | |
root() | public | 当前请求的根路径 | |
url() | public | 当前请求的 URL | |
domain() | public | 当前请求的域名(带协议) | |
host() | public | 当前请求的主机名 | |
scheme() | public | 当前请求的协议 | |
header() | public | 当前请求头信息 | |
token() | public | 取得表单令牌 | |
checkDuplicate() | public | 验证是否重复提交 | |
setDuplicate() | public | 设置重复提交 | |
baseFile() | public | 取得入口文件 | |
baseUrl() | public | 取得入口文件的 URL | |
fillParam() | public | 填充参数 | |
pagination() | public | 取得分页参数 | |
input() | public | 处理输入参数 | |
__construct() | protected | 同 instance() | |
__clone() | protected | 克隆,无实际功能,仅供限制为单例模式使用 | |
duplicateProcess() | private | 重复提交处理 | |
varProcessR() | private | 变量处理 | |
varProcessS() | private | 变量处理 |
$route
路由、$routeOrig
原始路由public $route;
public $routeOrig;
结构
名称 | 类型 | 默认 | 描述 |
---|---|---|---|
mod | string | 模块 | |
ctrl | string | 控制器 | |
act | string | 动作 |
$mimeType
常用 MIME 类型public $mimeType = array(
'json' => array(
'application/json',
'text/x-json',
'application/jsonrequest',
'text/json',
),
'html' => array(
'text/html',
'application/xhtml+xml',
'*/*',
),
'xml' => array(
'application/xml',
'text/xml',
'application/x-xml',
),
'js' => array(
'text/javascript',
'application/javascript',
'application/x-javascript',
),
'css' => array(
'text/css',
),
'rss' => array(
'application/rss+xml',
),
'yaml' => array(
'application/x-yaml',
'text/yaml',
),
'atom' => array(
'application/atom+xml',
),
'pdf' => array(
'application/pdf',
),
'text' => array(
'text/plain',
),
'image' => array(
'image/png',
'image/jpg',
'image/jpeg',
'image/pjpeg',
'image/gif',
'image/webp',
'image/*',
),
'csv' => array(
'text/csv',
),
);
instance()
实例化方法public static function instance() : object
参数
返回
setRoute()
设置路由 $route
public function setRoute( string $name [, string $value ] )
参数
name
路由名称
支持两种类型:字符串、数组,为数组时表示批量设置
value
路由值
当 name
为字符串时为必须,当 name
为数组时自动忽略。
返回
setRouteOrig()
设置原始路由 $routeOrig
public function setRouteOrig( string $name [, string $value ] )
参数
name
路由名称
支持两种类型:字符串、数组,为数组时表示批量设置
value
路由值
当 name
为字符串时为必须,当 name
为数组时自动忽略。
返回
setParam()
设置参数public function setParam( string $name [, string $value ] )
参数
name
路由名称
支持两种类型:字符串、数组,为数组时表示批量设置
value
路由值
当 name
为字符串时为必须,当 name
为数组时自动忽略。
返回
route()
取得路由 $route
public function route( [ mixed $name = false ] ) : mixed
参数
name
路由名称返回
routeOrig()
取得原始路由 $routeOrig
public function routeOrig( [ mixed $name = false ] ) : mixed
参数
name
路由名称返回
param()
取得路由参数public function param( [ mixed $name = true [, string $type = 'str' [, mixed $default [, bool $htmlmode = false ]]]] ) : mixed
参数
name
参数名称type
类型default
默认值htmlmode
是否 html 模式返回
get()
get 方法取得变量public function get( [ mixed $name = true [, string $type = 'str' [, mixed $default [, bool $htmlmode = false ]]]] ) : mixed
参数
name
名称type
类型default
默认值htmlmode
是否 html 模式返回
post()
post 方法取得变量public function post( [ mixed $name = true [, string $type = 'str' [, mixed $default [, bool $htmlmode = false ]]]] ) : mixed
参数
name
名称type
类型default
默认值htmlmode
是否 html 模式返回
request()
request 方法取得变量public function request( [ mixed $name = true [, string $type = 'str' [, mixed $default [, bool $htmlmode = false ]]]] ) : mixed
参数
name
名称type
类型default
默认值htmlmode
是否 html 模式返回
server()
取得服务器变量public function server( [ string $name ] ) : mixed
参数
name
名称返回
session()
取得会话变量public function session( [ string $name ] ) : mixed
参数
name
名称返回
cookie()
取得 Cookiepublic function cookie( [ string $name ] ) : mixed
参数
name
名称返回
accept()
取得请求类型public function accept() : string
参数
返回
type()
取得输出类型public function type() : string
参数
rule
生成文件名规则(函数名)返回
mimeType()
设置 $mimeType
public function mimeType( mixed $type [, mixed $value ] )
参数
path
图片路径返回
ip()
取得 IP 地址public function ip() : string
参数
返回
method()
取得请求方法public function method() : string
参数
返回
isGet()
是否 get 请求public function isGet() : bool
参数
返回
isPost()
是否 post 请求public function isPost() : bool
参数
返回
isAjax()
是否 ajax 请求public function isAjax() : bool
参数
返回
isPjax()
是否 pjax 请求public function isPjax() : bool
参数
返回
isSsl()
是否 ssl 请求public function isSsl() : bool
参数
返回
isMobile()
客户端是否移动设备public function isMobile() : bool
参数
返回
root()
当前请求的根路径public function root( [ bool $with_domain = false ] ) : string
参数
with_domain
是否带域名返回
url()
当前请求的 URLpublic function url( [ bool $with_domain = false ] ) : string
参数
with_domain
是否带域名返回
domain()
当前请求的域名(带协议)public function domain() : string
参数
返回
host()
当前请求的主机名public function host( [ bool $strict = false ] ) : string
参数
strict
严格模式返回
scheme()
当前请求的协议public function scheme() : string
参数
返回
header()
当前请求头信息public function header( [ string $name [, string $separator = '-' ]] ) : mixed
参数
name
名称separator
分隔符返回
token()
取得表单令牌public function token() : array
参数
返回
array(
'name' => '__token__', // 表单名称
'value' => 'fwegweerIUreljiErl', // 令牌值
);
checkDuplicate()
验证是否重复提交public function checkDuplicate( [ string $method = 'POST' ] ) : bool
参数
method
方法返回
setDuplicate
设置重复提交public function setDuplicate( [ string $method = 'POST' ] )
参数
method
方法返回
baseFile
取得入口文件public function baseFile() : string
参数
返回
baseUrl
取得入口文件的 URLpublic function baseUrl( [ bool $with_domain = false [, string $route_type ]] ) : string
参数
with_domain
是否带域名route_type
路由类型返回
fillParam
填充参数根据 param
规定的结构,将 data
数据填充完整
public function fillParam( array $data, array $param ) : array
参数
data
数据param
结构参数返回
pagination
取得分页参数public function pagination( int $count [, int $perpage = 0 [, mixed $current = 'get' [, string $pageparam = 'page' [, int $pergroup = 0 ]]]] ) : array
参数
count
总记录数perpage
每页记录数current
当前页码,为空时获取当前页码
混合型,默认为 get
可能的值
值 | 描述 |
---|---|
get | 用 get 方法获取页码 |
post | 用 post 方法获取页码 |
整数 | 当前页码 |
pageparam
分页参数
pergroup
每组页数返回
input
处理输入参数public function input( [ mixed $name = true [, string $type = 'str' [, mixed $default [, bool $htmlmode = false ]]]] ) : mixed
参数
name
名称type
类型default
默认值htmlmode
是否 html 模式返回
duplicateProcess
重复提交处理private function duplicateProcess( [ string $method = 'POST' ] ) : string
参数
method
方法返回
varProcessR
变量处理private function varProcessR( [ mixed $name = true [, string $type = 'str' [, mixed $default [, bool $htmlmode = false [, array $var = array() ]]]]] ) : mixed
参数
name
名称type
类型default
默认值htmlmode
是否 html 模式var
待处理值返回
varProcessS
变量处理private function varProcessS( [ mixed $name = true [, array $var = array() ]] ) : mixed
参数
name
名称var
待处理值返回