PHP Class think\Loader

Show file Open project: top-think/framework Class Usage Examples

Protected Properties

Property Type Description
$instance
$map 类名映射
$namespaceAlias 命名空间别名

Public Methods

Method Description
action ( string $url, string | array $vars = [], string $layer = 'controller', boolean $appendSuffix = false ) : mixed 远程调用模块的操作方法 参数格式 [模块/控制器/]操作
addClassMap ( $class, $map = '' ) 注册classmap
addNamespace ( $namespace, $path = '' ) 注册命名空间
addNamespaceAlias ( $namespace, $original = '' ) 注册命名空间别名
autoload ( $class ) 自动加载
clearInstance ( ) : void 初始化类的实例
controller ( string $name, string $layer = 'controller', boolean $appendSuffix = false, string $empty = '' ) : Object | false 实例化(分层)控制器 格式:[模块名/]控制器名
db ( mixed $config = [], boolean | string $name = false ) : Connection 数据库初始化 并取得数据库类实例
import ( string $class, string $baseUrl = '', string $ext = EXT ) : boolean 导入所需的类库 同java的Import 本函数有缓存功能
model ( string $name = '', string $layer = 'model', boolean $appendSuffix = false, string $common = 'common' ) : Object 实例化(分层)模型
parseClass ( string $module, string $layer, string $name, boolean $appendSuffix = false ) : string 解析应用类的类名
parseName ( string $name, integer $type ) : string 字符串命名风格转换 type 0 将Java风格转换为C的风格 1 将C风格转换为Java的风格
register ( $autoload = '' ) 注册自动加载机制
validate ( string $name = '', string $layer = 'validate', boolean $appendSuffix = false, string $common = 'common' ) : Object | false 实例化验证类 格式:[模块名/]验证器名

Private Methods

Method Description
addPsr0 ( $prefix, $paths, $prepend = false ) 添加Ps0空间
addPsr4 ( $prefix, $paths, $prepend = false ) 添加Psr4空间
findFile ( $class ) : boolean 查找文件
registerComposerLoader ( ) 注册composer自动加载

Method Details

action() public static method

远程调用模块的操作方法 参数格式 [模块/控制器/]操作
public static action ( string $url, string | array $vars = [], string $layer = 'controller', boolean $appendSuffix = false ) : mixed
$url string 调用地址
$vars string | array 调用参数 支持字符串和数组
$layer string 要调用的控制层名称
$appendSuffix boolean 是否添加类名后缀
return mixed

addClassMap() public static method

注册classmap
public static addClassMap ( $class, $map = '' )

addNamespace() public static method

注册命名空间
public static addNamespace ( $namespace, $path = '' )

addNamespaceAlias() public static method

注册命名空间别名
public static addNamespaceAlias ( $namespace, $original = '' )

autoload() public static method

自动加载
public static autoload ( $class )

clearInstance() public static method

初始化类的实例
public static clearInstance ( ) : void
return void

controller() public static method

实例化(分层)控制器 格式:[模块名/]控制器名
public static controller ( string $name, string $layer = 'controller', boolean $appendSuffix = false, string $empty = '' ) : Object | false
$name string 资源地址
$layer string 控制层名称
$appendSuffix boolean 是否添加类名后缀
$empty string 空控制器名称
return Object | false

db() public static method

数据库初始化 并取得数据库类实例
public static db ( mixed $config = [], boolean | string $name = false ) : Connection
$config mixed 数据库配置
$name boolean | string 连接标识 true 强制重新连接
return Think\Db\Connection

import() public static method

导入所需的类库 同java的Import 本函数有缓存功能
public static import ( string $class, string $baseUrl = '', string $ext = EXT ) : boolean
$class string 类库命名空间字符串
$baseUrl string 起始路径
$ext string 导入的文件扩展名
return boolean

model() public static method

实例化(分层)模型
public static model ( string $name = '', string $layer = 'model', boolean $appendSuffix = false, string $common = 'common' ) : Object
$name string Model名称
$layer string 业务层名称
$appendSuffix boolean 是否添加类名后缀
$common string 公共模块名
return Object

parseClass() public static method

解析应用类的类名
public static parseClass ( string $module, string $layer, string $name, boolean $appendSuffix = false ) : string
$module string 模块名
$layer string 层名 controller model ...
$name string 类名
$appendSuffix boolean
return string

parseName() public static method

字符串命名风格转换 type 0 将Java风格转换为C的风格 1 将C风格转换为Java的风格
public static parseName ( string $name, integer $type ) : string
$name string 字符串
$type integer 转换类型
return string

register() public static method

注册自动加载机制
public static register ( $autoload = '' )

validate() public static method

实例化验证类 格式:[模块名/]验证器名
public static validate ( string $name = '', string $layer = 'validate', boolean $appendSuffix = false, string $common = 'common' ) : Object | false
$name string 资源地址
$layer string 验证层名称
$appendSuffix boolean 是否添加类名后缀
$common string 公共模块名
return Object | false

Property Details

$instance protected static property

protected static $instance

$map protected static property

类名映射
protected static $map

$namespaceAlias protected static property

命名空间别名
protected static $namespaceAlias