选择语言 :

Core_Core
    └ Bootstrap

MyQEE 核心类

常量
Core::VERSION string(3) "3.1"
Core::RELEASE string(3) "rc1"
Core::CODER string(38) "呼吸二氧化碳 <jonwang@myqee.com>"

API - Core_Core

继承自父类的方法和变量
author
呼吸二氧化碳 jonwang@myqee.com
category
MyQEE
package
System
subpackage
Core
copyright
Copyright © 2008-2013 myqee.com
license
http://www.myqee.com/license.html

Core::setup( $auto_execute = true)

系统启动

参数列表

参数 类型 描述 默认值
$auto_execute boolean 是否直接运行 bool true

Core::run( )


Core::config( $key = null, $default = null)

获取指定key的配置

若不传key,则返回Core_Config对象,可获取动态配置,例如Core::config()->get();

参数列表

参数 类型 描述 默认值
$key string $key null
$default mixed 默认值 null
返回值
  • Config
  • array

Core::cookie( )

Cookie

返回值
  • Core_Cookie

Core::route( )

路由处理

返回值
  • Core_Route

Core::url( $uri = '', $isfullurl_or_project = false)

返回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

Core::url_assets( $uri = '')

返回静态资源URL路径

参数列表

参数 类型 描述 默认值
$uri string $uri empty

Core::load_controller( $uri )

Include一个指定URI的控制器

参数列表

参数 类型 描述 默认值
$uri string $uri
返回值
  • class_name | false

Core::is_file_write_disabled( )

是否系统设置禁用文件写入功能

可在 config.php 中设置 $config['file_write_mode'] = 'disable'; 如果disable则返回true,否则返回false

返回值
  • boolean

Core::log( $msg , $type = 'log', $file = null)

记录日志

参数列表

参数 类型 描述 默认值
$msg string 日志内容
$type string 类型,例如:log,error,debug 等 string(3) "log"
$file stirng 指定文件名,不指定则默认 null
返回值
  • boolean

Core::execute( $uri )

执行指定URI的控制器

参数列表

参数 类型 描述 默认值
$uri string $uri

Core::rm_controoler( )


Core::find_controller( )

寻找控制器

返回值
  • array

Core::write_log( $data , $type = 'log', $file = null)

写入日志

若有特殊写入需求,可以扩展本方法(比如调用数据库类克写到数据库里)

参数列表

参数 类型 描述 默认值
$data string $data
$type string 日志类型 string(3) "log"
$file stirng 指定文件名,不指定则默认 null
返回值
  • boolean

Core::log_format( $msg , $type , $format )

用于保存日志时格式化内容,如需要特殊格式可以自行扩展

参数列表

参数 类型 描述 默认值
$msg string $msg
$type string $format
$format unknown
返回值
  • string

Core::debug( )

获取debug对象 可安全用于生产环境,在生产环境下将忽略所有debug信息

返回值
  • Debug

Core::debug_path( $file , $highlight = false)

将真实路径地址输出为调试地址

显示结果类似 ./system/libraries/Database.class.php

参数列表

参数 类型 描述 默认值
$file string Path to debug
$highlight boolean 是否返回高亮前缀,可以传字符颜色,比如#f00 bool false
返回值
  • string

Core::close_buffers( $flush = true)

关闭缓冲区

参数列表

参数 类型 描述 默认值
$flush boolean 是否输出缓冲数据 bool true
返回值
  • void

Core::show_404( $msg = null)

404,可直接将Exception对象传给$msg

参数列表

参数 类型 描述 默认值
$msg string/Exception $msg null

Core::show_500( $msg = null)

系统错误,可直接将Exception对象传给$msg

参数列表

参数 类型 描述 默认值
$msg string/Exception $msg null

Core::key_string( $arr , $key , $default = 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

Core::register_shutdown_function( $function , $param_arr = null)

添加页面在关闭前执行的列队 将利用call_user_func或call_user_func_array回调 类似 register_shutdown_function

参数列表

参数 类型 描述 默认值
$function array 方法名,可以是数组
$param_arr array 参数,可空 null

Core::shutdown_handler( )


Core::exception_handler( )


Core::error_handler( )


Core::factory( $obj_name , $key = '')

根据$objName返回一个实例化并静态存储的对象

参数列表

参数 类型 描述 默认值
$obj_name string $obj_name
$key string $key empty

Core::factory_release( $obj_name = null, $key = null)

释放对象以释放内存

通常在批处理后操作,可有效的释放getFactory静态缓存的对象

参数列表

参数 类型 描述 默认值
$obj_name string 对象名称 不传的话则清除全部 null
$key string 对象关键字 不传的话则清除$objName里的所有对象 null

Core::reset_project( )

将项目切换回初始项目

当使用Core::change_project()设置切换过项目后,可使用此方法返回初始化时的项目


Core::change_project( $project )

切换到另外一个项目

切换其它项目后,相关的config,include_path等都将加载为设定项目的,但是已经加载的class等是不可能销毁的,所以需谨慎使用

参数列表

参数 类型 描述 默认值
$project string $project
返回值
  • boolean

Core::change_project_add_callback( $fun )

增加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

Core::change_project_remove_callback( $fun )

移除import_library回调事件

参数列表

参数 类型 描述 默认值
$fun string|array $fun

Core::import_library( $library_name )

导入指定类库

支持多个,当一次导入多个时,从数组最后一个开始导入

导入的格式必须是类似 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

Core::import_library_add_callback( $fun )

增加import_library回调事件

//将在每次执行 Core::import_library($library_name) 成功后执行 MyClass::myfun((array)$library_name) 方法
Core::add_import_library_callback('MyClass::myfun');

参数列表

参数 类型 描述 默认值
$fun string|array $fun

Core::import_library_remove_callback( $fun )

移除import_library回调事件

参数列表

参数 类型 描述 默认值
$fun string|array $fun

Core::run_shutdown_function( )

执行注册的关闭方法


Core::_merge_project_config( $c1 , $c2 )

特殊的合并项目配置

相当于一维数组之间相加,这里支持多维

参数列表

参数 类型 描述 默认值
$c1 array $c1
$c2 array $c2
返回值
  • array

Core::close_all_connect( )

关闭所有可能的外部链接,比如Database,Memcache等连接


Core::add_close_connect_class( $class_name , $fun = 'close_all_connect')

增加执行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"

Core::check_system_request_allow( )

检查内部调用HASH是否有效

返回值
  • boolean

Core::assets_hash( $file )

获取asset文件MD5号

参数列表

参数 类型 描述 默认值
$file string $file
返回值
  • md5

Core::ip( )

返回客户端IP数组列表

也可直接用 HttpIO::IP 来获取到当前单个IP

返回值
  • array

Core::_output_body( )

系统调用内容输出函数(请勿自行执行)


Bootstrap::auto_load( $class_name )

自动加载类

参数列表

参数 类型 描述 默认值
$class_name string $class_name
返回值
  • boolean

Bootstrap::include_path( )

获取包含目录,返回一个一维的数组

注意 Bootstrap::$include_path 为一个二维数组
返回值
  • array

Bootstrap::find_file( $dir , $file , $ext = null, $auto_require = false)

查找文件

 // 查找类文件路径
 $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

Bootstrap::_add_include_path_lib( $lib )

加入include_path类库

参数列表

参数 类型 描述 默认值
$lib string $lib
返回值
  • array `array($ns, $dir, $is_already_loaded)`

Bootstrap::get_debug_hash( $username , $password )

根据用户名和密码获取一个hash

参数列表

参数 类型 描述 默认值
$username string $username
$password string $password
返回值
  • string

Bootstrap::protocol( )

返回协议类型

当在命令行里执行,则返回null

返回值
  • string `null` | `http://` | `https://`