API 文档 - ginkgo


ginkgo\Request

请求处理


类摘要

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 模式

返回

  • get 变量

post() post 方法取得变量

public function post( [ mixed $name = true [, string $type = 'str' [, mixed $default [, bool $htmlmode = false ]]]] ) : mixed

参数

  • name 名称
  • type 类型
  • default 默认值
  • htmlmode 是否 html 模式

返回

  • post 变量

request() request 方法取得变量

public function request( [ mixed $name = true [, string $type = 'str' [, mixed $default [, bool $htmlmode = false ]]]] ) : mixed

参数

  • name 名称
  • type 类型
  • default 默认值
  • htmlmode 是否 html 模式

返回

  • request 变量

server() 取得服务器变量

public function server( [ string $name ] ) : mixed

参数

  • name 名称

返回

  • 服务器变量

session() 取得会话变量

public function session( [ string $name ] ) : mixed

参数

  • name 名称

返回

  • 会话变量

cookie() 取得 Cookie

public function cookie( [ string $name ] ) : mixed

参数

  • name 名称

返回

  • Cookie

accept() 取得请求类型

public function accept() : string

参数

返回

  • MIME 类型

type() 取得输出类型

public function type() : string

参数

  • rule 生成文件名规则(函数名)

返回

  • 输出类型

mimeType() 设置 $mimeType

public function mimeType( mixed $type [, mixed $value ] )

参数

  • path 图片路径

返回


ip() 取得 IP 地址

public function ip() : string

参数

返回

  • IP 地址

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() 当前请求的 URL

public function url( [ bool $with_domain = false ] ) : string

参数

  • with_domain 是否带域名

返回

  • URL

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 取得入口文件的 URL

public function baseUrl( [ bool $with_domain = false [, string $route_type ]] ) : string

参数

  • with_domain 是否带域名
  • route_type 路由类型

返回

  • 入口文件的 URL

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 待处理值

返回

  • 变量

更新时间 10-15 12:29
Top