Constants

VERSION

VERSION = '5.1.35 LTS'

Properties

$build

$build : \think\Build

Type

\think\Build

$cache

$cache : \think\Cache

Type

\think\Cache

$config

$config : \think\Config

Type

\think\Config

$cookie

$cookie : \think\Cookie

Type

\think\Cookie

$debug

$debug : \think\Debug

Type

\think\Debug

$env

$env : \think\Env

Type

\think\Env

$hook

$hook : \think\Hook

Type

\think\Hook

$lang

$lang : \think\Lang

Type

\think\Lang

$middleware

$middleware : \think\Middleware

Type

\think\Middleware

$request

$request : \think\Request

Type

\think\Request

$response

$response : \think\Response

Type

\think\Response

$route

$route : \think\Route

Type

\think\Route

$session

$session : \think\Session

Type

\think\Session

$template

$template : \think\Template

Type

\think\Template

$url

$url : \think\Url

Type

\think\Url

$validate

$validate : \think\Validate

Type

\think\Validate

$view

$view : \think\View

Type

\think\View

$rule_name

$rule_name : \think\route\RuleName

Type

\think\route\RuleName

$log

$log : \think\Log

Type

\think\Log

$instance

$instance : \think\Container

容器对象实例

Type

\think\Container

$instances

$instances : array

容器中的对象实例

Type

array

$bind

$bind : array

容器绑定标识

Type

array

$name

$name : array

容器标识别名

Type

array

$modulePath

$modulePath : string

当前模块路径

Type

string

$appDebug

$appDebug : boolean

应用调试模式

Type

boolean

$beginTime

$beginTime : float

应用开始时间

Type

float

$beginMem

$beginMem : integer

应用内存初始占用

Type

integer

$namespace

$namespace : string

应用类库命名空间

Type

string

$suffix

$suffix : boolean

应用类库后缀

Type

boolean

$routeMust

$routeMust : boolean

严格路由检测

Type

boolean

$appPath

$appPath : string

应用类库目录

Type

string

$thinkPath

$thinkPath : string

框架目录

Type

string

$rootPath

$rootPath : string

应用根目录

Type

string

$runtimePath

$runtimePath : string

运行时目录

Type

string

$configPath

$configPath : string

配置目录

Type

string

$routePath

$routePath : string

路由目录

Type

string

$configExt

$configExt : string

配置后缀

Type

string

$bindModule

$bindModule : string

绑定模块(控制器)

Type

string

$initialized

$initialized : boolean

初始化

Type

boolean

Methods

getInstance()

getInstance() : static

获取当前容器的实例(单例)

Returns

static

setInstance()

setInstance(object  $instance) : void

设置当前容器的实例

Parameters

object $instance

get()

get(string  $abstract, array|true  $vars = array(), boolean  $newInstance = false) : object

获取容器中的对象实例

Parameters

string $abstract

类名或者标识

array|true $vars

变量

boolean $newInstance

是否每次创建新的实例

Returns

object

set()

set(string  $abstract, mixed  $concrete = null) : \think\Container

绑定一个类、闭包、实例、接口实现到容器

Parameters

string $abstract

类标识、接口

mixed $concrete

要绑定的类、闭包或者实例

Returns

\think\Container

remove()

remove(string  $abstract) : void

移除容器中的对象实例

Parameters

string $abstract

类标识、接口

clear()

clear() : void

清除容器中的对象实例

bindTo()

bindTo(string|array  $abstract, mixed  $concrete = null) : $this

绑定一个类、闭包、实例、接口实现到容器

Parameters

string|array $abstract

类标识、接口

mixed $concrete

要绑定的类、闭包或者实例

Returns

$this

instance()

instance(string  $abstract, object|\Closure  $instance) : $this

绑定一个类实例当容器

Parameters

string $abstract

类名或者标识

object|\Closure $instance

类的实例

Returns

$this

bound()

bound(string  $abstract) : boolean

判断容器中是否存在类及标识

Parameters

string $abstract

类名或者标识

Returns

boolean

exists()

exists(string  $abstract) : boolean

判断容器中是否存在对象实例

Parameters

string $abstract

类名或者标识

Returns

boolean

has()

has(string  $name) : boolean

判断容器中是否存在类及标识

Parameters

string $name

类名或者标识

Returns

boolean

make()

make(string  $abstract, array|true  $vars = array(), boolean  $newInstance = false) : object

创建类的实例

Parameters

string $abstract

类名或者标识

array|true $vars

变量

boolean $newInstance

是否每次创建新的实例

Returns

object

delete()

delete(string|array  $abstract) : void

删除容器中的对象实例

Parameters

string|array $abstract

类名或者标识

all()

all() : array

获取容器中的对象实例

Returns

array

flush()

flush() : void

清除容器中的对象实例

invokeFunction()

invokeFunction(mixed  $function, array  $vars = array()) : mixed

执行函数或者闭包方法 支持参数调用

Parameters

mixed $function

函数或者闭包

array $vars

参数

Returns

mixed

invokeMethod()

invokeMethod(mixed  $method, array  $vars = array()) : mixed

调用反射执行类的方法 支持参数绑定

Parameters

mixed $method

方法

array $vars

参数

Returns

mixed

invokeReflectMethod()

invokeReflectMethod(object  $instance, mixed  $reflect, array  $vars = array()) : mixed

调用反射执行类的方法 支持参数绑定

Parameters

object $instance

对象实例

mixed $reflect

反射类

array $vars

参数

Returns

mixed

invoke()

invoke(mixed  $callable, array  $vars = array()) : mixed

调用反射执行callable 支持参数绑定

Parameters

mixed $callable
array $vars

参数

Returns

mixed

invokeClass()

invokeClass(string  $class, array  $vars = array()) : mixed

调用反射执行类的实例化 支持依赖注入

Parameters

string $class

类名

array $vars

参数

Returns

mixed

__set()

__set(  $name,   $value) 

Parameters

$name
$value

__get()

__get(  $name) 

Parameters

$name

__isset()

__isset(  $name) 

Parameters

$name

__unset()

__unset(  $name) 

Parameters

$name

offsetExists()

offsetExists(  $key) 

Parameters

$key

offsetGet()

offsetGet(  $key) 

Parameters

$key

offsetSet()

offsetSet(  $key,   $value) 

Parameters

$key
$value

offsetUnset()

offsetUnset(  $key) 

Parameters

$key

count()

count() 

getIterator()

getIterator() 

__debugInfo()

__debugInfo() 

__construct()

__construct(  $appPath = '') 

Parameters

$appPath

bind()

bind(string  $bind) : $this

绑定模块或者控制器

Parameters

string $bind

Returns

$this

path()

path(string  $path) : $this

设置应用类库目录

Parameters

string $path

路径

Returns

$this

initialize()

initialize() : void

初始化应用

init()

init(string  $module = '') : void

初始化应用或模块

Parameters

string $module

模块名

run()

run() : \think\Response

执行应用程序

Throws

\think\Exception

Returns

\think\Response

checkRequestCache()

checkRequestCache(string  $key, mixed  $expire = null, array  $except = array(), string  $tag = null) : void

设置当前地址的请求缓存

Parameters

string $key

缓存标识,支持变量规则 ,例如 item/:name/:id

mixed $expire

缓存有效期

array $except

缓存排除

string $tag

缓存标签

setResponseCache()

setResponseCache(  $cache) 

Parameters

$cache

dispatch()

dispatch(\think\route\Dispatch  $dispatch) : $this

设置当前请求的调度信息

Parameters

\think\route\Dispatch $dispatch

调度信息

Returns

$this

log()

log(mixed  $msg, string  $type = 'info') : void

记录调试信息

Parameters

mixed $msg

调试信息

string $type

信息类型

config()

config(string  $name = '') : mixed

获取配置参数 为空则获取所有配置

Parameters

string $name

配置参数名(支持二级配置 .号分割)

Returns

mixed

routeInit()

routeInit() : void

路由初始化 导入路由定义规则

routeCheck()

routeCheck() : \think\route\Dispatch

URL路由检测(根据PATH_INFO)

Returns

\think\route\Dispatch

routeMust()

routeMust(boolean  $must = false) : $this

设置应用的路由检测机制

Parameters

boolean $must

是否强制检测路由

Returns

$this

create()

create(string  $name, string  $layer, boolean  $appendSuffix = false, string  $common = 'common') : object

实例化应用类库

Parameters

string $name

类名称

string $layer

业务层名称

boolean $appendSuffix

是否添加类名后缀

string $common

公共模块名

Throws

\think\exception\ClassNotFoundException

Returns

object

model()

model(string  $name = '', string  $layer = 'model', boolean  $appendSuffix = false, string  $common = 'common') : \think\Model

实例化(分层)模型

Parameters

string $name

Model名称

string $layer

业务层名称

boolean $appendSuffix

是否添加类名后缀

string $common

公共模块名

Throws

\think\exception\ClassNotFoundException

Returns

\think\Model

controller()

controller(string  $name, string  $layer = 'controller', boolean  $appendSuffix = false, string  $empty = '') : object

实例化(分层)控制器 格式:[模块名/]控制器名

Parameters

string $name

资源地址

string $layer

控制层名称

boolean $appendSuffix

是否添加类名后缀

string $empty

空控制器名称

Throws

\think\exception\ClassNotFoundException

Returns

object

validate()

validate(string  $name = '', string  $layer = 'validate', boolean  $appendSuffix = false, string  $common = 'common') : \think\Validate

实例化验证类 格式:[模块名/]验证器名

Parameters

string $name

资源地址

string $layer

验证层名称

boolean $appendSuffix

是否添加类名后缀

string $common

公共模块名

Throws

\think\exception\ClassNotFoundException

Returns

\think\Validate

db()

db(mixed  $config = array(), boolean|string  $name = false) : \think\db\Query

数据库初始化

Parameters

mixed $config

数据库配置

boolean|string $name

连接标识 true 强制重新连接

Returns

\think\db\Query

action()

action(string  $url, string|array  $vars = array(), string  $layer = 'controller', boolean  $appendSuffix = false) : mixed

远程调用模块的操作方法 参数格式 [模块/控制器/]操作

Parameters

string $url

调用地址

string|array $vars

调用参数 支持字符串和数组

string $layer

要调用的控制层名称

boolean $appendSuffix

是否添加类名后缀

Throws

\think\exception\ClassNotFoundException

Returns

mixed

parseClass()

parseClass(string  $module, string  $layer, string  $name, boolean  $appendSuffix = false) : string

解析应用类的类名

Parameters

string $module

模块名

string $layer

层名 controller model ...

string $name

类名

boolean $appendSuffix

Returns

string

version()

version() : string

获取框架版本

Returns

string

isDebug()

isDebug() : boolean

是否为调试模式

Returns

boolean

getModulePath()

getModulePath() : string

获取模块路径

Returns

string

setModulePath()

setModulePath(string  $path) : void

设置模块路径

Parameters

string $path

路径

getRootPath()

getRootPath() : string

获取应用根目录

Returns

string

getAppPath()

getAppPath() : string

获取应用类库目录

Returns

string

getRuntimePath()

getRuntimePath() : string

获取应用运行时目录

Returns

string

getThinkPath()

getThinkPath() : string

获取核心框架目录

Returns

string

getRoutePath()

getRoutePath() : string

获取路由目录

Returns

string

getConfigPath()

getConfigPath() : string

获取应用配置目录

Returns

string

getConfigExt()

getConfigExt() : string

获取配置后缀

Returns

string

getNamespace()

getNamespace() : string

获取应用类库命名空间

Returns

string

setNamespace()

setNamespace(string  $namespace) : $this

设置应用类库命名空间

Parameters

string $namespace

命名空间名称

Returns

$this

getSuffix()

getSuffix() : boolean

是否启用类库后缀

Returns

boolean

getBeginTime()

getBeginTime() : float

获取应用开启时间

Returns

float

getBeginMem()

getBeginMem() : integer

获取应用初始内存占用

Returns

integer

bindParams()

bindParams(\ReflectionMethod|\ReflectionFunction  $reflect, array  $vars = array()) : array

绑定参数

Parameters

\ReflectionMethod|\ReflectionFunction $reflect

反射类

array $vars

参数

Returns

array

getObjectParam()

getObjectParam(string  $className, array  $vars) : mixed

获取对象类型的参数值

Parameters

string $className

类名

array $vars

参数

Returns

mixed

containerConfigUpdate()

containerConfigUpdate(  $module) 

Parameters

$module

getRouteCacheKey()

getRouteCacheKey() 

loadLangPack()

loadLangPack() 

parseModuleAndClass()

parseModuleAndClass(string  $name, string  $layer, boolean  $appendSuffix) : array

解析模块和类名

Parameters

string $name

资源地址

string $layer

验证层名称

boolean $appendSuffix

是否添加类名后缀

Returns

array