Zhamao Framework 3.2.4
A high-performance chatbot + web framework
载入中...
搜索中...
未找到
global_functions.php 文件参考

函数

if(function_exists( 'zm_internal_errcode')) zm_dir (string $dir)
 
 zm_exec (string $cmd)
 
 zm_sleep (float|int $time)
 
 zm_timer_tick (int $ms, callable $callback, int $times=0)
 
 zm_timer_after (int $ms, callable $callback)
 
 coroutine ()
 
 zm_internal_errcode (int|string $code)
 
 zm_instance_id ()
 
 logger ()
 
 is_assoc_array (array $array)
 
 match_pattern (string $pattern, string $subject)
 
 match_args (string $pattern, string $subject)
 
 segment (string $type, array $data=[])
 
 middleware ()
 
 container ()
 
 resolve (string $abstract, array $parameters=[])
 
 db (string $name='')
 
 sql_builder (string $name='')
 
 zm_sqlite (string $name, bool $create_new=true, bool $keep_alive=true)
 
 zm_sqlite_builder (string $name, bool $create_new=true, bool $keep_alive=true)
 
 redis (string $name='default')
 
 config (array|string $key=null, mixed $default=null)
 
 bot (string $bot_id='', string $platform='')
 
 bot_connect (int $flag, int $fd)
 
 kv (string $name='')
 
 env (string $key, mixed $default=null)
 
 zm_http_response (int $status_code=200, ?string $reason=null, array $headers=[], mixed $body=null, string $protocol='1.1')
 
 ws_socket (int $flag=1)
 
 zm_create_app ()
 
 zm_create_plugin ()
 
 zm_websocket_client (string $address, array $header=[], mixed $set=null)
 

函数说明

◆ bot()

bot ( string  $bot_id = '',
string  $platform = '' 
)

◆ bot_connect()

bot_connect ( int  $flag,
int  $fd 
)

◆ config()

config ( array|string  $key = null,
mixed  $default = null 
)

获取 / 设置配置项

传入键名和(或)默认值,获取配置项 传入数组,设置配置项 不传参数,返回配置容器

参数
null | array | string$key键名
null | mixed$default默认值
返回
mixed|void|ZMConfig

◆ container()

container ( )

获取容器实例

◆ coroutine()

coroutine ( )

获取协程接口

◆ db()

db ( string  $name = '')

获取 MySQL 调用的类

异常
DBException

◆ env()

env ( string  $key,
mixed  $default = null 
)

获取环境变量

函数调用图:

◆ is_assoc_array()

is_assoc_array ( array  $array)

判断传入的数组是否为关联数组

◆ kv()

kv ( string  $name = '')

获取一个 KV 库实例

参数
string$nameKV 库名称
返回
CacheInterface
函数调用图:

◆ logger()

logger ( )

助手方法,返回一个 Logger 实例

◆ match_args()

match_args ( string  $pattern,
string  $subject 
)

匹配参数

返回
array|false 成功时返回匹配到的参数数组,失败时返回false
函数调用图:

◆ match_pattern()

match_pattern ( string  $pattern,
string  $subject 
)

格式匹配

◆ middleware()

middleware ( )

中间件操作类的助手函数

◆ redis()

redis ( string  $name = 'default')

获取 Redis 操作类

参数
string$name使用的 Redis 连接名称

◆ resolve()

resolve ( string  $abstract,
array  $parameters = [] 
)

解析类实例(使用容器)

这是 {

参见
container()}->make($abstract, $parameters) 的别名

@template T

参数
class-string<T>$abstract
返回
Closure|mixed|T
函数调用图:

◆ segment()

segment ( string  $type,
array  $data = [] 
)

构建消息段的助手函数

参数
string$type类型
array$data字段

◆ sql_builder()

sql_builder ( string  $name = '')

获取构建 MySQL 的类

异常
DBException

◆ ws_socket()

ws_socket ( int  $flag = 1)

【助手函数】获取驱动的 WebSocket 服务器对应 Socket 操作对象

参数
int$flag对应的 Server 端口标记
异常
Exception

◆ zm_create_app()

zm_create_app ( )

创建炸毛框架应用

◆ zm_create_plugin()

zm_create_plugin ( )

创建炸毛框架的插件对象

◆ zm_dir()

if(function_exists('zm_internal_errcode')) zm_dir ( string  $dir)

根据具体操作系统替换目录分隔符

参数
string$dir目录

◆ zm_exec()

zm_exec ( string  $cmd)

执行shell指令

参数
string$cmd命令行

◆ zm_http_response()

zm_http_response ( int  $status_code = 200,
?string  $reason = null,
array  $headers = [],
mixed  $body = null,
string  $protocol = '1.1' 
)

【助手函数】HttpFactory 快速创建一个 Response

参数
int$status_code状态码
null | string$reason原因(留空则使用状态码本身的)
array$headers请求头
mixed$bodyHTTP Body
string$protocolHTTP 协议版本

◆ zm_instance_id()

zm_instance_id ( )

返回当前炸毛实例的 ID

◆ zm_internal_errcode()

zm_internal_errcode ( int|string  $code)

获取内部错误码

◆ zm_sleep()

zm_sleep ( float|int  $time)

sleep 指定时间,单位为秒(最小单位为1毫秒,即0.001)

◆ zm_sqlite()

zm_sqlite ( string  $name,
bool  $create_new = true,
bool  $keep_alive = true 
)

获取一个便携 SQLite 操作类

参数
string$name使用的 SQLite 连接文件名
bool$create_new是否在文件不存在时创建新的
bool$keep_alive是否维持 PDO 对象以便优化性能
异常
DBException

◆ zm_sqlite_builder()

zm_sqlite_builder ( string  $name,
bool  $create_new = true,
bool  $keep_alive = true 
)

获取便携 SQLite 操作类的 SQL 语句构造器

参数
string$name使用的 SQLite 连接文件名
bool$create_new是否在文件不存在时创建新的
bool$keep_alive是否维持 PDO 对象以便优化性能
异常
DBException
函数调用图:

◆ zm_timer_after()

zm_timer_after ( int  $ms,
callable  $callback 
)

创建一个延后一次性计时器,只在指定毫秒后执行一次即销毁(Timer::after() 的别名)

参数
int$ms时间(毫秒)
callable$callback回调函数

◆ zm_timer_tick()

zm_timer_tick ( int  $ms,
callable  $callback,
int  $times = 0 
)

创建一个计时器(Timer::tick() 的别名)

参数
int$ms时间(毫秒)
callable$callback回调函数
int$times重复次数(如果为 0 或 -1,则永久循环,其他大于 0 的数为限定次数)

◆ zm_websocket_client()

zm_websocket_client ( string  $address,
array  $header = [],
mixed  $set = null 
)

创建一个 WebSocket 客户端

参数
string$address接入地址,例如 ws://192.168.1.3:9998/
array$header请求头
null | mixed$setSwoole 驱动下传入的额外参数
异常
DriverException
ClientException