MyQEE 核心类
常量 | |
---|---|
Core::VERSION |
string(3) "3.1" |
Core::RELEASE |
string(3) "rc1" |
Core::CODER |
string(38) "呼吸二氧化碳 <jonwang@myqee.com>" |
API - Core_Core
- Core::$charset - 页面编码
- Core::$arguments - 页面传入的PATHINFO参数
- Core::$output - 页面输出内容
- Core::$autoload_dir_ext - 自动加载时各个文件夹后缀
- Core::setup - 系统启动
- Core::config - 获取指定key的配置
- Core::cookie - Cookie
- Core::route - 路由处理
- Core::url - 返回URL路径
- Core::url_assets - 返回静态资源URL路径
- Core::load_controller - Include一个指定URI的控制器
- Core::is_file_write_disabled - 是否系统设置禁用文件写入功能
- Core::log - 记录日志
- Core::execute - 执行指定URI的控制器
- Core::debug - 获取debug对象
- Core::debug_path - 将真实路径地址输出为调试地址
- Core::close_buffers - 关闭缓冲区
- Core::show_404 - 404,可直接将Exception对象传给$msg
- Core::show_500 - 系统错误,可直接将Exception对象传给$msg
- Core::key_string - 返回一个用.表示的字符串的key对应数组的内容
- Core::register_shutdown_function - 添加页面在关闭前执行的列队
- Core::shutdown_handler
- Core::exception_handler
- Core::error_handler
- Core::factory - 根据$objName返回一个实例化并静态存储的对象
- Core::factory_release - 释放对象以释放内存
- Core::reset_project - 将项目切换回初始项目
- Core::change_project - 切换到另外一个项目
- Core::change_project_add_callback - 增加change_project回调事件
- Core::change_project_remove_callback - 移除import_library回调事件
- Core::import_library - 导入指定类库
- Core::import_library_add_callback - 增加import_library回调事件
- Core::import_library_remove_callback - 移除import_library回调事件
- Core::close_all_connect - 关闭所有可能的外部链接,比如Database,Memcache等连接
- Core::add_close_connect_class - 增加执行Core::close_all_connect()时会去关闭的类
- Core::assets_hash - 获取asset文件MD5号
- Core::ip - 返回客户端IP数组列表
继承自父类的方法和变量
- Bootstrap::$include_path - 包含目录
- Bootstrap::$base_url - 当前URL的根路径
- Bootstrap::$path_info - 当前URL的PATH_INFO
- Bootstrap::$project - 当前项目
- Bootstrap::$project_dir - 当前项目目录
- Bootstrap::$project_url - 当前项目的URL
- Bootstrap::$file_list - 系统文件列表
- Bootstrap::auto_load - 自动加载类
- Bootstrap::include_path - 获取包含目录,返回一个一维的数组
- Bootstrap::find_file - 查找文件
- Bootstrap::get_debug_hash - 根据用户名和密码获取一个hash
- Bootstrap::protocol - 返回协议类型
系统启动
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$auto_execute |
boolean |
是否直接运行 | bool true |
获取指定key的配置
若不传key,则返回Core_Config对象,可获取动态配置,例如Core::config()->get();
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$key |
string |
$key | null |
$default |
mixed |
默认值 | null |
Config
array
Cookie
Core_Cookie
路由处理
Core_Route
返回URL路径
自3.0起可用 url() 直接快速调用此方法
Core::url('test/');
url('test/');
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$uri |
string |
$url URL | empty |
$isfullurl_or_project |
true|string |
若传true,则返回当前项目的完整url(http(s)://开头),若传项目名,比如default,则返回指定项目的完整URL | bool false |
string
返回静态资源URL路径
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$uri |
string |
$uri | empty |
Include一个指定URI的控制器
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$uri |
string |
$uri |
class_name
| false是否系统设置禁用文件写入功能
可在 config.php
中设置 $config['file_write_mode'] = 'disable';
如果disable则返回true,否则返回false
boolean
记录日志
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$msg |
string |
日志内容 | |
$type |
string |
类型,例如:log,error,debug 等 | string(3) "log" |
$file |
stirng |
指定文件名,不指定则默认 | null |
boolean
执行指定URI的控制器
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$uri |
string |
$uri |
寻找控制器
array
写入日志
若有特殊写入需求,可以扩展本方法(比如调用数据库类克写到数据库里)
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$data |
string |
$data | |
$type |
string |
日志类型 | string(3) "log" |
$file |
stirng |
指定文件名,不指定则默认 | null |
boolean
用于保存日志时格式化内容,如需要特殊格式可以自行扩展
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$msg |
string |
$msg | |
$type |
string |
$format | |
$format |
unknown |
string
获取debug对象 可安全用于生产环境,在生产环境下将忽略所有debug信息
Debug
将真实路径地址输出为调试地址
显示结果类似 ./system/libraries/Database.class.php
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$file |
string |
Path to debug | |
$highlight |
boolean |
是否返回高亮前缀,可以传字符颜色,比如#f00 | bool false |
string
关闭缓冲区
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$flush |
boolean |
是否输出缓冲数据 | bool true |
void
404,可直接将Exception对象传给$msg
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$msg |
string/Exception |
$msg | null |
系统错误,可直接将Exception对象传给$msg
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$msg |
string/Exception |
$msg | null |
返回一个用.表示的字符串的key对应数组的内容
例如
$arr = array
(
'a' => array
(
'b' => 123,
'c' => array
(
456,
),
),
);
Core::key_string($arr,'a.b'); //返回123
Core::key_string($arr,'a');
// 返回
array
(
'b' => 123,
'c' => array
(
456,
),
);
Core::key_string($arr,'a.c.0'); //返回456
Core::key_string($arr,'a.d'); //返回null
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$arr |
array |
$arr | |
$key |
string |
$key | |
$default |
unknown |
null |
fixed
添加页面在关闭前执行的列队 将利用call_user_func或call_user_func_array回调 类似 register_shutdown_function
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$function |
array |
方法名,可以是数组 | |
$param_arr |
array |
参数,可空 | null |
根据$objName返回一个实例化并静态存储的对象
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$obj_name |
string |
$obj_name | |
$key |
string |
$key | empty |
释放对象以释放内存
通常在批处理后操作,可有效的释放getFactory静态缓存的对象
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$obj_name |
string |
对象名称 不传的话则清除全部 | null |
$key |
string |
对象关键字 不传的话则清除$objName里的所有对象 | null |
将项目切换回初始项目
当使用Core::change_project()设置切换过项目后,可使用此方法返回初始化时的项目
切换到另外一个项目
切换其它项目后,相关的config,include_path等都将加载为设定项目的,但是已经加载的class等是不可能销毁的,所以需谨慎使用
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$project |
string |
$project |
boolean
增加change_project回调事件
//将在每次执行 Core::change_project($new_project) 成功后执行 MyClass::myfun($old_project, $new_project) 方法,其中$old_project是原来的项目名
Core::change_project_add_callback('MyClass::myfun');
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$fun |
string|array |
$fun |
移除import_library回调事件
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$fun |
string|array |
$fun |
导入指定类库
支持多个,当一次导入多个时,从数组最后一个开始导入
导入的格式必须是类似 com.a.b 的形式,否则会抛出异常,例如: com.myqee.test
Bootstrap::import_library('com.myqee.test');
Bootstrap::import_library(array('com.myqee.test','com.myqee.cms'));
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$library_name |
string|array |
指定类库 支持多个 |
boolean
增加import_library回调事件
//将在每次执行 Core::import_library($library_name) 成功后执行 MyClass::myfun((array)$library_name) 方法
Core::add_import_library_callback('MyClass::myfun');
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$fun |
string|array |
$fun |
移除import_library回调事件
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$fun |
string|array |
$fun |
执行注册的关闭方法
特殊的合并项目配置
相当于一维数组之间相加,这里支持多维
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$c1 |
array |
$c1 | |
$c2 |
array |
$c2 |
array
关闭所有可能的外部链接,比如Database,Memcache等连接
增加执行Core::close_all_connect()时会去关闭的类
Core::add_close_connect_class('Database','close_all_connect');
Core::add_close_connect_class('Cache_Driver_Memcache');
Core::add_close_connect_class('TestClass','close');
//当执行 Core::close_all_connect() 时会调用 Database::close_all_connect() 和 Cache_Driver_Memcache::close_all_connect() 和 TestClass::close() 方法
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$class_name |
string |
$class_name | |
$fun |
string |
$fun | string(17) "close_all_connect" |
检查内部调用HASH是否有效
boolean
获取asset文件MD5号
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$file |
string |
$file |
md5
返回客户端IP数组列表
也可直接用 HttpIO::IP
来获取到当前单个IP
array
系统调用内容输出函数(请勿自行执行)
自动加载类
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$class_name |
string |
$class_name |
boolean
获取包含目录,返回一个一维的数组
Bootstrap::$include_path
为一个二维数组array
查找文件
// 查找类文件路径
$file = Bootstrap::find_file('classes', 'Database');
// 查找一个视图文件
$file = Bootstrap::find_file('views', 'test');
// 查找一个自定义文件,注意第3个参数设置空表示后缀在文件名中
$file = Bootstrap::find_file('assets', 'test.css', '');
// 等价于
$file = Bootstrap::find_file('assets', 'test', '.css');
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$dir |
string |
目录 | |
$file |
string |
文件 | |
$ext |
string |
后缀 例如:.html,不指定(null)的话则自动设置后缀 | null |
$auto_require |
boolean |
是否自动加载上来,对config,i18n无效 | bool false |
string
加入include_path类库
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$lib |
string |
$lib |
array
`array($ns, $dir, $is_already_loaded)`根据用户名和密码获取一个hash
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$username |
string |
$username | |
$password |
string |
$password |
string