This commit is contained in:
gr
2026-11-11 14:22:02 +08:00
parent 245618dcdc
commit a62311a8da
64878 changed files with 3747172 additions and 66 deletions
+13
View File
@@ -0,0 +1,13 @@
APP_DEBUG=false
IAM_DATA_MODE=shared
IAM_SOURCE_API_URL=http://127.0.0.1:8082/adminapi
# Optional original login/binding page; this is a browser URL, never an API secret.
IAM_SOURCE_LOGIN_URL=
IAM_RUNTIME_PATH=runtime
IAM_SESSION_TTL=28800
IAM_CORS_ORIGINS=http://localhost:5173,http://127.0.0.1:5173
IAM_GROUP_ENABLED=1
IAM_GROUP_OWNER_IDS=1
IAM_GROUP_NAME=甄养堂集团
IAM_GROUP_DB_PATH=runtime/group.sqlite
IAM_HOSPITAL_BASE_URL=http://127.0.0.1:8090/admin
Binary file not shown.
@@ -0,0 +1 @@
93b743f5302ef739609b6a416fe4d0b93715ed28ccf3c782495eecf63ad9dba5
@@ -0,0 +1,611 @@
[2026-10-30T03:44:04+00:00][error] [0]请先登录
[2026-10-30T03:44:04+00:00][error] [0]请先登录
[2026-10-30T03:44:05+00:00][error] [0]账号已存在
[2026-10-30T03:44:05+00:00][error] [0]记录不存在
[2026-10-30T03:44:05+00:00][error] [0]上级节点不能是自己或后代
[2026-10-30T03:44:05+00:00][error] [0]上级节点不能是自己或后代
[2026-10-30T03:44:05+00:00][error] [0]上级节点不能是自己或后代
[2026-10-30T03:44:05+00:00][error] [0]上级节点不能是自己或后代
[2026-10-30T03:44:05+00:00][error] [0]存在子节点,不能删除
[2026-10-30T03:44:05+00:00][error] [0]部门仍关联用户,不能删除
[2026-10-30T03:44:05+00:00][error] [0]角色仍关联用户,不能删除
[2026-10-30T03:44:05+00:00][error] [0]存在子节点,不能删除
[2026-10-30T03:44:06+00:00][error] [0]权限不足
[2026-10-30T03:44:06+00:00][error] [0]权限不足
[2026-10-30T03:44:06+00:00][error] [0]权限不足
[2026-10-30T03:44:06+00:00][error] [0]权限不足
[2026-10-30T03:44:06+00:00][error] [0]权限不足
[2026-10-30T03:44:06+00:00][error] [0]权限不足
[2026-10-30T03:44:06+00:00][error] [0]权限不足
[2026-10-30T03:44:06+00:00][error] [0]权限不足
[2026-10-30T03:44:06+00:00][error] [0]权限不足
[2026-10-30T03:44:06+00:00][error] [0]权限不足
[2026-10-30T03:44:06+00:00][error] [0]权限不足
[2026-10-30T03:44:06+00:00][error] [0]权限不足
[2026-10-30T03:44:06+00:00][error] [0]权限不足
[2026-10-30T03:44:06+00:00][error] [0]权限不足
[2026-10-30T03:44:06+00:00][error] [0]不能新增关联已停用的角色或部门
[2026-10-30T03:44:07+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T03:44:07+00:00][error] [0]账号或密码错误,或账号已停用
[2026-10-30T03:44:08+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T03:44:09+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T03:44:09+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T03:44:09+00:00][error] [0]账号或密码错误,或账号已停用
[2026-10-30T03:44:09+00:00][error] [0]请求包含不支持的字段
[2026-10-30T03:44:10+00:00][error] [0]不能停用自己或根账号
[2026-10-30T03:48:48+00:00][error] [0]请先登录
[2026-10-30T03:48:48+00:00][error] [0]请先登录
[2026-10-30T03:48:48+00:00][error] [0]请先登录
[2026-10-30T03:48:48+00:00][error] [0]请先登录
[2026-10-30T03:48:49+00:00][error] [0]账号已存在
[2026-10-30T03:48:49+00:00][error] [0]角色不存在
[2026-10-30T03:48:49+00:00][error] [0]账号已存在
[2026-10-30T03:48:49+00:00][error] [0]角色不存在
[2026-10-30T03:48:49+00:00][error] [0]部门不存在
[2026-10-30T03:48:49+00:00][error] [0]部门不存在
[2026-10-30T03:48:49+00:00][error] [0]菜单不存在
[2026-10-30T03:48:49+00:00][error] [0]菜单不存在
[2026-10-30T03:48:50+00:00][error] [0]页面路径须为有效绝对路径
[2026-10-30T03:48:50+00:00][error] [0]页面路径须为有效绝对路径
[2026-10-30T03:48:50+00:00][error] [0]页面路径须为有效绝对路径
[2026-10-30T03:48:50+00:00][error] [0]页面路径须为有效绝对路径
[2026-10-30T03:48:50+00:00][error] [0]页面路径须为有效绝对路径
[2026-10-30T03:48:50+00:00][error] [0]页面路径须为有效绝对路径
[2026-10-30T03:48:50+00:00][error] [0]页面路径须为有效绝对路径
[2026-10-30T03:48:50+00:00][error] [0]首页路径仅允许使用首页组件
[2026-10-30T03:48:50+00:00][error] [0]上级节点不能是自己或后代
[2026-10-30T03:48:50+00:00][error] [0]上级节点不能是自己或后代
[2026-10-30T03:48:50+00:00][error] [0]上级节点不能是自己或后代
[2026-10-30T03:48:50+00:00][error] [0]上级节点不能是自己或后代
[2026-10-30T03:48:50+00:00][error] [0]存在子节点,不能删除
[2026-10-30T03:48:50+00:00][error] [0]部门仍关联用户,不能删除
[2026-10-30T03:48:50+00:00][error] [0]页面路径须为有效绝对路径
[2026-10-30T03:48:50+00:00][error] [0]角色仍关联用户,不能删除
[2026-10-30T03:48:50+00:00][error] [0]存在子节点,不能删除
[2026-10-30T03:48:50+00:00][error] [0]页面路径须为有效绝对路径
[2026-10-30T03:48:50+00:00][error] [0]页面路径须为有效绝对路径
[2026-10-30T03:48:50+00:00][error] [0]页面路径须为有效绝对路径
[2026-10-30T03:48:50+00:00][error] [0]页面路径须为有效绝对路径
[2026-10-30T03:48:50+00:00][error] [0]权限不足
[2026-10-30T03:48:50+00:00][error] [0]权限不足
[2026-10-30T03:48:50+00:00][error] [0]首页路径仅允许使用首页组件
[2026-10-30T03:48:51+00:00][error] [0]上级节点不能是自己或后代
[2026-10-30T03:48:51+00:00][error] [0]上级节点不能是自己或后代
[2026-10-30T03:48:51+00:00][error] [0]上级节点不能是自己或后代
[2026-10-30T03:48:51+00:00][error] [0]上级节点不能是自己或后代
[2026-10-30T03:48:51+00:00][error] [0]存在子节点,不能删除
[2026-10-30T03:48:51+00:00][error] [0]部门仍关联用户,不能删除
[2026-10-30T03:48:51+00:00][error] [0]权限不足
[2026-10-30T03:48:51+00:00][error] [0]角色仍关联用户,不能删除
[2026-10-30T03:48:51+00:00][error] [0]存在子节点,不能删除
[2026-10-30T03:48:51+00:00][error] [0]权限不足
[2026-10-30T03:48:51+00:00][error] [0]权限不足
[2026-10-30T03:48:51+00:00][error] [0]权限不足
[2026-10-30T03:48:51+00:00][error] [0]权限不足
[2026-10-30T03:48:51+00:00][error] [0]权限不足
[2026-10-30T03:48:51+00:00][error] [0]权限不足
[2026-10-30T03:48:51+00:00][error] [0]权限不足
[2026-10-30T03:48:51+00:00][error] [0]权限不足
[2026-10-30T03:48:51+00:00][error] [0]权限不足
[2026-10-30T03:48:51+00:00][error] [0]权限不足
[2026-10-30T03:48:51+00:00][error] [0]权限不足
[2026-10-30T03:48:52+00:00][error] [0]权限不足
[2026-10-30T03:48:52+00:00][error] [0]权限不足
[2026-10-30T03:48:52+00:00][error] [0]不能新增关联已停用的角色或部门
[2026-10-30T03:48:52+00:00][error] [0]权限不足
[2026-10-30T03:48:52+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T03:48:52+00:00][error] [0]权限不足
[2026-10-30T03:48:52+00:00][error] [0]账号或密码错误,或账号已停用
[2026-10-30T03:48:53+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T03:48:54+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T03:48:54+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T03:48:54+00:00][error] [0]账号或密码错误,或账号已停用
[2026-10-30T03:48:54+00:00][error] [0]请求包含不支持的字段
[2026-10-30T03:48:55+00:00][error] [0]权限不足
[2026-10-30T03:48:55+00:00][error] [0]不能停用自己或根账号
[2026-10-30T03:48:56+00:00][error] [0]权限不足
[2026-10-30T03:48:56+00:00][error] [0]权限不足
[2026-10-30T03:48:56+00:00][error] [0]权限不足
[2026-10-30T03:48:56+00:00][error] [0]权限不足
[2026-10-30T03:48:56+00:00][error] [0]权限不足
[2026-10-30T03:48:56+00:00][error] [0]权限不足
[2026-10-30T03:48:56+00:00][error] [0]权限不足
[2026-10-30T03:48:56+00:00][error] [0]权限不足
[2026-10-30T03:48:56+00:00][error] [0]权限不足
[2026-10-30T03:48:56+00:00][error] [0]权限不足
[2026-10-30T03:48:57+00:00][error] [0]权限不足
[2026-10-30T03:48:57+00:00][error] [0]权限不足
[2026-10-30T03:48:57+00:00][error] [0]权限不足
[2026-10-30T03:48:58+00:00][error] [0]不能新增关联已停用的角色或部门
[2026-10-30T03:48:58+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T03:48:58+00:00][error] [0]账号或密码错误,或账号已停用
[2026-10-30T03:48:59+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T03:49:00+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T03:49:00+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T03:49:01+00:00][error] [0]账号或密码错误,或账号已停用
[2026-10-30T03:49:01+00:00][error] [0]请求包含不支持的字段
[2026-10-30T03:49:02+00:00][error] [0]不能停用自己或根账号
[2026-10-30T03:53:12+00:00][error] [0]请先登录
[2026-10-30T03:53:12+00:00][error] [0]请先登录
[2026-10-30T03:53:13+00:00][error] [0]账号已存在
[2026-10-30T03:53:13+00:00][error] [0]角色不存在
[2026-10-30T03:53:13+00:00][error] [0]部门不存在
[2026-10-30T03:53:13+00:00][error] [0]菜单不存在
[2026-10-30T03:53:13+00:00][error] [0]页面路径须为有效绝对路径
[2026-10-30T03:53:13+00:00][error] [0]页面路径须为有效绝对路径
[2026-10-30T03:53:13+00:00][error] [0]页面路径须为有效绝对路径
[2026-10-30T03:53:13+00:00][error] [0]页面路径须为有效绝对路径
[2026-10-30T03:53:13+00:00][error] [0]页面路径须为有效绝对路径
[2026-10-30T03:53:14+00:00][error] [0]页面路径须为有效绝对路径
[2026-10-30T03:53:14+00:00][error] [0]首页路径仅允许使用首页组件
[2026-10-30T03:53:14+00:00][error] [0]上级节点不能是自己或后代
[2026-10-30T03:53:14+00:00][error] [0]上级节点不能是自己或后代
[2026-10-30T03:53:14+00:00][error] [0]上级节点不能是自己或后代
[2026-10-30T03:53:14+00:00][error] [0]上级节点不能是自己或后代
[2026-10-30T03:53:14+00:00][error] [0]存在子节点,不能删除
[2026-10-30T03:53:14+00:00][error] [0]部门仍关联用户,不能删除
[2026-10-30T03:53:14+00:00][error] [0]角色仍关联用户,不能删除
[2026-10-30T03:53:14+00:00][error] [0]存在子节点,不能删除
[2026-10-30T03:53:14+00:00][error] [0]权限不足
[2026-10-30T03:53:14+00:00][error] [0]权限不足
[2026-10-30T03:53:15+00:00][error] [0]权限不足
[2026-10-30T03:53:15+00:00][error] [0]权限不足
[2026-10-30T03:53:15+00:00][error] [0]权限不足
[2026-10-30T03:53:16+00:00][error] [0]权限不足
[2026-10-30T03:53:16+00:00][error] [0]权限不足
[2026-10-30T03:53:16+00:00][error] [0]权限不足
[2026-10-30T03:53:16+00:00][error] [0]权限不足
[2026-10-30T03:53:16+00:00][error] [0]权限不足
[2026-10-30T03:53:16+00:00][error] [0]权限不足
[2026-10-30T03:53:16+00:00][error] [0]权限不足
[2026-10-30T03:53:16+00:00][error] [0]权限不足
[2026-10-30T03:53:16+00:00][error] [0]权限不足
[2026-10-30T03:53:16+00:00][error] [0]权限不足
[2026-10-30T03:53:16+00:00][error] [0]权限不足
[2026-10-30T03:53:16+00:00][error] [0]不能新增关联已停用的角色或部门
[2026-10-30T03:53:16+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T03:53:17+00:00][error] [0]账号或密码错误,或账号已停用
[2026-10-30T03:53:17+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T03:53:18+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T03:53:18+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T03:53:18+00:00][error] [0]账号或密码错误,或账号已停用
[2026-10-30T03:53:18+00:00][error] [0]请求包含不支持的字段
[2026-10-30T03:53:19+00:00][error] [0]不能停用自己或根账号
[2026-10-30T04:12:53+00:00][error] [0]请先登录
[2026-10-30T04:12:53+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T04:12:54+00:00][error] [0]请先登录
[2026-10-30T04:12:54+00:00][error] [0]账号或密码错误,或账号已停用
[2026-10-30T04:12:54+00:00][error] [0]账号或密码错误,或账号已停用
[2026-10-30T04:12:54+00:00][error] [0]权限不足
[2026-10-30T04:12:54+00:00][error] [0]权限不足
[2026-10-30T04:12:54+00:00][error] [0]权限不足
[2026-10-30T04:12:55+00:00][error] [0]权限不足
[2026-10-30T04:12:55+00:00][error] [0]权限不足
[2026-10-30T04:12:55+00:00][error] [0]权限不足
[2026-10-30T04:12:55+00:00][error] [0]权限不足
[2026-10-30T04:12:55+00:00][error] [0]权限不足
[2026-10-30T04:12:55+00:00][error] [0]权限不足
[2026-10-30T04:12:55+00:00][error] [0]权限不足
[2026-10-30T04:12:55+00:00][error] [0]权限不足
[2026-10-30T04:12:55+00:00][error] [0]权限不足
[2026-10-30T04:12:55+00:00][error] [0]权限不足
[2026-10-30T04:12:55+00:00][error] [0]权限不足
[2026-10-30T04:12:56+00:00][error] [0]原系统不支持停用角色
[2026-10-30T04:12:56+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T04:12:56+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T04:12:56+00:00][error] [0]请先修改首次登录密码
[2026-10-30T04:12:56+00:00][error] [0]请先修改首次登录密码
[2026-10-30T04:12:56+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T04:12:56+00:00][error] [0]请先到原后台完成企业微信绑定
[2026-10-30T04:12:57+00:00][error] [0]请先到原后台完成企业微信绑定
[2026-10-30T04:12:57+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T04:12:57+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T04:12:57+00:00][error] [0]原密码错误
[2026-10-30T04:12:57+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T04:12:57+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T04:12:57+00:00][error] [0]账号或密码错误,或账号已停用
[2026-10-30T04:12:57+00:00][error] [0]合成源拒绝
[2026-10-30T04:12:57+00:00][error] [0]请先到原后台完成企业微信绑定
[2026-10-30T04:12:57+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T04:12:57+00:00][error] [0]请先到原后台完成企业微信绑定
[2026-10-30T04:12:58+00:00][error] [0]共享数据源响应异常
[2026-10-30T04:12:58+00:00][error] [0]共享数据源响应异常
[2026-10-30T04:12:58+00:00][error] [0]共享数据源暂时不可用
[2026-10-30T04:12:58+00:00][error] [0]无法连接共享数据源,请稍后重试
[2026-10-30T04:14:41+00:00][error] [0]请先登录
[2026-10-30T04:14:41+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T04:14:41+00:00][error] [0]请先登录
[2026-10-30T04:14:41+00:00][error] [0]账号或密码错误,或账号已停用
[2026-10-30T04:14:41+00:00][error] [0]账号或密码错误,或账号已停用
[2026-10-30T04:14:42+00:00][error] [0]权限不足
[2026-10-30T04:14:42+00:00][error] [0]权限不足
[2026-10-30T04:14:42+00:00][error] [0]权限不足
[2026-10-30T04:14:42+00:00][error] [0]权限不足
[2026-10-30T04:14:42+00:00][error] [0]权限不足
[2026-10-30T04:14:42+00:00][error] [0]权限不足
[2026-10-30T04:14:42+00:00][error] [0]权限不足
[2026-10-30T04:14:42+00:00][error] [0]权限不足
[2026-10-30T04:14:42+00:00][error] [0]权限不足
[2026-10-30T04:14:42+00:00][error] [0]权限不足
[2026-10-30T04:14:42+00:00][error] [0]权限不足
[2026-10-30T04:14:42+00:00][error] [0]权限不足
[2026-10-30T04:14:42+00:00][error] [0]权限不足
[2026-10-30T04:14:43+00:00][error] [0]权限不足
[2026-10-30T04:14:43+00:00][error] [0]原系统不支持停用角色
[2026-10-30T04:14:43+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T04:14:43+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T04:14:43+00:00][error] [0]请先修改首次登录密码
[2026-10-30T04:14:43+00:00][error] [0]请先修改首次登录密码
[2026-10-30T04:14:44+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T04:14:45+00:00][error] [0]请先到原后台完成企业微信绑定
[2026-10-30T04:14:45+00:00][error] [0]请先到原后台完成企业微信绑定
[2026-10-30T04:14:45+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T04:14:45+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T04:14:46+00:00][error] [0]原密码错误
[2026-10-30T04:14:46+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T04:14:46+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T04:14:46+00:00][error] [0]账号或密码错误,或账号已停用
[2026-10-30T04:14:46+00:00][error] [0]合成源拒绝
[2026-10-30T04:14:46+00:00][error] [0]请先到原后台完成企业微信绑定
[2026-10-30T04:14:46+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T04:14:46+00:00][error] [0]请先到原后台完成企业微信绑定
[2026-10-30T04:14:46+00:00][error] [0]共享数据源响应异常
[2026-10-30T04:14:47+00:00][error] [0]共享数据源响应异常
[2026-10-30T04:14:47+00:00][error] [0]共享数据源暂时不可用
[2026-10-30T04:14:47+00:00][error] [0]无法连接共享数据源,请稍后重试
[2026-10-30T04:14:48+00:00][error] [0]请先登录
[2026-10-30T04:14:48+00:00][error] [0]请先登录
[2026-10-30T04:14:49+00:00][error] [0]账号已存在
[2026-10-30T04:14:49+00:00][error] [0]角色不存在
[2026-10-30T04:14:49+00:00][error] [0]部门不存在
[2026-10-30T04:14:49+00:00][error] [0]菜单不存在
[2026-10-30T04:14:49+00:00][error] [0]页面路径须为有效绝对路径
[2026-10-30T04:14:49+00:00][error] [0]页面路径须为有效绝对路径
[2026-10-30T04:14:49+00:00][error] [0]页面路径须为有效绝对路径
[2026-10-30T04:14:50+00:00][error] [0]页面路径须为有效绝对路径
[2026-10-30T04:14:50+00:00][error] [0]页面路径须为有效绝对路径
[2026-10-30T04:14:50+00:00][error] [0]页面路径须为有效绝对路径
[2026-10-30T04:14:50+00:00][error] [0]首页路径仅允许使用首页组件
[2026-10-30T04:14:50+00:00][error] [0]上级节点不能是自己或后代
[2026-10-30T04:14:50+00:00][error] [0]上级节点不能是自己或后代
[2026-10-30T04:14:50+00:00][error] [0]上级节点不能是自己或后代
[2026-10-30T04:14:50+00:00][error] [0]上级节点不能是自己或后代
[2026-10-30T04:14:50+00:00][error] [0]存在子节点,不能删除
[2026-10-30T04:14:50+00:00][error] [0]部门仍关联用户,不能删除
[2026-10-30T04:14:50+00:00][error] [0]角色仍关联用户,不能删除
[2026-10-30T04:14:50+00:00][error] [0]存在子节点,不能删除
[2026-10-30T04:14:50+00:00][error] [0]权限不足
[2026-10-30T04:14:50+00:00][error] [0]权限不足
[2026-10-30T04:14:51+00:00][error] [0]权限不足
[2026-10-30T04:14:51+00:00][error] [0]权限不足
[2026-10-30T04:14:51+00:00][error] [0]权限不足
[2026-10-30T04:14:51+00:00][error] [0]权限不足
[2026-10-30T04:14:51+00:00][error] [0]权限不足
[2026-10-30T04:14:51+00:00][error] [0]权限不足
[2026-10-30T04:14:51+00:00][error] [0]权限不足
[2026-10-30T04:14:51+00:00][error] [0]权限不足
[2026-10-30T04:14:52+00:00][error] [0]权限不足
[2026-10-30T04:14:52+00:00][error] [0]权限不足
[2026-10-30T04:14:52+00:00][error] [0]权限不足
[2026-10-30T04:14:52+00:00][error] [0]权限不足
[2026-10-30T04:14:52+00:00][error] [0]权限不足
[2026-10-30T04:14:52+00:00][error] [0]权限不足
[2026-10-30T04:14:52+00:00][error] [0]不能新增关联已停用的角色或部门
[2026-10-30T04:14:52+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T04:14:53+00:00][error] [0]账号或密码错误,或账号已停用
[2026-10-30T04:14:53+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T04:14:53+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T04:14:53+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T04:14:54+00:00][error] [0]账号或密码错误,或账号已停用
[2026-10-30T04:14:54+00:00][error] [0]请求包含不支持的字段
[2026-10-30T04:14:55+00:00][error] [0]不能停用自己或根账号
[2026-10-30T04:18:58+00:00][error] [0]请先登录
[2026-10-30T04:18:58+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T04:18:58+00:00][error] [0]请先登录
[2026-10-30T04:18:58+00:00][error] [0]账号或密码错误,或账号已停用
[2026-10-30T04:18:58+00:00][error] [0]账号或密码错误,或账号已停用
[2026-10-30T04:18:59+00:00][error] [0]权限不足
[2026-10-30T04:18:59+00:00][error] [0]权限不足
[2026-10-30T04:18:59+00:00][error] [0]权限不足
[2026-10-30T04:18:59+00:00][error] [0]权限不足
[2026-10-30T04:18:59+00:00][error] [0]权限不足
[2026-10-30T04:18:59+00:00][error] [0]权限不足
[2026-10-30T04:18:59+00:00][error] [0]权限不足
[2026-10-30T04:18:59+00:00][error] [0]权限不足
[2026-10-30T04:18:59+00:00][error] [0]权限不足
[2026-10-30T04:18:59+00:00][error] [0]权限不足
[2026-10-30T04:18:59+00:00][error] [0]权限不足
[2026-10-30T04:18:59+00:00][error] [0]权限不足
[2026-10-30T04:18:59+00:00][error] [0]权限不足
[2026-10-30T04:18:59+00:00][error] [0]权限不足
[2026-10-30T04:19:00+00:00][error] [0]原系统不支持停用角色
[2026-10-30T04:19:00+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T04:19:00+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T04:19:00+00:00][error] [0]请先修改首次登录密码
[2026-10-30T04:19:00+00:00][error] [0]请先修改首次登录密码
[2026-10-30T04:19:00+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T04:19:01+00:00][error] [0]请先到原后台完成企业微信绑定
[2026-10-30T04:19:01+00:00][error] [0]请先到原后台完成企业微信绑定
[2026-10-30T04:19:01+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T04:19:01+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T04:19:01+00:00][error] [0]原密码错误
[2026-10-30T04:19:01+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T04:19:01+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T04:19:01+00:00][error] [0]账号或密码错误,或账号已停用
[2026-10-30T04:19:02+00:00][error] [0]合成源拒绝
[2026-10-30T04:19:02+00:00][error] [0]请先到原后台完成企业微信绑定
[2026-10-30T04:19:02+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T04:19:02+00:00][error] [0]请先到原后台完成企业微信绑定
[2026-10-30T04:19:02+00:00][error] [0]共享数据源响应异常
[2026-10-30T04:19:02+00:00][error] [0]共享数据源响应异常
[2026-10-30T04:19:02+00:00][error] [0]共享数据源暂时不可用
[2026-10-30T04:19:02+00:00][error] [0]无法连接共享数据源,请稍后重试
[2026-10-30T04:19:59+00:00][error] [0]请先登录
[2026-10-30T05:35:36+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T05:35:46+00:00][error] [0]账号或密码错误,或账号已停用
[2026-10-30T05:57:16+00:00][error] [0]请先登录
[2026-10-30T05:57:16+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T05:57:16+00:00][error] [0]请先登录
[2026-10-30T05:57:16+00:00][error] [0]账号或密码错误,或账号已停用
[2026-10-30T05:57:16+00:00][error] [0]账号或密码错误,或账号已停用
[2026-10-30T05:57:17+00:00][error] [0]权限不足
[2026-10-30T05:57:17+00:00][error] [0]权限不足
[2026-10-30T05:57:17+00:00][error] [0]权限不足
[2026-10-30T05:57:17+00:00][error] [0]权限不足
[2026-10-30T05:57:17+00:00][error] [0]权限不足
[2026-10-30T05:57:17+00:00][error] [0]权限不足
[2026-10-30T05:57:17+00:00][error] [0]权限不足
[2026-10-30T05:57:17+00:00][error] [0]权限不足
[2026-10-30T05:57:17+00:00][error] [0]权限不足
[2026-10-30T05:57:17+00:00][error] [0]权限不足
[2026-10-30T05:57:17+00:00][error] [0]权限不足
[2026-10-30T05:57:17+00:00][error] [0]权限不足
[2026-10-30T05:57:17+00:00][error] [0]权限不足
[2026-10-30T05:57:17+00:00][error] [0]权限不足
[2026-10-30T05:57:18+00:00][error] [0]原系统不支持停用角色
[2026-10-30T05:57:18+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T05:57:18+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T05:57:18+00:00][error] [0]请先修改首次登录密码
[2026-10-30T05:57:18+00:00][error] [0]请先修改首次登录密码
[2026-10-30T05:57:18+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T05:57:18+00:00][error] [0]请先到原后台完成企业微信绑定
[2026-10-30T05:57:19+00:00][error] [0]请先到原后台完成企业微信绑定
[2026-10-30T05:57:19+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T05:57:19+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T05:57:19+00:00][error] [0]原密码错误
[2026-10-30T05:57:19+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T05:57:19+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T05:57:19+00:00][error] [0]账号或密码错误,或账号已停用
[2026-10-30T05:57:19+00:00][error] [0]合成源拒绝
[2026-10-30T05:57:19+00:00][error] [0]请先到原后台完成企业微信绑定
[2026-10-30T05:57:19+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T05:57:19+00:00][error] [0]请先到原后台完成企业微信绑定
[2026-10-30T05:57:20+00:00][error] [0]共享数据源响应异常
[2026-10-30T05:57:20+00:00][error] [0]共享数据源响应异常
[2026-10-30T05:57:20+00:00][error] [0]共享数据源暂时不可用
[2026-10-30T05:57:20+00:00][error] [0]无法连接共享数据源,请稍后重试
[2026-10-30T05:59:04+00:00][error] [0]请先登录
[2026-10-30T05:59:05+00:00][error] [0]仅集团管理员可管理公司和成员资格
[2026-10-30T05:59:05+00:00][error] [0]仅集团管理员可管理公司和成员资格
[2026-10-30T05:59:05+00:00][error] [0]当前公司尚未接入子系统,不提供医院目录数据
[2026-10-30T05:59:05+00:00][error] [0]当前公司尚未接入子系统,不提供医院目录数据
[2026-10-30T05:59:05+00:00][error] [0]当前公司尚未接入子系统,不提供医院目录数据
[2026-10-30T05:59:05+00:00][error] [0]当前公司尚未接入子系统,不提供医院目录数据
[2026-10-30T05:59:05+00:00][error] [0]当前公司尚未接入子系统,不提供医院目录数据
[2026-10-30T05:59:05+00:00][error] [0]id必须是有效整数
[2026-10-30T05:59:05+00:00][error] [0]登录凭证无效或已过期,请重新进入医院
[2026-10-30T05:59:06+00:00][error] [0]当前账号没有该公司的应用访问资格
[2026-10-30T05:59:06+00:00][error] [0]当前账号没有该公司的应用访问资格
[2026-10-30T05:59:06+00:00][error] [0]账号已停用,请重新登录
[2026-10-30T05:59:06+00:00][error] [0]应用或回调地址未注册
[2026-10-30T06:01:36+00:00][error] [0]请先登录
[2026-10-30T06:01:36+00:00][error] [0]仅集团管理员可管理公司和成员资格
[2026-10-30T06:01:36+00:00][error] [0]仅集团管理员可管理公司和成员资格
[2026-10-30T06:01:36+00:00][error] [0]当前公司尚未接入子系统,不提供医院目录数据
[2026-10-30T06:01:36+00:00][error] [0]当前公司尚未接入子系统,不提供医院目录数据
[2026-10-30T06:01:36+00:00][error] [0]当前公司尚未接入子系统,不提供医院目录数据
[2026-10-30T06:01:36+00:00][error] [0]当前公司尚未接入子系统,不提供医院目录数据
[2026-10-30T06:01:36+00:00][error] [0]当前公司尚未接入子系统,不提供医院目录数据
[2026-10-30T06:01:37+00:00][error] [0]id必须是有效整数
[2026-10-30T06:01:37+00:00][error] [0]登录凭证无效或已过期,请重新进入医院
[2026-10-30T06:01:37+00:00][error] [0]当前账号没有该公司的应用访问资格
[2026-10-30T06:01:37+00:00][error] [0]当前账号没有该公司的应用访问资格
[2026-10-30T06:01:37+00:00][error] [0]账号已停用,请重新登录
[2026-10-30T06:01:37+00:00][error] [0]应用或回调地址未注册
[2026-10-30T06:01:45+00:00][error] [0]请先登录
[2026-10-30T06:01:45+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T06:01:45+00:00][error] [0]请先登录
[2026-10-30T06:01:45+00:00][error] [0]请先登录
[2026-10-30T06:01:45+00:00][error] [0]账号或密码错误,或账号已停用
[2026-10-30T06:01:45+00:00][error] [0]账号或密码错误,或账号已停用
[2026-10-30T06:01:46+00:00][error] [0]仅集团管理员可管理公司和成员资格
[2026-10-30T06:01:46+00:00][error] [0]仅集团管理员可管理公司和成员资格
[2026-10-30T06:01:46+00:00][error] [0]当前公司尚未接入子系统,不提供医院目录数据
[2026-10-30T06:01:46+00:00][error] [0]当前公司尚未接入子系统,不提供医院目录数据
[2026-10-30T06:01:46+00:00][error] [0]当前公司尚未接入子系统,不提供医院目录数据
[2026-10-30T06:01:46+00:00][error] [0]当前公司尚未接入子系统,不提供医院目录数据
[2026-10-30T06:01:46+00:00][error] [0]当前公司尚未接入子系统,不提供医院目录数据
[2026-10-30T06:01:46+00:00][error] [0]id必须是有效整数
[2026-10-30T06:01:46+00:00][error] [0]权限不足
[2026-10-30T06:01:46+00:00][error] [0]权限不足
[2026-10-30T06:01:46+00:00][error] [0]登录凭证无效或已过期,请重新进入医院
[2026-10-30T06:01:46+00:00][error] [0]权限不足
[2026-10-30T06:01:46+00:00][error] [0]权限不足
[2026-10-30T06:01:46+00:00][error] [0]权限不足
[2026-10-30T06:01:46+00:00][error] [0]权限不足
[2026-10-30T06:01:46+00:00][error] [0]当前账号没有该公司的应用访问资格
[2026-10-30T06:01:46+00:00][error] [0]权限不足
[2026-10-30T06:01:46+00:00][error] [0]当前账号没有该公司的应用访问资格
[2026-10-30T06:01:46+00:00][error] [0]权限不足
[2026-10-30T06:01:47+00:00][error] [0]权限不足
[2026-10-30T06:01:47+00:00][error] [0]账号已停用,请重新登录
[2026-10-30T06:01:47+00:00][error] [0]权限不足
[2026-10-30T06:01:47+00:00][error] [0]权限不足
[2026-10-30T06:01:47+00:00][error] [0]应用或回调地址未注册
[2026-10-30T06:01:47+00:00][error] [0]权限不足
[2026-10-30T06:01:47+00:00][error] [0]权限不足
[2026-10-30T06:01:47+00:00][error] [0]权限不足
[2026-10-30T06:01:47+00:00][error] [0]原系统不支持停用角色
[2026-10-30T06:01:48+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T06:01:48+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T06:01:49+00:00][error] [0]请先修改首次登录密码
[2026-10-30T06:01:49+00:00][error] [0]请先修改首次登录密码
[2026-10-30T06:01:49+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T06:01:50+00:00][error] [0]请先到原后台完成企业微信绑定
[2026-10-30T06:01:50+00:00][error] [0]请先到原后台完成企业微信绑定
[2026-10-30T06:01:50+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T06:01:50+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T06:01:50+00:00][error] [0]原密码错误
[2026-10-30T06:01:51+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T06:01:51+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T06:01:51+00:00][error] [0]账号或密码错误,或账号已停用
[2026-10-30T06:01:51+00:00][error] [0]合成源拒绝
[2026-10-30T06:01:51+00:00][error] [0]请先到原后台完成企业微信绑定
[2026-10-30T06:01:51+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T06:01:51+00:00][error] [0]请先到原后台完成企业微信绑定
[2026-10-30T06:01:51+00:00][error] [0]共享数据源响应异常
[2026-10-30T06:01:51+00:00][error] [0]共享数据源响应异常
[2026-10-30T06:01:51+00:00][error] [0]共享数据源暂时不可用
[2026-10-30T06:01:51+00:00][error] [0]无法连接共享数据源,请稍后重试
[2026-10-30T06:06:26+00:00][error] [0]请先登录
[2026-10-30T06:06:26+00:00][error] [0]请先登录
[2026-10-30T06:06:27+00:00][error] [0]账号已存在
[2026-10-30T06:06:27+00:00][error] [0]角色不存在
[2026-10-30T06:06:27+00:00][error] [0]部门不存在
[2026-10-30T06:06:27+00:00][error] [0]菜单不存在
[2026-10-30T06:06:27+00:00][error] [0]页面路径须为有效绝对路径
[2026-10-30T06:06:27+00:00][error] [0]页面路径须为有效绝对路径
[2026-10-30T06:06:27+00:00][error] [0]页面路径须为有效绝对路径
[2026-10-30T06:06:27+00:00][error] [0]页面路径须为有效绝对路径
[2026-10-30T06:06:27+00:00][error] [0]页面路径须为有效绝对路径
[2026-10-30T06:06:27+00:00][error] [0]页面路径须为有效绝对路径
[2026-10-30T06:06:28+00:00][error] [0]首页路径仅允许使用首页组件
[2026-10-30T06:06:28+00:00][error] [0]上级节点不能是自己或后代
[2026-10-30T06:06:28+00:00][error] [0]上级节点不能是自己或后代
[2026-10-30T06:06:28+00:00][error] [0]上级节点不能是自己或后代
[2026-10-30T06:06:28+00:00][error] [0]上级节点不能是自己或后代
[2026-10-30T06:06:28+00:00][error] [0]存在子节点,不能删除
[2026-10-30T06:06:28+00:00][error] [0]部门仍关联用户,不能删除
[2026-10-30T06:06:28+00:00][error] [0]角色仍关联用户,不能删除
[2026-10-30T06:06:28+00:00][error] [0]存在子节点,不能删除
[2026-10-30T06:06:28+00:00][error] [0]权限不足
[2026-10-30T06:06:28+00:00][error] [0]权限不足
[2026-10-30T06:06:29+00:00][error] [0]权限不足
[2026-10-30T06:06:29+00:00][error] [0]权限不足
[2026-10-30T06:06:30+00:00][error] [0]权限不足
[2026-10-30T06:06:30+00:00][error] [0]权限不足
[2026-10-30T06:06:30+00:00][error] [0]权限不足
[2026-10-30T06:06:30+00:00][error] [0]权限不足
[2026-10-30T06:06:30+00:00][error] [0]权限不足
[2026-10-30T06:06:30+00:00][error] [0]权限不足
[2026-10-30T06:06:30+00:00][error] [0]权限不足
[2026-10-30T06:06:30+00:00][error] [0]权限不足
[2026-10-30T06:06:30+00:00][error] [0]权限不足
[2026-10-30T06:06:30+00:00][error] [0]权限不足
[2026-10-30T06:06:30+00:00][error] [0]权限不足
[2026-10-30T06:06:30+00:00][error] [0]权限不足
[2026-10-30T06:06:30+00:00][error] [0]不能新增关联已停用的角色或部门
[2026-10-30T06:06:31+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T06:06:31+00:00][error] [0]账号或密码错误,或账号已停用
[2026-10-30T06:06:31+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T06:06:32+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T06:06:32+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T06:06:32+00:00][error] [0]账号或密码错误,或账号已停用
[2026-10-30T06:06:32+00:00][error] [0]请求包含不支持的字段
[2026-10-30T06:06:33+00:00][error] [0]不能停用自己或根账号
[2026-10-30T07:03:55+00:00][error] [0]请先登录
[2026-10-30T07:03:56+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T07:03:56+00:00][error] [0]请先登录
[2026-10-30T07:03:56+00:00][error] [0]请先登录
[2026-10-30T07:03:56+00:00][error] [0]账号或密码错误,或账号已停用
[2026-10-30T07:03:56+00:00][error] [0]账号或密码错误,或账号已停用
[2026-10-30T07:03:56+00:00][error] [0]仅集团管理员可管理公司和成员资格
[2026-10-30T07:03:56+00:00][error] [0]仅集团管理员可管理公司和成员资格
[2026-10-30T07:03:57+00:00][error] [0]当前公司尚未接入子系统,不提供医院目录数据
[2026-10-30T07:03:57+00:00][error] [0]当前公司尚未接入子系统,不提供医院目录数据
[2026-10-30T07:03:57+00:00][error] [0]当前公司尚未接入子系统,不提供医院目录数据
[2026-10-30T07:03:57+00:00][error] [0]当前公司尚未接入子系统,不提供医院目录数据
[2026-10-30T07:03:57+00:00][error] [0]当前公司尚未接入子系统,不提供医院目录数据
[2026-10-30T07:03:57+00:00][error] [0]id必须是有效整数
[2026-10-30T07:03:57+00:00][error] [0]权限不足
[2026-10-30T07:03:57+00:00][error] [0]权限不足
[2026-10-30T07:03:57+00:00][error] [0]权限不足
[2026-10-30T07:03:57+00:00][error] [0]登录凭证无效或已过期,请重新进入医院
[2026-10-30T07:03:57+00:00][error] [0]权限不足
[2026-10-30T07:03:57+00:00][error] [0]权限不足
[2026-10-30T07:03:57+00:00][error] [0]权限不足
[2026-10-30T07:03:57+00:00][error] [0]权限不足
[2026-10-30T07:03:57+00:00][error] [0]当前账号没有该公司的应用访问资格
[2026-10-30T07:03:57+00:00][error] [0]权限不足
[2026-10-30T07:03:57+00:00][error] [0]权限不足
[2026-10-30T07:03:57+00:00][error] [0]当前账号没有该公司的应用访问资格
[2026-10-30T07:03:57+00:00][error] [0]权限不足
[2026-10-30T07:03:58+00:00][error] [0]权限不足
[2026-10-30T07:03:58+00:00][error] [0]账号已停用,请重新登录
[2026-10-30T07:03:58+00:00][error] [0]权限不足
[2026-10-30T07:03:58+00:00][error] [0]应用或回调地址未注册
[2026-10-30T07:03:58+00:00][error] [0]权限不足
[2026-10-30T07:03:58+00:00][error] [0]权限不足
[2026-10-30T07:03:58+00:00][error] [0]原系统不支持停用角色
[2026-10-30T07:03:59+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T07:03:59+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T07:03:59+00:00][error] [0]请先修改首次登录密码
[2026-10-30T07:03:59+00:00][error] [0]请先修改首次登录密码
[2026-10-30T07:03:59+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T07:03:59+00:00][error] [0]请先到原后台完成企业微信绑定
[2026-10-30T07:04:00+00:00][error] [0]请先到原后台完成企业微信绑定
[2026-10-30T07:04:00+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T07:04:00+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T07:04:00+00:00][error] [0]原密码错误
[2026-10-30T07:04:00+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T07:04:00+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T07:04:00+00:00][error] [0]账号或密码错误,或账号已停用
[2026-10-30T07:04:00+00:00][error] [0]合成源拒绝
[2026-10-30T07:04:00+00:00][error] [0]请先到原后台完成企业微信绑定
[2026-10-30T07:04:01+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T07:04:01+00:00][error] [0]请先到原后台完成企业微信绑定
[2026-10-30T07:04:01+00:00][error] [0]共享数据源响应异常
[2026-10-30T07:04:01+00:00][error] [0]共享数据源响应异常
[2026-10-30T07:04:01+00:00][error] [0]共享数据源暂时不可用
[2026-10-30T07:04:01+00:00][error] [0]无法连接共享数据源,请稍后重试
[2026-10-30T07:21:28+00:00][error] [0]请先登录
[2026-10-30T07:21:29+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T07:21:29+00:00][error] [0]请先登录
[2026-10-30T07:21:29+00:00][error] [0]账号或密码错误,或账号已停用
[2026-10-30T07:21:29+00:00][error] [0]账号或密码错误,或账号已停用
[2026-10-30T07:21:29+00:00][error] [0]权限不足
[2026-10-30T07:21:30+00:00][error] [0]权限不足
[2026-10-30T07:21:30+00:00][error] [0]权限不足
[2026-10-30T07:21:30+00:00][error] [0]权限不足
[2026-10-30T07:21:30+00:00][error] [0]权限不足
[2026-10-30T07:21:30+00:00][error] [0]权限不足
[2026-10-30T07:21:30+00:00][error] [0]权限不足
[2026-10-30T07:21:30+00:00][error] [0]权限不足
[2026-10-30T07:21:30+00:00][error] [0]权限不足
[2026-10-30T07:21:30+00:00][error] [0]权限不足
[2026-10-30T07:21:30+00:00][error] [0]权限不足
[2026-10-30T07:21:30+00:00][error] [0]权限不足
[2026-10-30T07:21:30+00:00][error] [0]权限不足
[2026-10-30T07:21:30+00:00][error] [0]权限不足
[2026-10-30T07:21:31+00:00][error] [0]原系统不支持停用角色
[2026-10-30T07:21:31+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T07:21:31+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T07:21:31+00:00][error] [0]请先修改首次登录密码
[2026-10-30T07:21:31+00:00][error] [0]请先修改首次登录密码
[2026-10-30T07:21:32+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T07:21:32+00:00][error] [0]请先到原后台完成企业微信绑定
[2026-10-30T07:21:32+00:00][error] [0]请先到原后台完成企业微信绑定
[2026-10-30T07:21:32+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T07:21:33+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T07:21:33+00:00][error] [0]原密码错误
[2026-10-30T07:21:33+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T07:21:33+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T07:21:33+00:00][error] [0]账号或密码错误,或账号已停用
[2026-10-30T07:21:34+00:00][error] [0]合成源拒绝
[2026-10-30T07:21:34+00:00][error] [0]请先到原后台完成企业微信绑定
[2026-10-30T07:21:34+00:00][error] [0]登录已失效,请重新登录
[2026-10-30T07:21:34+00:00][error] [0]请先到原后台完成企业微信绑定
[2026-10-30T07:21:34+00:00][error] [0]共享数据源响应异常
[2026-10-30T07:21:34+00:00][error] [0]共享数据源响应异常
[2026-10-30T07:21:34+00:00][error] [0]共享数据源暂时不可用
[2026-10-30T07:21:34+00:00][error] [0]无法连接共享数据源,请稍后重试
@@ -0,0 +1 @@
[2026-11-02T08:28:25+00:00][error] [0]账号或密码错误,或账号已停用
@@ -0,0 +1,4 @@
[2026-11-03T06:35:02+00:00][error] [0]登录已失效,请重新登录
[2026-11-03T07:25:47+00:00][error] [0]账号格式错误
[2026-11-03T15:55:34+00:00][error] [0]登录已失效,请重新登录
[2026-11-03T15:55:34+00:00][error] [0]请先登录
@@ -0,0 +1,3 @@
[2026-11-04T01:32:15+00:00][error] [0]账号或密码错误,或账号已停用
[2026-11-04T01:32:20+00:00][error] [0]账号或密码错误,或账号已停用
[2026-11-04T01:32:25+00:00][error] [0]账号或密码错误,或账号已停用
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,5 @@
{
"root": "C:\\zyt\\server",
"pid": 14000,
"port": 8082
}
+22
View File
@@ -0,0 +1,22 @@
<?php
// autoload.php @generated by Composer
if (PHP_VERSION_ID < 50600) {
if (!headers_sent()) {
header('HTTP/1.1 500 Internal Server Error');
}
$err = 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL;
if (!ini_get('display_errors')) {
if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
fwrite(STDERR, $err);
} elseif (!headers_sent()) {
echo $err;
}
}
throw new RuntimeException($err);
}
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit65c59340162793bd027dabb86cb7a03d::getLoader();
+579
View File
@@ -0,0 +1,579 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Autoload;
/**
* ClassLoader implements a PSR-0, PSR-4 and classmap class loader.
*
* $loader = new \Composer\Autoload\ClassLoader();
*
* // register classes with namespaces
* $loader->add('Symfony\Component', __DIR__.'/component');
* $loader->add('Symfony', __DIR__.'/framework');
*
* // activate the autoloader
* $loader->register();
*
* // to enable searching the include path (eg. for PEAR packages)
* $loader->setUseIncludePath(true);
*
* In this example, if you try to use a class in the Symfony\Component
* namespace or one of its children (Symfony\Component\Console for instance),
* the autoloader will first look for the class under the component/
* directory, and it will then fallback to the framework/ directory if not
* found before giving up.
*
* This class is loosely based on the Symfony UniversalClassLoader.
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Jordi Boggiano <j.boggiano@seld.be>
* @see https://www.php-fig.org/psr/psr-0/
* @see https://www.php-fig.org/psr/psr-4/
*/
class ClassLoader
{
/** @var \Closure(string):void */
private static $includeFile;
/** @var string|null */
private $vendorDir;
// PSR-4
/**
* @var array<string, array<string, int>>
*/
private $prefixLengthsPsr4 = array();
/**
* @var array<string, list<string>>
*/
private $prefixDirsPsr4 = array();
/**
* @var list<string>
*/
private $fallbackDirsPsr4 = array();
// PSR-0
/**
* List of PSR-0 prefixes
*
* Structured as array('F (first letter)' => array('Foo\Bar (full prefix)' => array('path', 'path2')))
*
* @var array<string, array<string, list<string>>>
*/
private $prefixesPsr0 = array();
/**
* @var list<string>
*/
private $fallbackDirsPsr0 = array();
/** @var bool */
private $useIncludePath = false;
/**
* @var array<string, string>
*/
private $classMap = array();
/** @var bool */
private $classMapAuthoritative = false;
/**
* @var array<string, bool>
*/
private $missingClasses = array();
/** @var string|null */
private $apcuPrefix;
/**
* @var array<string, self>
*/
private static $registeredLoaders = array();
/**
* @param string|null $vendorDir
*/
public function __construct($vendorDir = null)
{
$this->vendorDir = $vendorDir;
self::initializeIncludeClosure();
}
/**
* @return array<string, list<string>>
*/
public function getPrefixes()
{
if (!empty($this->prefixesPsr0)) {
return call_user_func_array('array_merge', array_values($this->prefixesPsr0));
}
return array();
}
/**
* @return array<string, list<string>>
*/
public function getPrefixesPsr4()
{
return $this->prefixDirsPsr4;
}
/**
* @return list<string>
*/
public function getFallbackDirs()
{
return $this->fallbackDirsPsr0;
}
/**
* @return list<string>
*/
public function getFallbackDirsPsr4()
{
return $this->fallbackDirsPsr4;
}
/**
* @return array<string, string> Array of classname => path
*/
public function getClassMap()
{
return $this->classMap;
}
/**
* @param array<string, string> $classMap Class to filename map
*
* @return void
*/
public function addClassMap(array $classMap)
{
if ($this->classMap) {
$this->classMap = array_merge($this->classMap, $classMap);
} else {
$this->classMap = $classMap;
}
}
/**
* Registers a set of PSR-0 directories for a given prefix, either
* appending or prepending to the ones previously set for this prefix.
*
* @param string $prefix The prefix
* @param list<string>|string $paths The PSR-0 root directories
* @param bool $prepend Whether to prepend the directories
*
* @return void
*/
public function add($prefix, $paths, $prepend = false)
{
$paths = (array) $paths;
if (!$prefix) {
if ($prepend) {
$this->fallbackDirsPsr0 = array_merge(
$paths,
$this->fallbackDirsPsr0
);
} else {
$this->fallbackDirsPsr0 = array_merge(
$this->fallbackDirsPsr0,
$paths
);
}
return;
}
$first = $prefix[0];
if (!isset($this->prefixesPsr0[$first][$prefix])) {
$this->prefixesPsr0[$first][$prefix] = $paths;
return;
}
if ($prepend) {
$this->prefixesPsr0[$first][$prefix] = array_merge(
$paths,
$this->prefixesPsr0[$first][$prefix]
);
} else {
$this->prefixesPsr0[$first][$prefix] = array_merge(
$this->prefixesPsr0[$first][$prefix],
$paths
);
}
}
/**
* Registers a set of PSR-4 directories for a given namespace, either
* appending or prepending to the ones previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param list<string>|string $paths The PSR-4 base directories
* @param bool $prepend Whether to prepend the directories
*
* @throws \InvalidArgumentException
*
* @return void
*/
public function addPsr4($prefix, $paths, $prepend = false)
{
$paths = (array) $paths;
if (!$prefix) {
// Register directories for the root namespace.
if ($prepend) {
$this->fallbackDirsPsr4 = array_merge(
$paths,
$this->fallbackDirsPsr4
);
} else {
$this->fallbackDirsPsr4 = array_merge(
$this->fallbackDirsPsr4,
$paths
);
}
} elseif (!isset($this->prefixDirsPsr4[$prefix])) {
// Register directories for a new namespace.
$length = strlen($prefix);
if ('\\' !== $prefix[$length - 1]) {
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
}
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
$this->prefixDirsPsr4[$prefix] = $paths;
} elseif ($prepend) {
// Prepend directories for an already registered namespace.
$this->prefixDirsPsr4[$prefix] = array_merge(
$paths,
$this->prefixDirsPsr4[$prefix]
);
} else {
// Append directories for an already registered namespace.
$this->prefixDirsPsr4[$prefix] = array_merge(
$this->prefixDirsPsr4[$prefix],
$paths
);
}
}
/**
* Registers a set of PSR-0 directories for a given prefix,
* replacing any others previously set for this prefix.
*
* @param string $prefix The prefix
* @param list<string>|string $paths The PSR-0 base directories
*
* @return void
*/
public function set($prefix, $paths)
{
if (!$prefix) {
$this->fallbackDirsPsr0 = (array) $paths;
} else {
$this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
}
}
/**
* Registers a set of PSR-4 directories for a given namespace,
* replacing any others previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param list<string>|string $paths The PSR-4 base directories
*
* @throws \InvalidArgumentException
*
* @return void
*/
public function setPsr4($prefix, $paths)
{
if (!$prefix) {
$this->fallbackDirsPsr4 = (array) $paths;
} else {
$length = strlen($prefix);
if ('\\' !== $prefix[$length - 1]) {
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
}
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
$this->prefixDirsPsr4[$prefix] = (array) $paths;
}
}
/**
* Turns on searching the include path for class files.
*
* @param bool $useIncludePath
*
* @return void
*/
public function setUseIncludePath($useIncludePath)
{
$this->useIncludePath = $useIncludePath;
}
/**
* Can be used to check if the autoloader uses the include path to check
* for classes.
*
* @return bool
*/
public function getUseIncludePath()
{
return $this->useIncludePath;
}
/**
* Turns off searching the prefix and fallback directories for classes
* that have not been registered with the class map.
*
* @param bool $classMapAuthoritative
*
* @return void
*/
public function setClassMapAuthoritative($classMapAuthoritative)
{
$this->classMapAuthoritative = $classMapAuthoritative;
}
/**
* Should class lookup fail if not found in the current class map?
*
* @return bool
*/
public function isClassMapAuthoritative()
{
return $this->classMapAuthoritative;
}
/**
* APCu prefix to use to cache found/not-found classes, if the extension is enabled.
*
* @param string|null $apcuPrefix
*
* @return void
*/
public function setApcuPrefix($apcuPrefix)
{
$this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null;
}
/**
* The APCu prefix in use, or null if APCu caching is not enabled.
*
* @return string|null
*/
public function getApcuPrefix()
{
return $this->apcuPrefix;
}
/**
* Registers this instance as an autoloader.
*
* @param bool $prepend Whether to prepend the autoloader or not
*
* @return void
*/
public function register($prepend = false)
{
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
if (null === $this->vendorDir) {
return;
}
if ($prepend) {
self::$registeredLoaders = array($this->vendorDir => $this) + self::$registeredLoaders;
} else {
unset(self::$registeredLoaders[$this->vendorDir]);
self::$registeredLoaders[$this->vendorDir] = $this;
}
}
/**
* Unregisters this instance as an autoloader.
*
* @return void
*/
public function unregister()
{
spl_autoload_unregister(array($this, 'loadClass'));
if (null !== $this->vendorDir) {
unset(self::$registeredLoaders[$this->vendorDir]);
}
}
/**
* Loads the given class or interface.
*
* @param string $class The name of the class
* @return true|null True if loaded, null otherwise
*/
public function loadClass($class)
{
if ($file = $this->findFile($class)) {
$includeFile = self::$includeFile;
$includeFile($file);
return true;
}
return null;
}
/**
* Finds the path to the file where the class is defined.
*
* @param string $class The name of the class
*
* @return string|false The path if found, false otherwise
*/
public function findFile($class)
{
// class map lookup
if (isset($this->classMap[$class])) {
return $this->classMap[$class];
}
if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
return false;
}
if (null !== $this->apcuPrefix) {
$file = apcu_fetch($this->apcuPrefix.$class, $hit);
if ($hit) {
return $file;
}
}
$file = $this->findFileWithExtension($class, '.php');
// Search for Hack files if we are running on HHVM
if (false === $file && defined('HHVM_VERSION')) {
$file = $this->findFileWithExtension($class, '.hh');
}
if (null !== $this->apcuPrefix) {
apcu_add($this->apcuPrefix.$class, $file);
}
if (false === $file) {
// Remember that this class does not exist.
$this->missingClasses[$class] = true;
}
return $file;
}
/**
* Returns the currently registered loaders keyed by their corresponding vendor directories.
*
* @return array<string, self>
*/
public static function getRegisteredLoaders()
{
return self::$registeredLoaders;
}
/**
* @param string $class
* @param string $ext
* @return string|false
*/
private function findFileWithExtension($class, $ext)
{
// PSR-4 lookup
$logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
$first = $class[0];
if (isset($this->prefixLengthsPsr4[$first])) {
$subPath = $class;
while (false !== $lastPos = strrpos($subPath, '\\')) {
$subPath = substr($subPath, 0, $lastPos);
$search = $subPath . '\\';
if (isset($this->prefixDirsPsr4[$search])) {
$pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
foreach ($this->prefixDirsPsr4[$search] as $dir) {
if (file_exists($file = $dir . $pathEnd)) {
return $file;
}
}
}
}
}
// PSR-4 fallback dirs
foreach ($this->fallbackDirsPsr4 as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
return $file;
}
}
// PSR-0 lookup
if (false !== $pos = strrpos($class, '\\')) {
// namespaced class name
$logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
. strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
} else {
// PEAR-like class name
$logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
}
if (isset($this->prefixesPsr0[$first])) {
foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
if (0 === strpos($class, $prefix)) {
foreach ($dirs as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
return $file;
}
}
}
}
}
// PSR-0 fallback dirs
foreach ($this->fallbackDirsPsr0 as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
return $file;
}
}
// PSR-0 include paths.
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
return $file;
}
return false;
}
/**
* @return void
*/
private static function initializeIncludeClosure()
{
if (self::$includeFile !== null) {
return;
}
/**
* Scope isolated include.
*
* Prevents access to $this/self from included files.
*
* @param string $file
* @return void
*/
self::$includeFile = \Closure::bind(static function($file) {
include $file;
}, null, null);
}
}
@@ -0,0 +1,396 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer;
use Composer\Autoload\ClassLoader;
use Composer\Semver\VersionParser;
/**
* This class is copied in every Composer installed project and available to all
*
* See also https://getcomposer.org/doc/07-runtime.md#installed-versions
*
* To require its presence, you can require `composer-runtime-api ^2.0`
*
* @final
*/
class InstalledVersions
{
/**
* @var string|null if set (by reflection by Composer), this should be set to the path where this class is being copied to
* @internal
*/
private static $selfDir = null;
/**
* @var mixed[]|null
* @psalm-var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}|array{}|null
*/
private static $installed;
/**
* @var bool
*/
private static $installedIsLocalDir;
/**
* @var bool|null
*/
private static $canGetVendors;
/**
* @var array[]
* @psalm-var array<string, array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}>
*/
private static $installedByVendor = array();
/**
* Returns a list of all package names which are present, either by being installed, replaced or provided
*
* @return string[]
* @psalm-return list<string>
*/
public static function getInstalledPackages()
{
$packages = array();
foreach (self::getInstalled() as $installed) {
$packages[] = array_keys($installed['versions']);
}
if (1 === \count($packages)) {
return $packages[0];
}
return array_keys(array_flip(\call_user_func_array('array_merge', $packages)));
}
/**
* Returns a list of all package names with a specific type e.g. 'library'
*
* @param string $type
* @return string[]
* @psalm-return list<string>
*/
public static function getInstalledPackagesByType($type)
{
$packagesByType = array();
foreach (self::getInstalled() as $installed) {
foreach ($installed['versions'] as $name => $package) {
if (isset($package['type']) && $package['type'] === $type) {
$packagesByType[] = $name;
}
}
}
return $packagesByType;
}
/**
* Checks whether the given package is installed
*
* This also returns true if the package name is provided or replaced by another package
*
* @param string $packageName
* @param bool $includeDevRequirements
* @return bool
*/
public static function isInstalled($packageName, $includeDevRequirements = true)
{
foreach (self::getInstalled() as $installed) {
if (isset($installed['versions'][$packageName])) {
return $includeDevRequirements || !isset($installed['versions'][$packageName]['dev_requirement']) || $installed['versions'][$packageName]['dev_requirement'] === false;
}
}
return false;
}
/**
* Checks whether the given package satisfies a version constraint
*
* e.g. If you want to know whether version 2.3+ of package foo/bar is installed, you would call:
*
* Composer\InstalledVersions::satisfies(new VersionParser, 'foo/bar', '^2.3')
*
* @param VersionParser $parser Install composer/semver to have access to this class and functionality
* @param string $packageName
* @param string|null $constraint A version constraint to check for, if you pass one you have to make sure composer/semver is required by your package
* @return bool
*/
public static function satisfies(VersionParser $parser, $packageName, $constraint)
{
$constraint = $parser->parseConstraints((string) $constraint);
$provided = $parser->parseConstraints(self::getVersionRanges($packageName));
return $provided->matches($constraint);
}
/**
* Returns a version constraint representing all the range(s) which are installed for a given package
*
* It is easier to use this via isInstalled() with the $constraint argument if you need to check
* whether a given version of a package is installed, and not just whether it exists
*
* @param string $packageName
* @return string Version constraint usable with composer/semver
*/
public static function getVersionRanges($packageName)
{
foreach (self::getInstalled() as $installed) {
if (!isset($installed['versions'][$packageName])) {
continue;
}
$ranges = array();
if (isset($installed['versions'][$packageName]['pretty_version'])) {
$ranges[] = $installed['versions'][$packageName]['pretty_version'];
}
if (array_key_exists('aliases', $installed['versions'][$packageName])) {
$ranges = array_merge($ranges, $installed['versions'][$packageName]['aliases']);
}
if (array_key_exists('replaced', $installed['versions'][$packageName])) {
$ranges = array_merge($ranges, $installed['versions'][$packageName]['replaced']);
}
if (array_key_exists('provided', $installed['versions'][$packageName])) {
$ranges = array_merge($ranges, $installed['versions'][$packageName]['provided']);
}
return implode(' || ', $ranges);
}
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
}
/**
* @param string $packageName
* @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present
*/
public static function getVersion($packageName)
{
foreach (self::getInstalled() as $installed) {
if (!isset($installed['versions'][$packageName])) {
continue;
}
if (!isset($installed['versions'][$packageName]['version'])) {
return null;
}
return $installed['versions'][$packageName]['version'];
}
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
}
/**
* @param string $packageName
* @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present
*/
public static function getPrettyVersion($packageName)
{
foreach (self::getInstalled() as $installed) {
if (!isset($installed['versions'][$packageName])) {
continue;
}
if (!isset($installed['versions'][$packageName]['pretty_version'])) {
return null;
}
return $installed['versions'][$packageName]['pretty_version'];
}
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
}
/**
* @param string $packageName
* @return string|null If the package is being replaced or provided but is not really installed, null will be returned as reference
*/
public static function getReference($packageName)
{
foreach (self::getInstalled() as $installed) {
if (!isset($installed['versions'][$packageName])) {
continue;
}
if (!isset($installed['versions'][$packageName]['reference'])) {
return null;
}
return $installed['versions'][$packageName]['reference'];
}
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
}
/**
* @param string $packageName
* @return string|null If the package is being replaced or provided but is not really installed, null will be returned as install path. Packages of type metapackages also have a null install path.
*/
public static function getInstallPath($packageName)
{
foreach (self::getInstalled() as $installed) {
if (!isset($installed['versions'][$packageName])) {
continue;
}
return isset($installed['versions'][$packageName]['install_path']) ? $installed['versions'][$packageName]['install_path'] : null;
}
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
}
/**
* @return array
* @psalm-return array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}
*/
public static function getRootPackage()
{
$installed = self::getInstalled();
return $installed[0]['root'];
}
/**
* Returns the raw installed.php data for custom implementations
*
* @deprecated Use getAllRawData() instead which returns all datasets for all autoloaders present in the process. getRawData only returns the first dataset loaded, which may not be what you expect.
* @return array[]
* @psalm-return array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}
*/
public static function getRawData()
{
@trigger_error('getRawData only returns the first dataset loaded, which may not be what you expect. Use getAllRawData() instead which returns all datasets for all autoloaders present in the process.', E_USER_DEPRECATED);
if (null === self::$installed) {
// only require the installed.php file if this file is loaded from its dumped location,
// and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
if (substr(__DIR__, -8, 1) !== 'C') {
self::$installed = include __DIR__ . '/installed.php';
} else {
self::$installed = array();
}
}
return self::$installed;
}
/**
* Returns the raw data of all installed.php which are currently loaded for custom implementations
*
* @return array[]
* @psalm-return list<array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}>
*/
public static function getAllRawData()
{
return self::getInstalled();
}
/**
* Lets you reload the static array from another file
*
* This is only useful for complex integrations in which a project needs to use
* this class but then also needs to execute another project's autoloader in process,
* and wants to ensure both projects have access to their version of installed.php.
*
* A typical case would be PHPUnit, where it would need to make sure it reads all
* the data it needs from this class, then call reload() with
* `require $CWD/vendor/composer/installed.php` (or similar) as input to make sure
* the project in which it runs can then also use this class safely, without
* interference between PHPUnit's dependencies and the project's dependencies.
*
* @param array[] $data A vendor/composer/installed.php data set
* @return void
*
* @psalm-param array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $data
*/
public static function reload($data)
{
self::$installed = $data;
self::$installedByVendor = array();
// when using reload, we disable the duplicate protection to ensure that self::$installed data is
// always returned, but we cannot know whether it comes from the installed.php in __DIR__ or not,
// so we have to assume it does not, and that may result in duplicate data being returned when listing
// all installed packages for example
self::$installedIsLocalDir = false;
}
/**
* @return string
*/
private static function getSelfDir()
{
if (self::$selfDir === null) {
self::$selfDir = strtr(__DIR__, '\\', '/');
}
return self::$selfDir;
}
/**
* @return array[]
* @psalm-return list<array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}>
*/
private static function getInstalled()
{
if (null === self::$canGetVendors) {
self::$canGetVendors = method_exists('Composer\Autoload\ClassLoader', 'getRegisteredLoaders');
}
$installed = array();
$copiedLocalDir = false;
if (self::$canGetVendors) {
$selfDir = self::getSelfDir();
foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) {
$vendorDir = strtr($vendorDir, '\\', '/');
if (isset(self::$installedByVendor[$vendorDir])) {
$installed[] = self::$installedByVendor[$vendorDir];
} elseif (is_file($vendorDir.'/composer/installed.php')) {
/** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
$required = require $vendorDir.'/composer/installed.php';
self::$installedByVendor[$vendorDir] = $required;
$installed[] = $required;
if (self::$installed === null && $vendorDir.'/composer' === $selfDir) {
self::$installed = $required;
self::$installedIsLocalDir = true;
}
}
if (self::$installedIsLocalDir && $vendorDir.'/composer' === $selfDir) {
$copiedLocalDir = true;
}
}
}
if (null === self::$installed) {
// only require the installed.php file if this file is loaded from its dumped location,
// and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
if (substr(__DIR__, -8, 1) !== 'C') {
/** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
$required = require __DIR__ . '/installed.php';
self::$installed = $required;
} else {
self::$installed = array();
}
}
if (self::$installed !== array() && !$copiedLocalDir) {
$installed[] = self::$installed;
}
return $installed;
}
}
+21
View File
@@ -0,0 +1,21 @@
Copyright (c) Nils Adermann, Jordi Boggiano
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
@@ -0,0 +1,10 @@
<?php
// autoload_classmap.php @generated by Composer
$vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir);
return array(
'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
);
@@ -0,0 +1,13 @@
<?php
// autoload_files.php @generated by Composer
$vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir);
return array(
'9b552a3cc426e3287cc811caefa3cf53' => $vendorDir . '/topthink/think-helper/src/helper.php',
'15ec93fa4ce4b2d53816a1a5f2c514e2' => $vendorDir . '/topthink/think-validate/src/helper.php',
'7448f3465e10b5f033e4babb31eb0b06' => $vendorDir . '/topthink/think-orm/src/helper.php',
'35fab96057f1bf5e7aba31a8a6d5fdde' => $vendorDir . '/topthink/think-orm/stubs/load_stubs.php',
);
@@ -0,0 +1,9 @@
<?php
// autoload_namespaces.php @generated by Composer
$vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir);
return array(
);
+15
View File
@@ -0,0 +1,15 @@
<?php
// autoload_psr4.php @generated by Composer
$vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir);
return array(
'think\\' => array($vendorDir . '/topthink/framework/src/think', $vendorDir . '/topthink/think-orm/src', $vendorDir . '/topthink/think-validate/src', $vendorDir . '/topthink/think-container/src', $vendorDir . '/topthink/think-helper/src'),
'app\\' => array($baseDir . '/app'),
'Psr\\SimpleCache\\' => array($vendorDir . '/psr/simple-cache/src'),
'Psr\\Log\\' => array($vendorDir . '/psr/log/src'),
'Psr\\Http\\Message\\' => array($vendorDir . '/psr/http-message/src'),
'Psr\\Container\\' => array($vendorDir . '/psr/container/src'),
);
+50
View File
@@ -0,0 +1,50 @@
<?php
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit65c59340162793bd027dabb86cb7a03d
{
private static $loader;
public static function loadClassLoader($class)
{
if ('Composer\Autoload\ClassLoader' === $class) {
require __DIR__ . '/ClassLoader.php';
}
}
/**
* @return \Composer\Autoload\ClassLoader
*/
public static function getLoader()
{
if (null !== self::$loader) {
return self::$loader;
}
require __DIR__ . '/platform_check.php';
spl_autoload_register(array('ComposerAutoloaderInit65c59340162793bd027dabb86cb7a03d', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit65c59340162793bd027dabb86cb7a03d', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit65c59340162793bd027dabb86cb7a03d::getInitializer($loader));
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInit65c59340162793bd027dabb86cb7a03d::$files;
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
require $file;
}
}, null, null);
foreach ($filesToLoad as $fileIdentifier => $file) {
$requireFile($fileIdentifier, $file);
}
return $loader;
}
}
@@ -0,0 +1,78 @@
<?php
// autoload_static.php @generated by Composer
namespace Composer\Autoload;
class ComposerStaticInit65c59340162793bd027dabb86cb7a03d
{
public static $files = array (
'9b552a3cc426e3287cc811caefa3cf53' => __DIR__ . '/..' . '/topthink/think-helper/src/helper.php',
'15ec93fa4ce4b2d53816a1a5f2c514e2' => __DIR__ . '/..' . '/topthink/think-validate/src/helper.php',
'7448f3465e10b5f033e4babb31eb0b06' => __DIR__ . '/..' . '/topthink/think-orm/src/helper.php',
'35fab96057f1bf5e7aba31a8a6d5fdde' => __DIR__ . '/..' . '/topthink/think-orm/stubs/load_stubs.php',
);
public static $prefixLengthsPsr4 = array (
't' =>
array (
'think\\' => 6,
),
'a' =>
array (
'app\\' => 4,
),
'P' =>
array (
'Psr\\SimpleCache\\' => 16,
'Psr\\Log\\' => 8,
'Psr\\Http\\Message\\' => 17,
'Psr\\Container\\' => 14,
),
);
public static $prefixDirsPsr4 = array (
'think\\' =>
array (
0 => __DIR__ . '/..' . '/topthink/framework/src/think',
1 => __DIR__ . '/..' . '/topthink/think-orm/src',
2 => __DIR__ . '/..' . '/topthink/think-validate/src',
3 => __DIR__ . '/..' . '/topthink/think-container/src',
4 => __DIR__ . '/..' . '/topthink/think-helper/src',
),
'app\\' =>
array (
0 => __DIR__ . '/../..' . '/app',
),
'Psr\\SimpleCache\\' =>
array (
0 => __DIR__ . '/..' . '/psr/simple-cache/src',
),
'Psr\\Log\\' =>
array (
0 => __DIR__ . '/..' . '/psr/log/src',
),
'Psr\\Http\\Message\\' =>
array (
0 => __DIR__ . '/..' . '/psr/http-message/src',
),
'Psr\\Container\\' =>
array (
0 => __DIR__ . '/..' . '/psr/container/src',
),
);
public static $classMap = array (
'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
);
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit65c59340162793bd027dabb86cb7a03d::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit65c59340162793bd027dabb86cb7a03d::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit65c59340162793bd027dabb86cb7a03d::$classMap;
}, null, ClassLoader::class);
}
}
+513
View File
@@ -0,0 +1,513 @@
{
"packages": [
{
"name": "psr/container",
"version": "2.0.2",
"version_normalized": "2.0.2.0",
"source": {
"type": "git",
"url": "https://github.com/php-fig/container.git",
"reference": "c71ecc56dfe541dbd90c5360474fbc405f8d5963"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/container/zipball/c71ecc56dfe541dbd90c5360474fbc405f8d5963",
"reference": "c71ecc56dfe541dbd90c5360474fbc405f8d5963",
"shasum": ""
},
"require": {
"php": ">=7.4.0"
},
"time": "2021-11-05T16:47:00+00:00",
"published-time": "2021-11-05T16:53:27+00:00",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-4": {
"Psr\\Container\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "https://www.php-fig.org/"
}
],
"description": "Common Container Interface (PHP FIG PSR-11)",
"homepage": "https://github.com/php-fig/container",
"keywords": [
"PSR-11",
"container",
"container-interface",
"container-interop",
"psr"
],
"support": {
"issues": "https://github.com/php-fig/container/issues",
"source": "https://github.com/php-fig/container/tree/2.0.2"
},
"install-path": "../psr/container"
},
{
"name": "psr/http-message",
"version": "2.0",
"version_normalized": "2.0.0.0",
"source": {
"type": "git",
"url": "https://github.com/php-fig/http-message.git",
"reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/http-message/zipball/402d35bcb92c70c026d1a6a9883f06b2ead23d71",
"reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71",
"shasum": ""
},
"require": {
"php": "^7.2 || ^8.0"
},
"time": "2023-04-04T09:54:51+00:00",
"published-time": "2023-04-04T09:55:35+00:00",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-4": {
"Psr\\Http\\Message\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "https://www.php-fig.org/"
}
],
"description": "Common interface for HTTP messages",
"homepage": "https://github.com/php-fig/http-message",
"keywords": [
"http",
"http-message",
"psr",
"psr-7",
"request",
"response"
],
"support": {
"source": "https://github.com/php-fig/http-message/tree/2.0"
},
"install-path": "../psr/http-message"
},
{
"name": "psr/log",
"version": "3.0.2",
"version_normalized": "3.0.2.0",
"source": {
"type": "git",
"url": "https://github.com/php-fig/log.git",
"reference": "f16e1d5863e37f8d8c2a01719f5b34baa2b714d3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/log/zipball/f16e1d5863e37f8d8c2a01719f5b34baa2b714d3",
"reference": "f16e1d5863e37f8d8c2a01719f5b34baa2b714d3",
"shasum": ""
},
"require": {
"php": ">=8.0.0"
},
"time": "2024-09-11T13:17:53+00:00",
"published-time": "2024-09-11T13:21:14+00:00",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.x-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-4": {
"Psr\\Log\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "https://www.php-fig.org/"
}
],
"description": "Common interface for logging libraries",
"homepage": "https://github.com/php-fig/log",
"keywords": [
"log",
"psr",
"psr-3"
],
"support": {
"source": "https://github.com/php-fig/log/tree/3.0.2"
},
"install-path": "../psr/log"
},
{
"name": "psr/simple-cache",
"version": "3.0.0",
"version_normalized": "3.0.0.0",
"source": {
"type": "git",
"url": "https://github.com/php-fig/simple-cache.git",
"reference": "764e0b3939f5ca87cb904f570ef9be2d78a07865"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/simple-cache/zipball/764e0b3939f5ca87cb904f570ef9be2d78a07865",
"reference": "764e0b3939f5ca87cb904f570ef9be2d78a07865",
"shasum": ""
},
"require": {
"php": ">=8.0.0"
},
"time": "2021-10-29T13:26:27+00:00",
"published-time": "2021-10-29T13:27:19+00:00",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.0.x-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-4": {
"Psr\\SimpleCache\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "https://www.php-fig.org/"
}
],
"description": "Common interfaces for simple caching",
"keywords": [
"cache",
"caching",
"psr",
"psr-16",
"simple-cache"
],
"support": {
"source": "https://github.com/php-fig/simple-cache/tree/3.0.0"
},
"install-path": "../psr/simple-cache"
},
{
"name": "topthink/framework",
"version": "v8.1.4",
"version_normalized": "8.1.4.0",
"source": {
"type": "git",
"url": "https://github.com/top-think/framework.git",
"reference": "8e7b2b2364047cbf71a38c4e397a9ca0d4ef2b01"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/top-think/framework/zipball/8e7b2b2364047cbf71a38c4e397a9ca0d4ef2b01",
"reference": "8e7b2b2364047cbf71a38c4e397a9ca0d4ef2b01",
"shasum": ""
},
"require": {
"ext-ctype": "*",
"ext-json": "*",
"ext-mbstring": "*",
"php": ">=8.0.0",
"psr/http-message": "^1.0|^2.0",
"psr/log": "^1.0|^2.0|^3.0",
"psr/simple-cache": "^1.0|^2.0|^3.0",
"topthink/think-container": "^3.0",
"topthink/think-helper": "^3.1",
"topthink/think-orm": "^3.0|^4.0",
"topthink/think-validate": "^3.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.92",
"guzzlehttp/psr7": "^2.1.0",
"mikey179/vfsstream": "^1.6",
"mockery/mockery": "^1.2",
"phpunit/phpunit": "^9.5"
},
"time": "2026-01-15T02:45:10+00:00",
"published-time": "2026-01-16T00:47:38+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
"files": [],
"psr-4": {
"think\\": "src/think/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"authors": [
{
"name": "liu21st",
"email": "liu21st@gmail.com"
},
{
"name": "yunwuxin",
"email": "448901948@qq.com"
}
],
"description": "The ThinkPHP Framework.",
"homepage": "http://thinkphp.cn/",
"keywords": [
"framework",
"orm",
"thinkphp"
],
"support": {
"issues": "https://github.com/top-think/framework/issues",
"source": "https://github.com/top-think/framework/tree/v8.1.4"
},
"install-path": "../topthink/framework"
},
{
"name": "topthink/think-container",
"version": "v3.0.2",
"version_normalized": "3.0.2.0",
"source": {
"type": "git",
"url": "https://github.com/top-think/think-container.git",
"reference": "b2df244be1e7399ad4c8be1ccc40ed57868f730a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/top-think/think-container/zipball/b2df244be1e7399ad4c8be1ccc40ed57868f730a",
"reference": "b2df244be1e7399ad4c8be1ccc40ed57868f730a",
"shasum": ""
},
"require": {
"php": ">=8.0",
"psr/container": "^2.0",
"topthink/think-helper": "^3.1"
},
"require-dev": {
"phpunit/phpunit": "^9.5"
},
"time": "2025-04-07T03:21:51+00:00",
"published-time": "2025-05-06T09:23:28+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
"files": [],
"psr-4": {
"think\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"authors": [
{
"name": "liu21st",
"email": "liu21st@gmail.com"
}
],
"description": "PHP Container & Facade Manager",
"support": {
"issues": "https://github.com/top-think/think-container/issues",
"source": "https://github.com/top-think/think-container/tree/v3.0.2"
},
"install-path": "../topthink/think-container"
},
{
"name": "topthink/think-helper",
"version": "v3.1.12",
"version_normalized": "3.1.12.0",
"source": {
"type": "git",
"url": "https://github.com/top-think/think-helper.git",
"reference": "fe277121112a8f1c872e169a733ca80bb11c4acb"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/top-think/think-helper/zipball/fe277121112a8f1c872e169a733ca80bb11c4acb",
"reference": "fe277121112a8f1c872e169a733ca80bb11c4acb",
"shasum": ""
},
"require": {
"php": ">=7.1.0"
},
"require-dev": {
"phpunit/phpunit": "^9.5"
},
"time": "2025-12-26T09:58:29+00:00",
"published-time": "2025-12-26T10:00:03+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
"files": [
"src/helper.php"
],
"psr-4": {
"think\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"authors": [
{
"name": "yunwuxin",
"email": "448901948@qq.com"
}
],
"description": "The ThinkPHP6 Helper Package",
"support": {
"issues": "https://github.com/top-think/think-helper/issues",
"source": "https://github.com/top-think/think-helper/tree/v3.1.12"
},
"install-path": "../topthink/think-helper"
},
{
"name": "topthink/think-orm",
"version": "v4.0.51",
"version_normalized": "4.0.51.0",
"source": {
"type": "git",
"url": "https://github.com/top-think/think-orm.git",
"reference": "46abe2f824eb3bcb117d4c0ce93b203b592b79f7"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/top-think/think-orm/zipball/46abe2f824eb3bcb117d4c0ce93b203b592b79f7",
"reference": "46abe2f824eb3bcb117d4c0ce93b203b592b79f7",
"shasum": ""
},
"require": {
"ext-json": "*",
"ext-pdo": "*",
"php": ">=8.0.0",
"psr/log": ">=1.0",
"psr/simple-cache": "^3.0",
"topthink/think-helper": "^3.1",
"topthink/think-validate": "^3.0"
},
"require-dev": {
"phpunit/phpunit": "^9.6|^10"
},
"suggest": {
"ext-mongodb": "provide mongodb support"
},
"time": "2025-12-18T13:11:52+00:00",
"published-time": "2026-01-01T12:11:42+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
"files": [
"src/helper.php",
"stubs/load_stubs.php"
],
"psr-4": {
"think\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"authors": [
{
"name": "liu21st",
"email": "liu21st@gmail.com"
}
],
"description": "the PHP Database&ORM Framework",
"keywords": [
"database",
"orm"
],
"support": {
"issues": "https://github.com/top-think/think-orm/issues",
"source": "https://github.com/top-think/think-orm/tree/v4.0.51"
},
"install-path": "../topthink/think-orm"
},
{
"name": "topthink/think-validate",
"version": "v3.0.7",
"version_normalized": "3.0.7.0",
"source": {
"type": "git",
"url": "https://github.com/top-think/think-validate.git",
"reference": "85063f6d4ef8ed122f17a36179dc3e0949b30988"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/top-think/think-validate/zipball/85063f6d4ef8ed122f17a36179dc3e0949b30988",
"reference": "85063f6d4ef8ed122f17a36179dc3e0949b30988",
"shasum": ""
},
"require": {
"php": ">=8.0",
"topthink/think-container": ">=3.0"
},
"time": "2025-06-11T05:51:40+00:00",
"published-time": "2025-06-11T05:53:16+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
"files": [
"src/helper.php"
],
"psr-4": {
"think\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"authors": [
{
"name": "liu21st",
"email": "liu21st@gmail.com"
}
],
"description": "think validate",
"support": {
"issues": "https://github.com/top-think/think-validate/issues",
"source": "https://github.com/top-think/think-validate/tree/v3.0.7"
},
"install-path": "../topthink/think-validate"
}
],
"dev": true,
"dev-package-names": []
}
+104
View File
@@ -0,0 +1,104 @@
<?php return array(
'root' => array(
'name' => 'identity-admin/server',
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'reference' => '85ffda8fd0b1fc8fa03b5229eb7190caa1548f37',
'type' => 'project',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
'dev' => true,
),
'versions' => array(
'identity-admin/server' => array(
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'reference' => '85ffda8fd0b1fc8fa03b5229eb7190caa1548f37',
'type' => 'project',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
'dev_requirement' => false,
),
'psr/container' => array(
'pretty_version' => '2.0.2',
'version' => '2.0.2.0',
'reference' => 'c71ecc56dfe541dbd90c5360474fbc405f8d5963',
'type' => 'library',
'install_path' => __DIR__ . '/../psr/container',
'aliases' => array(),
'dev_requirement' => false,
),
'psr/http-message' => array(
'pretty_version' => '2.0',
'version' => '2.0.0.0',
'reference' => '402d35bcb92c70c026d1a6a9883f06b2ead23d71',
'type' => 'library',
'install_path' => __DIR__ . '/../psr/http-message',
'aliases' => array(),
'dev_requirement' => false,
),
'psr/log' => array(
'pretty_version' => '3.0.2',
'version' => '3.0.2.0',
'reference' => 'f16e1d5863e37f8d8c2a01719f5b34baa2b714d3',
'type' => 'library',
'install_path' => __DIR__ . '/../psr/log',
'aliases' => array(),
'dev_requirement' => false,
),
'psr/simple-cache' => array(
'pretty_version' => '3.0.0',
'version' => '3.0.0.0',
'reference' => '764e0b3939f5ca87cb904f570ef9be2d78a07865',
'type' => 'library',
'install_path' => __DIR__ . '/../psr/simple-cache',
'aliases' => array(),
'dev_requirement' => false,
),
'topthink/framework' => array(
'pretty_version' => 'v8.1.4',
'version' => '8.1.4.0',
'reference' => '8e7b2b2364047cbf71a38c4e397a9ca0d4ef2b01',
'type' => 'library',
'install_path' => __DIR__ . '/../topthink/framework',
'aliases' => array(),
'dev_requirement' => false,
),
'topthink/think-container' => array(
'pretty_version' => 'v3.0.2',
'version' => '3.0.2.0',
'reference' => 'b2df244be1e7399ad4c8be1ccc40ed57868f730a',
'type' => 'library',
'install_path' => __DIR__ . '/../topthink/think-container',
'aliases' => array(),
'dev_requirement' => false,
),
'topthink/think-helper' => array(
'pretty_version' => 'v3.1.12',
'version' => '3.1.12.0',
'reference' => 'fe277121112a8f1c872e169a733ca80bb11c4acb',
'type' => 'library',
'install_path' => __DIR__ . '/../topthink/think-helper',
'aliases' => array(),
'dev_requirement' => false,
),
'topthink/think-orm' => array(
'pretty_version' => 'v4.0.51',
'version' => '4.0.51.0',
'reference' => '46abe2f824eb3bcb117d4c0ce93b203b592b79f7',
'type' => 'library',
'install_path' => __DIR__ . '/../topthink/think-orm',
'aliases' => array(),
'dev_requirement' => false,
),
'topthink/think-validate' => array(
'pretty_version' => 'v3.0.7',
'version' => '3.0.7.0',
'reference' => '85063f6d4ef8ed122f17a36179dc3e0949b30988',
'type' => 'library',
'install_path' => __DIR__ . '/../topthink/think-validate',
'aliases' => array(),
'dev_requirement' => false,
),
),
);
@@ -0,0 +1,25 @@
<?php
// platform_check.php @generated by Composer
$issues = array();
if (!(PHP_VERSION_ID >= 80200)) {
$issues[] = 'Your Composer dependencies require a PHP version ">= 8.2.0". You are running ' . PHP_VERSION . '.';
}
if ($issues) {
if (!headers_sent()) {
header('HTTP/1.1 500 Internal Server Error');
}
if (!ini_get('display_errors')) {
if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
fwrite(STDERR, 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . implode(PHP_EOL, $issues) . PHP_EOL.PHP_EOL);
} elseif (!headers_sent()) {
echo 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . str_replace('You are running '.PHP_VERSION.'.', '', implode(PHP_EOL, $issues)) . PHP_EOL.PHP_EOL;
}
}
throw new \RuntimeException(
'Composer detected issues in your platform: ' . implode(' ', $issues)
);
}
@@ -0,0 +1,3 @@
composer.lock
composer.phar
/vendor/
+21
View File
@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2013-2016 container-interop
Copyright (c) 2016 PHP Framework Interoperability Group
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+13
View File
@@ -0,0 +1,13 @@
Container interface
==============
This repository holds all interfaces related to [PSR-11 (Container Interface)][psr-url].
Note that this is not a Container implementation of its own. It is merely abstractions that describe the components of a Dependency Injection Container.
The installable [package][package-url] and [implementations][implementation-url] are listed on Packagist.
[psr-url]: https://www.php-fig.org/psr/psr-11/
[package-url]: https://packagist.org/packages/psr/container
[implementation-url]: https://packagist.org/providers/psr/container-implementation
@@ -0,0 +1,27 @@
{
"name": "psr/container",
"type": "library",
"description": "Common Container Interface (PHP FIG PSR-11)",
"keywords": ["psr", "psr-11", "container", "container-interop", "container-interface"],
"homepage": "https://github.com/php-fig/container",
"license": "MIT",
"authors": [
{
"name": "PHP-FIG",
"homepage": "https://www.php-fig.org/"
}
],
"require": {
"php": ">=7.4.0"
},
"autoload": {
"psr-4": {
"Psr\\Container\\": "src/"
}
},
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
}
}
}
@@ -0,0 +1,12 @@
<?php
namespace Psr\Container;
use Throwable;
/**
* Base interface representing a generic exception in a container.
*/
interface ContainerExceptionInterface extends Throwable
{
}
@@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
namespace Psr\Container;
/**
* Describes the interface of a container that exposes methods to read its entries.
*/
interface ContainerInterface
{
/**
* Finds an entry of the container by its identifier and returns it.
*
* @param string $id Identifier of the entry to look for.
*
* @throws NotFoundExceptionInterface No entry was found for **this** identifier.
* @throws ContainerExceptionInterface Error while retrieving the entry.
*
* @return mixed Entry.
*/
public function get(string $id);
/**
* Returns true if the container can return an entry for the given identifier.
* Returns false otherwise.
*
* `has($id)` returning true does not mean that `get($id)` will not throw an exception.
* It does however mean that `get($id)` will not throw a `NotFoundExceptionInterface`.
*
* @param string $id Identifier of the entry to look for.
*
* @return bool
*/
public function has(string $id): bool;
}
@@ -0,0 +1,10 @@
<?php
namespace Psr\Container;
/**
* No entry was found in the container.
*/
interface NotFoundExceptionInterface extends ContainerExceptionInterface
{
}
@@ -0,0 +1,36 @@
# Changelog
All notable changes to this project will be documented in this file, in reverse chronological order by release.
## 1.0.1 - 2016-08-06
### Added
- Nothing.
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- Updated all `@return self` annotation references in interfaces to use
`@return static`, which more closelly follows the semantics of the
specification.
- Updated the `MessageInterface::getHeaders()` return annotation to use the
value `string[][]`, indicating the format is a nested array of strings.
- Updated the `@link` annotation for `RequestInterface::withRequestTarget()`
to point to the correct section of RFC 7230.
- Updated the `ServerRequestInterface::withUploadedFiles()` parameter annotation
to add the parameter name (`$uploadedFiles`).
- Updated a `@throws` annotation for the `UploadedFileInterface::moveTo()`
method to correctly reference the method parameter (it was referencing an
incorrect parameter name previously).
## 1.0.0 - 2016-05-18
Initial stable release; reflects accepted PSR-7 specification.
+19
View File
@@ -0,0 +1,19 @@
Copyright (c) 2014 PHP Framework Interoperability Group
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
+16
View File
@@ -0,0 +1,16 @@
PSR Http Message
================
This repository holds all interfaces/classes/traits related to
[PSR-7](http://www.php-fig.org/psr/psr-7/).
Note that this is not a HTTP message implementation of its own. It is merely an
interface that describes a HTTP message. See the specification for more details.
Usage
-----
Before reading the usage guide we recommend reading the PSR-7 interfaces method list:
* [`PSR-7 Interfaces Method List`](docs/PSR7-Interfaces.md)
* [`PSR-7 Usage Guide`](docs/PSR7-Usage.md)
@@ -0,0 +1,26 @@
{
"name": "psr/http-message",
"description": "Common interface for HTTP messages",
"keywords": ["psr", "psr-7", "http", "http-message", "request", "response"],
"homepage": "https://github.com/php-fig/http-message",
"license": "MIT",
"authors": [
{
"name": "PHP-FIG",
"homepage": "https://www.php-fig.org/"
}
],
"require": {
"php": "^7.2 || ^8.0"
},
"autoload": {
"psr-4": {
"Psr\\Http\\Message\\": "src/"
}
},
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
}
}
}
@@ -0,0 +1,130 @@
# Interfaces
The purpose of this list is to help in finding the methods when working with PSR-7. This can be considered as a cheatsheet for PSR-7 interfaces.
The interfaces defined in PSR-7 are the following:
| Class Name | Description |
|---|---|
| [Psr\Http\Message\MessageInterface](http://www.php-fig.org/psr/psr-7/#psrhttpmessagemessageinterface) | Representation of a HTTP message |
| [Psr\Http\Message\RequestInterface](http://www.php-fig.org/psr/psr-7/#psrhttpmessagerequestinterface) | Representation of an outgoing, client-side request. |
| [Psr\Http\Message\ServerRequestInterface](http://www.php-fig.org/psr/psr-7/#psrhttpmessageserverrequestinterface) | Representation of an incoming, server-side HTTP request. |
| [Psr\Http\Message\ResponseInterface](http://www.php-fig.org/psr/psr-7/#psrhttpmessageresponseinterface) | Representation of an outgoing, server-side response. |
| [Psr\Http\Message\StreamInterface](http://www.php-fig.org/psr/psr-7/#psrhttpmessagestreaminterface) | Describes a data stream |
| [Psr\Http\Message\UriInterface](http://www.php-fig.org/psr/psr-7/#psrhttpmessageuriinterface) | Value object representing a URI. |
| [Psr\Http\Message\UploadedFileInterface](http://www.php-fig.org/psr/psr-7/#psrhttpmessageuploadedfileinterface) | Value object representing a file uploaded through an HTTP request. |
## `Psr\Http\Message\MessageInterface` Methods
| Method Name | Description | Notes |
|------------------------------------| ----------- | ----- |
| `getProtocolVersion()` | Retrieve HTTP protocol version | 1.0 or 1.1 |
| `withProtocolVersion($version)` | Returns new message instance with given HTTP protocol version | |
| `getHeaders()` | Retrieve all HTTP Headers | [Request Header List](https://en.wikipedia.org/wiki/List_of_HTTP_header_fields#Request_fields), [Response Header List](https://en.wikipedia.org/wiki/List_of_HTTP_header_fields#Response_fields) |
| `hasHeader($name)` | Checks if HTTP Header with given name exists | |
| `getHeader($name)` | Retrieves a array with the values for a single header | |
| `getHeaderLine($name)` | Retrieves a comma-separated string of the values for a single header | |
| `withHeader($name, $value)` | Returns new message instance with given HTTP Header | if the header existed in the original instance, replaces the header value from the original message with the value provided when creating the new instance. |
| `withAddedHeader($name, $value)` | Returns new message instance with appended value to given header | If header already exists value will be appended, if not a new header will be created |
| `withoutHeader($name)` | Removes HTTP Header with given name| |
| `getBody()` | Retrieves the HTTP Message Body | Returns object implementing `StreamInterface`|
| `withBody(StreamInterface $body)` | Returns new message instance with given HTTP Message Body | |
## `Psr\Http\Message\RequestInterface` Methods
Same methods as `Psr\Http\Message\MessageInterface` + the following methods:
| Method Name | Description | Notes |
|------------------------------------| ----------- | ----- |
| `getRequestTarget()` | Retrieves the message's request target | origin-form, absolute-form, authority-form, asterisk-form ([RFC7230](https://www.rfc-editor.org/rfc/rfc7230.txt)) |
| `withRequestTarget($requestTarget)` | Return a new message instance with the specific request-target | |
| `getMethod()` | Retrieves the HTTP method of the request. | GET, HEAD, POST, PUT, DELETE, CONNECT, OPTIONS, TRACE (defined in [RFC7231](https://tools.ietf.org/html/rfc7231)), PATCH (defined in [RFC5789](https://tools.ietf.org/html/rfc5789)) |
| `withMethod($method)` | Returns a new message instance with the provided HTTP method | |
| `getUri()` | Retrieves the URI instance | |
| `withUri(UriInterface $uri, $preserveHost = false)` | Returns a new message instance with the provided URI | |
## `Psr\Http\Message\ServerRequestInterface` Methods
Same methods as `Psr\Http\Message\RequestInterface` + the following methods:
| Method Name | Description | Notes |
|------------------------------------| ----------- | ----- |
| `getServerParams() ` | Retrieve server parameters | Typically derived from `$_SERVER` |
| `getCookieParams()` | Retrieves cookies sent by the client to the server. | Typically derived from `$_COOKIES` |
| `withCookieParams(array $cookies)` | Returns a new request instance with the specified cookies | |
| `withQueryParams(array $query)` | Returns a new request instance with the specified query string arguments | |
| `getUploadedFiles()` | Retrieve normalized file upload data | |
| `withUploadedFiles(array $uploadedFiles)` | Returns a new request instance with the specified uploaded files | |
| `getParsedBody()` | Retrieve any parameters provided in the request body | |
| `withParsedBody($data)` | Returns a new request instance with the specified body parameters | |
| `getAttributes()` | Retrieve attributes derived from the request | |
| `getAttribute($name, $default = null)` | Retrieve a single derived request attribute | |
| `withAttribute($name, $value)` | Returns a new request instance with the specified derived request attribute | |
| `withoutAttribute($name)` | Returns a new request instance that without the specified derived request attribute | |
## `Psr\Http\Message\ResponseInterface` Methods:
Same methods as `Psr\Http\Message\MessageInterface` + the following methods:
| Method Name | Description | Notes |
|------------------------------------| ----------- | ----- |
| `getStatusCode()` | Gets the response status code. | |
| `withStatus($code, $reasonPhrase = '')` | Returns a new response instance with the specified status code and, optionally, reason phrase. | |
| `getReasonPhrase()` | Gets the response reason phrase associated with the status code. | |
## `Psr\Http\Message\StreamInterface` Methods
| Method Name | Description | Notes |
|------------------------------------| ----------- | ----- |
| `__toString()` | Reads all data from the stream into a string, from the beginning to end. | |
| `close()` | Closes the stream and any underlying resources. | |
| `detach()` | Separates any underlying resources from the stream. | |
| `getSize()` | Get the size of the stream if known. | |
| `eof()` | Returns true if the stream is at the end of the stream.| |
| `isSeekable()` | Returns whether or not the stream is seekable. | |
| `seek($offset, $whence = SEEK_SET)` | Seek to a position in the stream. | |
| `rewind()` | Seek to the beginning of the stream. | |
| `isWritable()` | Returns whether or not the stream is writable. | |
| `write($string)` | Write data to the stream. | |
| `isReadable()` | Returns whether or not the stream is readable. | |
| `read($length)` | Read data from the stream. | |
| `getContents()` | Returns the remaining contents in a string | |
| `getMetadata($key = null)()` | Get stream metadata as an associative array or retrieve a specific key. | |
## `Psr\Http\Message\UriInterface` Methods
| Method Name | Description | Notes |
|------------------------------------| ----------- | ----- |
| `getScheme()` | Retrieve the scheme component of the URI. | |
| `getAuthority()` | Retrieve the authority component of the URI. | |
| `getUserInfo()` | Retrieve the user information component of the URI. | |
| `getHost()` | Retrieve the host component of the URI. | |
| `getPort()` | Retrieve the port component of the URI. | |
| `getPath()` | Retrieve the path component of the URI. | |
| `getQuery()` | Retrieve the query string of the URI. | |
| `getFragment()` | Retrieve the fragment component of the URI. | |
| `withScheme($scheme)` | Return an instance with the specified scheme. | |
| `withUserInfo($user, $password = null)` | Return an instance with the specified user information. | |
| `withHost($host)` | Return an instance with the specified host. | |
| `withPort($port)` | Return an instance with the specified port. | |
| `withPath($path)` | Return an instance with the specified path. | |
| `withQuery($query)` | Return an instance with the specified query string. | |
| `withFragment($fragment)` | Return an instance with the specified URI fragment. | |
| `__toString()` | Return the string representation as a URI reference. | |
## `Psr\Http\Message\UploadedFileInterface` Methods
| Method Name | Description | Notes |
|------------------------------------| ----------- | ----- |
| `getStream()` | Retrieve a stream representing the uploaded file. | |
| `moveTo($targetPath)` | Move the uploaded file to a new location. | |
| `getSize()` | Retrieve the file size. | |
| `getError()` | Retrieve the error associated with the uploaded file. | |
| `getClientFilename()` | Retrieve the filename sent by the client. | |
| `getClientMediaType()` | Retrieve the media type sent by the client. | |
> `RequestInterface`, `ServerRequestInterface`, `ResponseInterface` extend `MessageInterface` because the `Request` and the `Response` are `HTTP Messages`.
> When using `ServerRequestInterface`, both `RequestInterface` and `Psr\Http\Message\MessageInterface` methods are considered.
@@ -0,0 +1,159 @@
### PSR-7 Usage
All PSR-7 applications comply with these interfaces
They were created to establish a standard between middleware implementations.
> `RequestInterface`, `ServerRequestInterface`, `ResponseInterface` extend `MessageInterface` because the `Request` and the `Response` are `HTTP Messages`.
> When using `ServerRequestInterface`, both `RequestInterface` and `Psr\Http\Message\MessageInterface` methods are considered.
The following examples will illustrate how basic operations are done in PSR-7.
##### Examples
For this examples to work (at least) a PSR-7 implementation package is required. (eg: zendframework/zend-diactoros, guzzlehttp/psr7, slim/slim, etc)
All PSR-7 implementations should have the same behaviour.
The following will be assumed:
`$request` is an object of `Psr\Http\Message\RequestInterface` and
`$response` is an object implementing `Psr\Http\Message\RequestInterface`
### Working with HTTP Headers
#### Adding headers to response:
```php
$response->withHeader('My-Custom-Header', 'My Custom Message');
```
#### Appending values to headers
```php
$response->withAddedHeader('My-Custom-Header', 'The second message');
```
#### Checking if header exists:
```php
$request->hasHeader('My-Custom-Header'); // will return false
$response->hasHeader('My-Custom-Header'); // will return true
```
> Note: My-Custom-Header was only added in the Response
#### Getting comma-separated values from a header (also applies to request)
```php
// getting value from request headers
$request->getHeaderLine('Content-Type'); // will return: "text/html; charset=UTF-8"
// getting value from response headers
$response->getHeaderLine('My-Custom-Header'); // will return: "My Custom Message; The second message"
```
#### Getting array of value from a header (also applies to request)
```php
// getting value from request headers
$request->getHeader('Content-Type'); // will return: ["text/html", "charset=UTF-8"]
// getting value from response headers
$response->getHeader('My-Custom-Header'); // will return: ["My Custom Message", "The second message"]
```
#### Removing headers from HTTP Messages
```php
// removing a header from Request, removing deprecated "Content-MD5" header
$request->withoutHeader('Content-MD5');
// removing a header from Response
// effect: the browser won't know the size of the stream
// the browser will download the stream till it ends
$response->withoutHeader('Content-Length');
```
### Working with HTTP Message Body
When working with the PSR-7 there are two methods of implementation:
#### 1. Getting the body separately
> This method makes the body handling easier to understand and is useful when repeatedly calling body methods. (You only call `getBody()` once). Using this method mistakes like `$response->write()` are also prevented.
```php
$body = $response->getBody();
// operations on body, eg. read, write, seek
// ...
// replacing the old body
$response->withBody($body);
// this last statement is optional as we working with objects
// in this case the "new" body is same with the "old" one
// the $body variable has the same value as the one in $request, only the reference is passed
```
#### 2. Working directly on response
> This method is useful when only performing few operations as the `$request->getBody()` statement fragment is required
```php
$response->getBody()->write('hello');
```
### Getting the body contents
The following snippet gets the contents of a stream contents.
> Note: Streams must be rewinded, if content was written into streams, it will be ignored when calling `getContents()` because the stream pointer is set to the last character, which is `\0` - meaning end of stream.
```php
$body = $response->getBody();
$body->rewind(); // or $body->seek(0);
$bodyText = $body->getContents();
```
> Note: If `$body->seek(1)` is called before `$body->getContents()`, the first character will be ommited as the starting pointer is set to `1`, not `0`. This is why using `$body->rewind()` is recommended.
### Append to body
```php
$response->getBody()->write('Hello'); // writing directly
$body = $request->getBody(); // which is a `StreamInterface`
$body->write('xxxxx');
```
### Prepend to body
Prepending is different when it comes to streams. The content must be copied before writing the content to be prepended.
The following example will explain the behaviour of streams.
```php
// assuming our response is initially empty
$body = $repsonse->getBody();
// writing the string "abcd"
$body->write('abcd');
// seeking to start of stream
$body->seek(0);
// writing 'ef'
$body->write('ef'); // at this point the stream contains "efcd"
```
#### Prepending by rewriting separately
```php
// assuming our response body stream only contains: "abcd"
$body = $response->getBody();
$body->rewind();
$contents = $body->getContents(); // abcd
// seeking the stream to beginning
$body->rewind();
$body->write('ef'); // stream contains "efcd"
$body->write($contents); // stream contains "efabcd"
```
> Note: `getContents()` seeks the stream while reading it, therefore if the second `rewind()` method call was not present the stream would have resulted in `abcdefabcd` because the `write()` method appends to stream if not preceeded by `rewind()` or `seek(0)`.
#### Prepending by using contents as a string
```php
$body = $response->getBody();
$body->rewind();
$contents = $body->getContents(); // efabcd
$contents = 'ef'.$contents;
$body->rewind();
$body->write($contents);
```
@@ -0,0 +1,187 @@
<?php
namespace Psr\Http\Message;
/**
* HTTP messages consist of requests from a client to a server and responses
* from a server to a client. This interface defines the methods common to
* each.
*
* Messages are considered immutable; all methods that might change state MUST
* be implemented such that they retain the internal state of the current
* message and return an instance that contains the changed state.
*
* @link http://www.ietf.org/rfc/rfc7230.txt
* @link http://www.ietf.org/rfc/rfc7231.txt
*/
interface MessageInterface
{
/**
* Retrieves the HTTP protocol version as a string.
*
* The string MUST contain only the HTTP version number (e.g., "1.1", "1.0").
*
* @return string HTTP protocol version.
*/
public function getProtocolVersion(): string;
/**
* Return an instance with the specified HTTP protocol version.
*
* The version string MUST contain only the HTTP version number (e.g.,
* "1.1", "1.0").
*
* This method MUST be implemented in such a way as to retain the
* immutability of the message, and MUST return an instance that has the
* new protocol version.
*
* @param string $version HTTP protocol version
* @return static
*/
public function withProtocolVersion(string $version): MessageInterface;
/**
* Retrieves all message header values.
*
* The keys represent the header name as it will be sent over the wire, and
* each value is an array of strings associated with the header.
*
* // Represent the headers as a string
* foreach ($message->getHeaders() as $name => $values) {
* echo $name . ": " . implode(", ", $values);
* }
*
* // Emit headers iteratively:
* foreach ($message->getHeaders() as $name => $values) {
* foreach ($values as $value) {
* header(sprintf('%s: %s', $name, $value), false);
* }
* }
*
* While header names are not case-sensitive, getHeaders() will preserve the
* exact case in which headers were originally specified.
*
* @return string[][] Returns an associative array of the message's headers. Each
* key MUST be a header name, and each value MUST be an array of strings
* for that header.
*/
public function getHeaders(): array;
/**
* Checks if a header exists by the given case-insensitive name.
*
* @param string $name Case-insensitive header field name.
* @return bool Returns true if any header names match the given header
* name using a case-insensitive string comparison. Returns false if
* no matching header name is found in the message.
*/
public function hasHeader(string $name): bool;
/**
* Retrieves a message header value by the given case-insensitive name.
*
* This method returns an array of all the header values of the given
* case-insensitive header name.
*
* If the header does not appear in the message, this method MUST return an
* empty array.
*
* @param string $name Case-insensitive header field name.
* @return string[] An array of string values as provided for the given
* header. If the header does not appear in the message, this method MUST
* return an empty array.
*/
public function getHeader(string $name): array;
/**
* Retrieves a comma-separated string of the values for a single header.
*
* This method returns all of the header values of the given
* case-insensitive header name as a string concatenated together using
* a comma.
*
* NOTE: Not all header values may be appropriately represented using
* comma concatenation. For such headers, use getHeader() instead
* and supply your own delimiter when concatenating.
*
* If the header does not appear in the message, this method MUST return
* an empty string.
*
* @param string $name Case-insensitive header field name.
* @return string A string of values as provided for the given header
* concatenated together using a comma. If the header does not appear in
* the message, this method MUST return an empty string.
*/
public function getHeaderLine(string $name): string;
/**
* Return an instance with the provided value replacing the specified header.
*
* While header names are case-insensitive, the casing of the header will
* be preserved by this function, and returned from getHeaders().
*
* This method MUST be implemented in such a way as to retain the
* immutability of the message, and MUST return an instance that has the
* new and/or updated header and value.
*
* @param string $name Case-insensitive header field name.
* @param string|string[] $value Header value(s).
* @return static
* @throws \InvalidArgumentException for invalid header names or values.
*/
public function withHeader(string $name, $value): MessageInterface;
/**
* Return an instance with the specified header appended with the given value.
*
* Existing values for the specified header will be maintained. The new
* value(s) will be appended to the existing list. If the header did not
* exist previously, it will be added.
*
* This method MUST be implemented in such a way as to retain the
* immutability of the message, and MUST return an instance that has the
* new header and/or value.
*
* @param string $name Case-insensitive header field name to add.
* @param string|string[] $value Header value(s).
* @return static
* @throws \InvalidArgumentException for invalid header names or values.
*/
public function withAddedHeader(string $name, $value): MessageInterface;
/**
* Return an instance without the specified header.
*
* Header resolution MUST be done without case-sensitivity.
*
* This method MUST be implemented in such a way as to retain the
* immutability of the message, and MUST return an instance that removes
* the named header.
*
* @param string $name Case-insensitive header field name to remove.
* @return static
*/
public function withoutHeader(string $name): MessageInterface;
/**
* Gets the body of the message.
*
* @return StreamInterface Returns the body as a stream.
*/
public function getBody(): StreamInterface;
/**
* Return an instance with the specified message body.
*
* The body MUST be a StreamInterface object.
*
* This method MUST be implemented in such a way as to retain the
* immutability of the message, and MUST return a new instance that has the
* new body stream.
*
* @param StreamInterface $body Body.
* @return static
* @throws \InvalidArgumentException When the body is not valid.
*/
public function withBody(StreamInterface $body): MessageInterface;
}
@@ -0,0 +1,130 @@
<?php
namespace Psr\Http\Message;
/**
* Representation of an outgoing, client-side request.
*
* Per the HTTP specification, this interface includes properties for
* each of the following:
*
* - Protocol version
* - HTTP method
* - URI
* - Headers
* - Message body
*
* During construction, implementations MUST attempt to set the Host header from
* a provided URI if no Host header is provided.
*
* Requests are considered immutable; all methods that might change state MUST
* be implemented such that they retain the internal state of the current
* message and return an instance that contains the changed state.
*/
interface RequestInterface extends MessageInterface
{
/**
* Retrieves the message's request target.
*
* Retrieves the message's request-target either as it will appear (for
* clients), as it appeared at request (for servers), or as it was
* specified for the instance (see withRequestTarget()).
*
* In most cases, this will be the origin-form of the composed URI,
* unless a value was provided to the concrete implementation (see
* withRequestTarget() below).
*
* If no URI is available, and no request-target has been specifically
* provided, this method MUST return the string "/".
*
* @return string
*/
public function getRequestTarget(): string;
/**
* Return an instance with the specific request-target.
*
* If the request needs a non-origin-form request-target — e.g., for
* specifying an absolute-form, authority-form, or asterisk-form —
* this method may be used to create an instance with the specified
* request-target, verbatim.
*
* This method MUST be implemented in such a way as to retain the
* immutability of the message, and MUST return an instance that has the
* changed request target.
*
* @link http://tools.ietf.org/html/rfc7230#section-5.3 (for the various
* request-target forms allowed in request messages)
* @param string $requestTarget
* @return static
*/
public function withRequestTarget(string $requestTarget): RequestInterface;
/**
* Retrieves the HTTP method of the request.
*
* @return string Returns the request method.
*/
public function getMethod(): string;
/**
* Return an instance with the provided HTTP method.
*
* While HTTP method names are typically all uppercase characters, HTTP
* method names are case-sensitive and thus implementations SHOULD NOT
* modify the given string.
*
* This method MUST be implemented in such a way as to retain the
* immutability of the message, and MUST return an instance that has the
* changed request method.
*
* @param string $method Case-sensitive method.
* @return static
* @throws \InvalidArgumentException for invalid HTTP methods.
*/
public function withMethod(string $method): RequestInterface;
/**
* Retrieves the URI instance.
*
* This method MUST return a UriInterface instance.
*
* @link http://tools.ietf.org/html/rfc3986#section-4.3
* @return UriInterface Returns a UriInterface instance
* representing the URI of the request.
*/
public function getUri(): UriInterface;
/**
* Returns an instance with the provided URI.
*
* This method MUST update the Host header of the returned request by
* default if the URI contains a host component. If the URI does not
* contain a host component, any pre-existing Host header MUST be carried
* over to the returned request.
*
* You can opt-in to preserving the original state of the Host header by
* setting `$preserveHost` to `true`. When `$preserveHost` is set to
* `true`, this method interacts with the Host header in the following ways:
*
* - If the Host header is missing or empty, and the new URI contains
* a host component, this method MUST update the Host header in the returned
* request.
* - If the Host header is missing or empty, and the new URI does not contain a
* host component, this method MUST NOT update the Host header in the returned
* request.
* - If a Host header is present and non-empty, this method MUST NOT update
* the Host header in the returned request.
*
* This method MUST be implemented in such a way as to retain the
* immutability of the message, and MUST return an instance that has the
* new UriInterface instance.
*
* @link http://tools.ietf.org/html/rfc3986#section-4.3
* @param UriInterface $uri New request URI to use.
* @param bool $preserveHost Preserve the original state of the Host header.
* @return static
*/
public function withUri(UriInterface $uri, bool $preserveHost = false): RequestInterface;
}
@@ -0,0 +1,68 @@
<?php
namespace Psr\Http\Message;
/**
* Representation of an outgoing, server-side response.
*
* Per the HTTP specification, this interface includes properties for
* each of the following:
*
* - Protocol version
* - Status code and reason phrase
* - Headers
* - Message body
*
* Responses are considered immutable; all methods that might change state MUST
* be implemented such that they retain the internal state of the current
* message and return an instance that contains the changed state.
*/
interface ResponseInterface extends MessageInterface
{
/**
* Gets the response status code.
*
* The status code is a 3-digit integer result code of the server's attempt
* to understand and satisfy the request.
*
* @return int Status code.
*/
public function getStatusCode(): int;
/**
* Return an instance with the specified status code and, optionally, reason phrase.
*
* If no reason phrase is specified, implementations MAY choose to default
* to the RFC 7231 or IANA recommended reason phrase for the response's
* status code.
*
* This method MUST be implemented in such a way as to retain the
* immutability of the message, and MUST return an instance that has the
* updated status and reason phrase.
*
* @link http://tools.ietf.org/html/rfc7231#section-6
* @link http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
* @param int $code The 3-digit integer result code to set.
* @param string $reasonPhrase The reason phrase to use with the
* provided status code; if none is provided, implementations MAY
* use the defaults as suggested in the HTTP specification.
* @return static
* @throws \InvalidArgumentException For invalid status code arguments.
*/
public function withStatus(int $code, string $reasonPhrase = ''): ResponseInterface;
/**
* Gets the response reason phrase associated with the status code.
*
* Because a reason phrase is not a required element in a response
* status line, the reason phrase value MAY be null. Implementations MAY
* choose to return the default RFC 7231 recommended reason phrase (or those
* listed in the IANA HTTP Status Code Registry) for the response's
* status code.
*
* @link http://tools.ietf.org/html/rfc7231#section-6
* @link http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
* @return string Reason phrase; must return an empty string if none present.
*/
public function getReasonPhrase(): string;
}
@@ -0,0 +1,261 @@
<?php
namespace Psr\Http\Message;
/**
* Representation of an incoming, server-side HTTP request.
*
* Per the HTTP specification, this interface includes properties for
* each of the following:
*
* - Protocol version
* - HTTP method
* - URI
* - Headers
* - Message body
*
* Additionally, it encapsulates all data as it has arrived to the
* application from the CGI and/or PHP environment, including:
*
* - The values represented in $_SERVER.
* - Any cookies provided (generally via $_COOKIE)
* - Query string arguments (generally via $_GET, or as parsed via parse_str())
* - Upload files, if any (as represented by $_FILES)
* - Deserialized body parameters (generally from $_POST)
*
* $_SERVER values MUST be treated as immutable, as they represent application
* state at the time of request; as such, no methods are provided to allow
* modification of those values. The other values provide such methods, as they
* can be restored from $_SERVER or the request body, and may need treatment
* during the application (e.g., body parameters may be deserialized based on
* content type).
*
* Additionally, this interface recognizes the utility of introspecting a
* request to derive and match additional parameters (e.g., via URI path
* matching, decrypting cookie values, deserializing non-form-encoded body
* content, matching authorization headers to users, etc). These parameters
* are stored in an "attributes" property.
*
* Requests are considered immutable; all methods that might change state MUST
* be implemented such that they retain the internal state of the current
* message and return an instance that contains the changed state.
*/
interface ServerRequestInterface extends RequestInterface
{
/**
* Retrieve server parameters.
*
* Retrieves data related to the incoming request environment,
* typically derived from PHP's $_SERVER superglobal. The data IS NOT
* REQUIRED to originate from $_SERVER.
*
* @return array
*/
public function getServerParams(): array;
/**
* Retrieve cookies.
*
* Retrieves cookies sent by the client to the server.
*
* The data MUST be compatible with the structure of the $_COOKIE
* superglobal.
*
* @return array
*/
public function getCookieParams(): array;
/**
* Return an instance with the specified cookies.
*
* The data IS NOT REQUIRED to come from the $_COOKIE superglobal, but MUST
* be compatible with the structure of $_COOKIE. Typically, this data will
* be injected at instantiation.
*
* This method MUST NOT update the related Cookie header of the request
* instance, nor related values in the server params.
*
* This method MUST be implemented in such a way as to retain the
* immutability of the message, and MUST return an instance that has the
* updated cookie values.
*
* @param array $cookies Array of key/value pairs representing cookies.
* @return static
*/
public function withCookieParams(array $cookies): ServerRequestInterface;
/**
* Retrieve query string arguments.
*
* Retrieves the deserialized query string arguments, if any.
*
* Note: the query params might not be in sync with the URI or server
* params. If you need to ensure you are only getting the original
* values, you may need to parse the query string from `getUri()->getQuery()`
* or from the `QUERY_STRING` server param.
*
* @return array
*/
public function getQueryParams(): array;
/**
* Return an instance with the specified query string arguments.
*
* These values SHOULD remain immutable over the course of the incoming
* request. They MAY be injected during instantiation, such as from PHP's
* $_GET superglobal, or MAY be derived from some other value such as the
* URI. In cases where the arguments are parsed from the URI, the data
* MUST be compatible with what PHP's parse_str() would return for
* purposes of how duplicate query parameters are handled, and how nested
* sets are handled.
*
* Setting query string arguments MUST NOT change the URI stored by the
* request, nor the values in the server params.
*
* This method MUST be implemented in such a way as to retain the
* immutability of the message, and MUST return an instance that has the
* updated query string arguments.
*
* @param array $query Array of query string arguments, typically from
* $_GET.
* @return static
*/
public function withQueryParams(array $query): ServerRequestInterface;
/**
* Retrieve normalized file upload data.
*
* This method returns upload metadata in a normalized tree, with each leaf
* an instance of Psr\Http\Message\UploadedFileInterface.
*
* These values MAY be prepared from $_FILES or the message body during
* instantiation, or MAY be injected via withUploadedFiles().
*
* @return array An array tree of UploadedFileInterface instances; an empty
* array MUST be returned if no data is present.
*/
public function getUploadedFiles(): array;
/**
* Create a new instance with the specified uploaded files.
*
* This method MUST be implemented in such a way as to retain the
* immutability of the message, and MUST return an instance that has the
* updated body parameters.
*
* @param array $uploadedFiles An array tree of UploadedFileInterface instances.
* @return static
* @throws \InvalidArgumentException if an invalid structure is provided.
*/
public function withUploadedFiles(array $uploadedFiles): ServerRequestInterface;
/**
* Retrieve any parameters provided in the request body.
*
* If the request Content-Type is either application/x-www-form-urlencoded
* or multipart/form-data, and the request method is POST, this method MUST
* return the contents of $_POST.
*
* Otherwise, this method may return any results of deserializing
* the request body content; as parsing returns structured content, the
* potential types MUST be arrays or objects only. A null value indicates
* the absence of body content.
*
* @return null|array|object The deserialized body parameters, if any.
* These will typically be an array or object.
*/
public function getParsedBody();
/**
* Return an instance with the specified body parameters.
*
* These MAY be injected during instantiation.
*
* If the request Content-Type is either application/x-www-form-urlencoded
* or multipart/form-data, and the request method is POST, use this method
* ONLY to inject the contents of $_POST.
*
* The data IS NOT REQUIRED to come from $_POST, but MUST be the results of
* deserializing the request body content. Deserialization/parsing returns
* structured data, and, as such, this method ONLY accepts arrays or objects,
* or a null value if nothing was available to parse.
*
* As an example, if content negotiation determines that the request data
* is a JSON payload, this method could be used to create a request
* instance with the deserialized parameters.
*
* This method MUST be implemented in such a way as to retain the
* immutability of the message, and MUST return an instance that has the
* updated body parameters.
*
* @param null|array|object $data The deserialized body data. This will
* typically be in an array or object.
* @return static
* @throws \InvalidArgumentException if an unsupported argument type is
* provided.
*/
public function withParsedBody($data): ServerRequestInterface;
/**
* Retrieve attributes derived from the request.
*
* The request "attributes" may be used to allow injection of any
* parameters derived from the request: e.g., the results of path
* match operations; the results of decrypting cookies; the results of
* deserializing non-form-encoded message bodies; etc. Attributes
* will be application and request specific, and CAN be mutable.
*
* @return array Attributes derived from the request.
*/
public function getAttributes(): array;
/**
* Retrieve a single derived request attribute.
*
* Retrieves a single derived request attribute as described in
* getAttributes(). If the attribute has not been previously set, returns
* the default value as provided.
*
* This method obviates the need for a hasAttribute() method, as it allows
* specifying a default value to return if the attribute is not found.
*
* @see getAttributes()
* @param string $name The attribute name.
* @param mixed $default Default value to return if the attribute does not exist.
* @return mixed
*/
public function getAttribute(string $name, $default = null);
/**
* Return an instance with the specified derived request attribute.
*
* This method allows setting a single derived request attribute as
* described in getAttributes().
*
* This method MUST be implemented in such a way as to retain the
* immutability of the message, and MUST return an instance that has the
* updated attribute.
*
* @see getAttributes()
* @param string $name The attribute name.
* @param mixed $value The value of the attribute.
* @return static
*/
public function withAttribute(string $name, $value): ServerRequestInterface;
/**
* Return an instance that removes the specified derived request attribute.
*
* This method allows removing a single derived request attribute as
* described in getAttributes().
*
* This method MUST be implemented in such a way as to retain the
* immutability of the message, and MUST return an instance that removes
* the attribute.
*
* @see getAttributes()
* @param string $name The attribute name.
* @return static
*/
public function withoutAttribute(string $name): ServerRequestInterface;
}
@@ -0,0 +1,158 @@
<?php
namespace Psr\Http\Message;
/**
* Describes a data stream.
*
* Typically, an instance will wrap a PHP stream; this interface provides
* a wrapper around the most common operations, including serialization of
* the entire stream to a string.
*/
interface StreamInterface
{
/**
* Reads all data from the stream into a string, from the beginning to end.
*
* This method MUST attempt to seek to the beginning of the stream before
* reading data and read the stream until the end is reached.
*
* Warning: This could attempt to load a large amount of data into memory.
*
* This method MUST NOT raise an exception in order to conform with PHP's
* string casting operations.
*
* @see http://php.net/manual/en/language.oop5.magic.php#object.tostring
* @return string
*/
public function __toString(): string;
/**
* Closes the stream and any underlying resources.
*
* @return void
*/
public function close(): void;
/**
* Separates any underlying resources from the stream.
*
* After the stream has been detached, the stream is in an unusable state.
*
* @return resource|null Underlying PHP stream, if any
*/
public function detach();
/**
* Get the size of the stream if known.
*
* @return int|null Returns the size in bytes if known, or null if unknown.
*/
public function getSize(): ?int;
/**
* Returns the current position of the file read/write pointer
*
* @return int Position of the file pointer
* @throws \RuntimeException on error.
*/
public function tell(): int;
/**
* Returns true if the stream is at the end of the stream.
*
* @return bool
*/
public function eof(): bool;
/**
* Returns whether or not the stream is seekable.
*
* @return bool
*/
public function isSeekable(): bool;
/**
* Seek to a position in the stream.
*
* @link http://www.php.net/manual/en/function.fseek.php
* @param int $offset Stream offset
* @param int $whence Specifies how the cursor position will be calculated
* based on the seek offset. Valid values are identical to the built-in
* PHP $whence values for `fseek()`. SEEK_SET: Set position equal to
* offset bytes SEEK_CUR: Set position to current location plus offset
* SEEK_END: Set position to end-of-stream plus offset.
* @throws \RuntimeException on failure.
*/
public function seek(int $offset, int $whence = SEEK_SET): void;
/**
* Seek to the beginning of the stream.
*
* If the stream is not seekable, this method will raise an exception;
* otherwise, it will perform a seek(0).
*
* @see seek()
* @link http://www.php.net/manual/en/function.fseek.php
* @throws \RuntimeException on failure.
*/
public function rewind(): void;
/**
* Returns whether or not the stream is writable.
*
* @return bool
*/
public function isWritable(): bool;
/**
* Write data to the stream.
*
* @param string $string The string that is to be written.
* @return int Returns the number of bytes written to the stream.
* @throws \RuntimeException on failure.
*/
public function write(string $string): int;
/**
* Returns whether or not the stream is readable.
*
* @return bool
*/
public function isReadable(): bool;
/**
* Read data from the stream.
*
* @param int $length Read up to $length bytes from the object and return
* them. Fewer than $length bytes may be returned if underlying stream
* call returns fewer bytes.
* @return string Returns the data read from the stream, or an empty string
* if no bytes are available.
* @throws \RuntimeException if an error occurs.
*/
public function read(int $length): string;
/**
* Returns the remaining contents in a string
*
* @return string
* @throws \RuntimeException if unable to read or an error occurs while
* reading.
*/
public function getContents(): string;
/**
* Get stream metadata as an associative array or retrieve a specific key.
*
* The keys returned are identical to the keys returned from PHP's
* stream_get_meta_data() function.
*
* @link http://php.net/manual/en/function.stream-get-meta-data.php
* @param string|null $key Specific metadata to retrieve.
* @return array|mixed|null Returns an associative array if no key is
* provided. Returns a specific key value if a key is provided and the
* value is found, or null if the key is not found.
*/
public function getMetadata(?string $key = null);
}
@@ -0,0 +1,123 @@
<?php
namespace Psr\Http\Message;
/**
* Value object representing a file uploaded through an HTTP request.
*
* Instances of this interface are considered immutable; all methods that
* might change state MUST be implemented such that they retain the internal
* state of the current instance and return an instance that contains the
* changed state.
*/
interface UploadedFileInterface
{
/**
* Retrieve a stream representing the uploaded file.
*
* This method MUST return a StreamInterface instance, representing the
* uploaded file. The purpose of this method is to allow utilizing native PHP
* stream functionality to manipulate the file upload, such as
* stream_copy_to_stream() (though the result will need to be decorated in a
* native PHP stream wrapper to work with such functions).
*
* If the moveTo() method has been called previously, this method MUST raise
* an exception.
*
* @return StreamInterface Stream representation of the uploaded file.
* @throws \RuntimeException in cases when no stream is available or can be
* created.
*/
public function getStream(): StreamInterface;
/**
* Move the uploaded file to a new location.
*
* Use this method as an alternative to move_uploaded_file(). This method is
* guaranteed to work in both SAPI and non-SAPI environments.
* Implementations must determine which environment they are in, and use the
* appropriate method (move_uploaded_file(), rename(), or a stream
* operation) to perform the operation.
*
* $targetPath may be an absolute path, or a relative path. If it is a
* relative path, resolution should be the same as used by PHP's rename()
* function.
*
* The original file or stream MUST be removed on completion.
*
* If this method is called more than once, any subsequent calls MUST raise
* an exception.
*
* When used in an SAPI environment where $_FILES is populated, when writing
* files via moveTo(), is_uploaded_file() and move_uploaded_file() SHOULD be
* used to ensure permissions and upload status are verified correctly.
*
* If you wish to move to a stream, use getStream(), as SAPI operations
* cannot guarantee writing to stream destinations.
*
* @see http://php.net/is_uploaded_file
* @see http://php.net/move_uploaded_file
* @param string $targetPath Path to which to move the uploaded file.
* @throws \InvalidArgumentException if the $targetPath specified is invalid.
* @throws \RuntimeException on any error during the move operation, or on
* the second or subsequent call to the method.
*/
public function moveTo(string $targetPath): void;
/**
* Retrieve the file size.
*
* Implementations SHOULD return the value stored in the "size" key of
* the file in the $_FILES array if available, as PHP calculates this based
* on the actual size transmitted.
*
* @return int|null The file size in bytes or null if unknown.
*/
public function getSize(): ?int;
/**
* Retrieve the error associated with the uploaded file.
*
* The return value MUST be one of PHP's UPLOAD_ERR_XXX constants.
*
* If the file was uploaded successfully, this method MUST return
* UPLOAD_ERR_OK.
*
* Implementations SHOULD return the value stored in the "error" key of
* the file in the $_FILES array.
*
* @see http://php.net/manual/en/features.file-upload.errors.php
* @return int One of PHP's UPLOAD_ERR_XXX constants.
*/
public function getError(): int;
/**
* Retrieve the filename sent by the client.
*
* Do not trust the value returned by this method. A client could send
* a malicious filename with the intention to corrupt or hack your
* application.
*
* Implementations SHOULD return the value stored in the "name" key of
* the file in the $_FILES array.
*
* @return string|null The filename sent by the client or null if none
* was provided.
*/
public function getClientFilename(): ?string;
/**
* Retrieve the media type sent by the client.
*
* Do not trust the value returned by this method. A client could send
* a malicious media type with the intention to corrupt or hack your
* application.
*
* Implementations SHOULD return the value stored in the "type" key of
* the file in the $_FILES array.
*
* @return string|null The media type sent by the client or null if none
* was provided.
*/
public function getClientMediaType(): ?string;
}
@@ -0,0 +1,324 @@
<?php
namespace Psr\Http\Message;
/**
* Value object representing a URI.
*
* This interface is meant to represent URIs according to RFC 3986 and to
* provide methods for most common operations. Additional functionality for
* working with URIs can be provided on top of the interface or externally.
* Its primary use is for HTTP requests, but may also be used in other
* contexts.
*
* Instances of this interface are considered immutable; all methods that
* might change state MUST be implemented such that they retain the internal
* state of the current instance and return an instance that contains the
* changed state.
*
* Typically the Host header will be also be present in the request message.
* For server-side requests, the scheme will typically be discoverable in the
* server parameters.
*
* @link http://tools.ietf.org/html/rfc3986 (the URI specification)
*/
interface UriInterface
{
/**
* Retrieve the scheme component of the URI.
*
* If no scheme is present, this method MUST return an empty string.
*
* The value returned MUST be normalized to lowercase, per RFC 3986
* Section 3.1.
*
* The trailing ":" character is not part of the scheme and MUST NOT be
* added.
*
* @see https://tools.ietf.org/html/rfc3986#section-3.1
* @return string The URI scheme.
*/
public function getScheme(): string;
/**
* Retrieve the authority component of the URI.
*
* If no authority information is present, this method MUST return an empty
* string.
*
* The authority syntax of the URI is:
*
* <pre>
* [user-info@]host[:port]
* </pre>
*
* If the port component is not set or is the standard port for the current
* scheme, it SHOULD NOT be included.
*
* @see https://tools.ietf.org/html/rfc3986#section-3.2
* @return string The URI authority, in "[user-info@]host[:port]" format.
*/
public function getAuthority(): string;
/**
* Retrieve the user information component of the URI.
*
* If no user information is present, this method MUST return an empty
* string.
*
* If a user is present in the URI, this will return that value;
* additionally, if the password is also present, it will be appended to the
* user value, with a colon (":") separating the values.
*
* The trailing "@" character is not part of the user information and MUST
* NOT be added.
*
* @return string The URI user information, in "username[:password]" format.
*/
public function getUserInfo(): string;
/**
* Retrieve the host component of the URI.
*
* If no host is present, this method MUST return an empty string.
*
* The value returned MUST be normalized to lowercase, per RFC 3986
* Section 3.2.2.
*
* @see http://tools.ietf.org/html/rfc3986#section-3.2.2
* @return string The URI host.
*/
public function getHost(): string;
/**
* Retrieve the port component of the URI.
*
* If a port is present, and it is non-standard for the current scheme,
* this method MUST return it as an integer. If the port is the standard port
* used with the current scheme, this method SHOULD return null.
*
* If no port is present, and no scheme is present, this method MUST return
* a null value.
*
* If no port is present, but a scheme is present, this method MAY return
* the standard port for that scheme, but SHOULD return null.
*
* @return null|int The URI port.
*/
public function getPort(): ?int;
/**
* Retrieve the path component of the URI.
*
* The path can either be empty or absolute (starting with a slash) or
* rootless (not starting with a slash). Implementations MUST support all
* three syntaxes.
*
* Normally, the empty path "" and absolute path "/" are considered equal as
* defined in RFC 7230 Section 2.7.3. But this method MUST NOT automatically
* do this normalization because in contexts with a trimmed base path, e.g.
* the front controller, this difference becomes significant. It's the task
* of the user to handle both "" and "/".
*
* The value returned MUST be percent-encoded, but MUST NOT double-encode
* any characters. To determine what characters to encode, please refer to
* RFC 3986, Sections 2 and 3.3.
*
* As an example, if the value should include a slash ("/") not intended as
* delimiter between path segments, that value MUST be passed in encoded
* form (e.g., "%2F") to the instance.
*
* @see https://tools.ietf.org/html/rfc3986#section-2
* @see https://tools.ietf.org/html/rfc3986#section-3.3
* @return string The URI path.
*/
public function getPath(): string;
/**
* Retrieve the query string of the URI.
*
* If no query string is present, this method MUST return an empty string.
*
* The leading "?" character is not part of the query and MUST NOT be
* added.
*
* The value returned MUST be percent-encoded, but MUST NOT double-encode
* any characters. To determine what characters to encode, please refer to
* RFC 3986, Sections 2 and 3.4.
*
* As an example, if a value in a key/value pair of the query string should
* include an ampersand ("&") not intended as a delimiter between values,
* that value MUST be passed in encoded form (e.g., "%26") to the instance.
*
* @see https://tools.ietf.org/html/rfc3986#section-2
* @see https://tools.ietf.org/html/rfc3986#section-3.4
* @return string The URI query string.
*/
public function getQuery(): string;
/**
* Retrieve the fragment component of the URI.
*
* If no fragment is present, this method MUST return an empty string.
*
* The leading "#" character is not part of the fragment and MUST NOT be
* added.
*
* The value returned MUST be percent-encoded, but MUST NOT double-encode
* any characters. To determine what characters to encode, please refer to
* RFC 3986, Sections 2 and 3.5.
*
* @see https://tools.ietf.org/html/rfc3986#section-2
* @see https://tools.ietf.org/html/rfc3986#section-3.5
* @return string The URI fragment.
*/
public function getFragment(): string;
/**
* Return an instance with the specified scheme.
*
* This method MUST retain the state of the current instance, and return
* an instance that contains the specified scheme.
*
* Implementations MUST support the schemes "http" and "https" case
* insensitively, and MAY accommodate other schemes if required.
*
* An empty scheme is equivalent to removing the scheme.
*
* @param string $scheme The scheme to use with the new instance.
* @return static A new instance with the specified scheme.
* @throws \InvalidArgumentException for invalid or unsupported schemes.
*/
public function withScheme(string $scheme): UriInterface;
/**
* Return an instance with the specified user information.
*
* This method MUST retain the state of the current instance, and return
* an instance that contains the specified user information.
*
* Password is optional, but the user information MUST include the
* user; an empty string for the user is equivalent to removing user
* information.
*
* @param string $user The user name to use for authority.
* @param null|string $password The password associated with $user.
* @return static A new instance with the specified user information.
*/
public function withUserInfo(string $user, ?string $password = null): UriInterface;
/**
* Return an instance with the specified host.
*
* This method MUST retain the state of the current instance, and return
* an instance that contains the specified host.
*
* An empty host value is equivalent to removing the host.
*
* @param string $host The hostname to use with the new instance.
* @return static A new instance with the specified host.
* @throws \InvalidArgumentException for invalid hostnames.
*/
public function withHost(string $host): UriInterface;
/**
* Return an instance with the specified port.
*
* This method MUST retain the state of the current instance, and return
* an instance that contains the specified port.
*
* Implementations MUST raise an exception for ports outside the
* established TCP and UDP port ranges.
*
* A null value provided for the port is equivalent to removing the port
* information.
*
* @param null|int $port The port to use with the new instance; a null value
* removes the port information.
* @return static A new instance with the specified port.
* @throws \InvalidArgumentException for invalid ports.
*/
public function withPort(?int $port): UriInterface;
/**
* Return an instance with the specified path.
*
* This method MUST retain the state of the current instance, and return
* an instance that contains the specified path.
*
* The path can either be empty or absolute (starting with a slash) or
* rootless (not starting with a slash). Implementations MUST support all
* three syntaxes.
*
* If the path is intended to be domain-relative rather than path relative then
* it must begin with a slash ("/"). Paths not starting with a slash ("/")
* are assumed to be relative to some base path known to the application or
* consumer.
*
* Users can provide both encoded and decoded path characters.
* Implementations ensure the correct encoding as outlined in getPath().
*
* @param string $path The path to use with the new instance.
* @return static A new instance with the specified path.
* @throws \InvalidArgumentException for invalid paths.
*/
public function withPath(string $path): UriInterface;
/**
* Return an instance with the specified query string.
*
* This method MUST retain the state of the current instance, and return
* an instance that contains the specified query string.
*
* Users can provide both encoded and decoded query characters.
* Implementations ensure the correct encoding as outlined in getQuery().
*
* An empty query string value is equivalent to removing the query string.
*
* @param string $query The query string to use with the new instance.
* @return static A new instance with the specified query string.
* @throws \InvalidArgumentException for invalid query strings.
*/
public function withQuery(string $query): UriInterface;
/**
* Return an instance with the specified URI fragment.
*
* This method MUST retain the state of the current instance, and return
* an instance that contains the specified URI fragment.
*
* Users can provide both encoded and decoded fragment characters.
* Implementations ensure the correct encoding as outlined in getFragment().
*
* An empty fragment value is equivalent to removing the fragment.
*
* @param string $fragment The fragment to use with the new instance.
* @return static A new instance with the specified fragment.
*/
public function withFragment(string $fragment): UriInterface;
/**
* Return the string representation as a URI reference.
*
* Depending on which components of the URI are present, the resulting
* string is either a full URI or relative reference according to RFC 3986,
* Section 4.1. The method concatenates the various components of the URI,
* using the appropriate delimiters:
*
* - If a scheme is present, it MUST be suffixed by ":".
* - If an authority is present, it MUST be prefixed by "//".
* - The path can be concatenated without delimiters. But there are two
* cases where the path has to be adjusted to make the URI reference
* valid as PHP does not allow to throw an exception in __toString():
* - If the path is rootless and an authority is present, the path MUST
* be prefixed by "/".
* - If the path is starting with more than one "/" and no authority is
* present, the starting slashes MUST be reduced to one.
* - If a query is present, it MUST be prefixed by "?".
* - If a fragment is present, it MUST be prefixed by "#".
*
* @see http://tools.ietf.org/html/rfc3986#section-4.1
* @return string
*/
public function __toString(): string;
}
+19
View File
@@ -0,0 +1,19 @@
Copyright (c) 2012 PHP Framework Interoperability Group
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
+58
View File
@@ -0,0 +1,58 @@
PSR Log
=======
This repository holds all interfaces/classes/traits related to
[PSR-3](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md).
Note that this is not a logger of its own. It is merely an interface that
describes a logger. See the specification for more details.
Installation
------------
```bash
composer require psr/log
```
Usage
-----
If you need a logger, you can use the interface like this:
```php
<?php
use Psr\Log\LoggerInterface;
class Foo
{
private $logger;
public function __construct(LoggerInterface $logger = null)
{
$this->logger = $logger;
}
public function doSomething()
{
if ($this->logger) {
$this->logger->info('Doing work');
}
try {
$this->doSomethingElse();
} catch (Exception $exception) {
$this->logger->error('Oh no!', array('exception' => $exception));
}
// do something useful
}
}
```
You can then pick one of the implementations of the interface to get a logger.
If you want to implement the interface, you can require this package and
implement `Psr\Log\LoggerInterface` in your code. Please read the
[specification text](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md)
for details.
+26
View File
@@ -0,0 +1,26 @@
{
"name": "psr/log",
"description": "Common interface for logging libraries",
"keywords": ["psr", "psr-3", "log"],
"homepage": "https://github.com/php-fig/log",
"license": "MIT",
"authors": [
{
"name": "PHP-FIG",
"homepage": "https://www.php-fig.org/"
}
],
"require": {
"php": ">=8.0.0"
},
"autoload": {
"psr-4": {
"Psr\\Log\\": "src"
}
},
"extra": {
"branch-alias": {
"dev-master": "3.x-dev"
}
}
}
@@ -0,0 +1,15 @@
<?php
namespace Psr\Log;
/**
* This is a simple Logger implementation that other Loggers can inherit from.
*
* It simply delegates all log-level-specific methods to the `log` method to
* reduce boilerplate code that a simple Logger that does the same thing with
* messages regardless of the error level has to implement.
*/
abstract class AbstractLogger implements LoggerInterface
{
use LoggerTrait;
}
@@ -0,0 +1,7 @@
<?php
namespace Psr\Log;
class InvalidArgumentException extends \InvalidArgumentException
{
}
+18
View File
@@ -0,0 +1,18 @@
<?php
namespace Psr\Log;
/**
* Describes log levels.
*/
class LogLevel
{
const EMERGENCY = 'emergency';
const ALERT = 'alert';
const CRITICAL = 'critical';
const ERROR = 'error';
const WARNING = 'warning';
const NOTICE = 'notice';
const INFO = 'info';
const DEBUG = 'debug';
}
@@ -0,0 +1,14 @@
<?php
namespace Psr\Log;
/**
* Describes a logger-aware instance.
*/
interface LoggerAwareInterface
{
/**
* Sets a logger instance on the object.
*/
public function setLogger(LoggerInterface $logger): void;
}
@@ -0,0 +1,22 @@
<?php
namespace Psr\Log;
/**
* Basic Implementation of LoggerAwareInterface.
*/
trait LoggerAwareTrait
{
/**
* The logger instance.
*/
protected ?LoggerInterface $logger = null;
/**
* Sets a logger.
*/
public function setLogger(LoggerInterface $logger): void
{
$this->logger = $logger;
}
}
@@ -0,0 +1,98 @@
<?php
namespace Psr\Log;
/**
* Describes a logger instance.
*
* The message MUST be a string or object implementing __toString().
*
* The message MAY contain placeholders in the form: {foo} where foo
* will be replaced by the context data in key "foo".
*
* The context array can contain arbitrary data. The only assumption that
* can be made by implementors is that if an Exception instance is given
* to produce a stack trace, it MUST be in a key named "exception".
*
* See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md
* for the full interface specification.
*/
interface LoggerInterface
{
/**
* System is unusable.
*
* @param mixed[] $context
*/
public function emergency(string|\Stringable $message, array $context = []): void;
/**
* Action must be taken immediately.
*
* Example: Entire website down, database unavailable, etc. This should
* trigger the SMS alerts and wake you up.
*
* @param mixed[] $context
*/
public function alert(string|\Stringable $message, array $context = []): void;
/**
* Critical conditions.
*
* Example: Application component unavailable, unexpected exception.
*
* @param mixed[] $context
*/
public function critical(string|\Stringable $message, array $context = []): void;
/**
* Runtime errors that do not require immediate action but should typically
* be logged and monitored.
*
* @param mixed[] $context
*/
public function error(string|\Stringable $message, array $context = []): void;
/**
* Exceptional occurrences that are not errors.
*
* Example: Use of deprecated APIs, poor use of an API, undesirable things
* that are not necessarily wrong.
*
* @param mixed[] $context
*/
public function warning(string|\Stringable $message, array $context = []): void;
/**
* Normal but significant events.
*
* @param mixed[] $context
*/
public function notice(string|\Stringable $message, array $context = []): void;
/**
* Interesting events.
*
* Example: User logs in, SQL logs.
*
* @param mixed[] $context
*/
public function info(string|\Stringable $message, array $context = []): void;
/**
* Detailed debug information.
*
* @param mixed[] $context
*/
public function debug(string|\Stringable $message, array $context = []): void;
/**
* Logs with an arbitrary level.
*
* @param mixed $level
* @param mixed[] $context
*
* @throws \Psr\Log\InvalidArgumentException
*/
public function log($level, string|\Stringable $message, array $context = []): void;
}
@@ -0,0 +1,98 @@
<?php
namespace Psr\Log;
/**
* This is a simple Logger trait that classes unable to extend AbstractLogger
* (because they extend another class, etc) can include.
*
* It simply delegates all log-level-specific methods to the `log` method to
* reduce boilerplate code that a simple Logger that does the same thing with
* messages regardless of the error level has to implement.
*/
trait LoggerTrait
{
/**
* System is unusable.
*/
public function emergency(string|\Stringable $message, array $context = []): void
{
$this->log(LogLevel::EMERGENCY, $message, $context);
}
/**
* Action must be taken immediately.
*
* Example: Entire website down, database unavailable, etc. This should
* trigger the SMS alerts and wake you up.
*/
public function alert(string|\Stringable $message, array $context = []): void
{
$this->log(LogLevel::ALERT, $message, $context);
}
/**
* Critical conditions.
*
* Example: Application component unavailable, unexpected exception.
*/
public function critical(string|\Stringable $message, array $context = []): void
{
$this->log(LogLevel::CRITICAL, $message, $context);
}
/**
* Runtime errors that do not require immediate action but should typically
* be logged and monitored.
*/
public function error(string|\Stringable $message, array $context = []): void
{
$this->log(LogLevel::ERROR, $message, $context);
}
/**
* Exceptional occurrences that are not errors.
*
* Example: Use of deprecated APIs, poor use of an API, undesirable things
* that are not necessarily wrong.
*/
public function warning(string|\Stringable $message, array $context = []): void
{
$this->log(LogLevel::WARNING, $message, $context);
}
/**
* Normal but significant events.
*/
public function notice(string|\Stringable $message, array $context = []): void
{
$this->log(LogLevel::NOTICE, $message, $context);
}
/**
* Interesting events.
*
* Example: User logs in, SQL logs.
*/
public function info(string|\Stringable $message, array $context = []): void
{
$this->log(LogLevel::INFO, $message, $context);
}
/**
* Detailed debug information.
*/
public function debug(string|\Stringable $message, array $context = []): void
{
$this->log(LogLevel::DEBUG, $message, $context);
}
/**
* Logs with an arbitrary level.
*
* @param mixed $level
*
* @throws \Psr\Log\InvalidArgumentException
*/
abstract public function log($level, string|\Stringable $message, array $context = []): void;
}
+26
View File
@@ -0,0 +1,26 @@
<?php
namespace Psr\Log;
/**
* This Logger can be used to avoid conditional log calls.
*
* Logging should always be optional, and if no logger is provided to your
* library creating a NullLogger instance to have something to throw logs at
* is a good way to avoid littering your code with `if ($this->logger) { }`
* blocks.
*/
class NullLogger extends AbstractLogger
{
/**
* Logs with an arbitrary level.
*
* @param mixed[] $context
*
* @throws \Psr\Log\InvalidArgumentException
*/
public function log($level, string|\Stringable $message, array $context = []): void
{
// noop
}
}
@@ -0,0 +1,12 @@
; This file is for unifying the coding style for different editors and IDEs.
; More information at http://editorconfig.org
root = true
[*]
charset = utf-8
indent_size = 4
indent_style = space
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
@@ -0,0 +1,21 @@
# The MIT License (MIT)
Copyright (c) 2016 PHP Framework Interoperability Group
> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
> in the Software without restriction, including without limitation the rights
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> copies of the Software, and to permit persons to whom the Software is
> furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in
> all copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> THE SOFTWARE.
@@ -0,0 +1,8 @@
PHP FIG Simple Cache PSR
========================
This repository holds all interfaces related to PSR-16.
Note that this is not a cache implementation of its own. It is merely an interface that describes a cache implementation. See [the specification](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-16-simple-cache.md) for more details.
You can find implementations of the specification by looking for packages providing the [psr/simple-cache-implementation](https://packagist.org/providers/psr/simple-cache-implementation) virtual package.
@@ -0,0 +1,25 @@
{
"name": "psr/simple-cache",
"description": "Common interfaces for simple caching",
"keywords": ["psr", "psr-16", "cache", "simple-cache", "caching"],
"license": "MIT",
"authors": [
{
"name": "PHP-FIG",
"homepage": "https://www.php-fig.org/"
}
],
"require": {
"php": ">=8.0.0"
},
"autoload": {
"psr-4": {
"Psr\\SimpleCache\\": "src/"
}
},
"extra": {
"branch-alias": {
"dev-master": "3.0.x-dev"
}
}
}
@@ -0,0 +1,10 @@
<?php
namespace Psr\SimpleCache;
/**
* Interface used for all types of exceptions thrown by the implementing library.
*/
interface CacheException extends \Throwable
{
}
@@ -0,0 +1,114 @@
<?php
namespace Psr\SimpleCache;
interface CacheInterface
{
/**
* Fetches a value from the cache.
*
* @param string $key The unique key of this item in the cache.
* @param mixed $default Default value to return if the key does not exist.
*
* @return mixed The value of the item from the cache, or $default in case of cache miss.
*
* @throws \Psr\SimpleCache\InvalidArgumentException
* MUST be thrown if the $key string is not a legal value.
*/
public function get(string $key, mixed $default = null): mixed;
/**
* Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time.
*
* @param string $key The key of the item to store.
* @param mixed $value The value of the item to store, must be serializable.
* @param null|int|\DateInterval $ttl Optional. The TTL value of this item. If no value is sent and
* the driver supports TTL then the library may set a default value
* for it or let the driver take care of that.
*
* @return bool True on success and false on failure.
*
* @throws \Psr\SimpleCache\InvalidArgumentException
* MUST be thrown if the $key string is not a legal value.
*/
public function set(string $key, mixed $value, null|int|\DateInterval $ttl = null): bool;
/**
* Delete an item from the cache by its unique key.
*
* @param string $key The unique cache key of the item to delete.
*
* @return bool True if the item was successfully removed. False if there was an error.
*
* @throws \Psr\SimpleCache\InvalidArgumentException
* MUST be thrown if the $key string is not a legal value.
*/
public function delete(string $key): bool;
/**
* Wipes clean the entire cache's keys.
*
* @return bool True on success and false on failure.
*/
public function clear(): bool;
/**
* Obtains multiple cache items by their unique keys.
*
* @param iterable<string> $keys A list of keys that can be obtained in a single operation.
* @param mixed $default Default value to return for keys that do not exist.
*
* @return iterable<string, mixed> A list of key => value pairs. Cache keys that do not exist or are stale will have $default as value.
*
* @throws \Psr\SimpleCache\InvalidArgumentException
* MUST be thrown if $keys is neither an array nor a Traversable,
* or if any of the $keys are not a legal value.
*/
public function getMultiple(iterable $keys, mixed $default = null): iterable;
/**
* Persists a set of key => value pairs in the cache, with an optional TTL.
*
* @param iterable $values A list of key => value pairs for a multiple-set operation.
* @param null|int|\DateInterval $ttl Optional. The TTL value of this item. If no value is sent and
* the driver supports TTL then the library may set a default value
* for it or let the driver take care of that.
*
* @return bool True on success and false on failure.
*
* @throws \Psr\SimpleCache\InvalidArgumentException
* MUST be thrown if $values is neither an array nor a Traversable,
* or if any of the $values are not a legal value.
*/
public function setMultiple(iterable $values, null|int|\DateInterval $ttl = null): bool;
/**
* Deletes multiple cache items in a single operation.
*
* @param iterable<string> $keys A list of string-based keys to be deleted.
*
* @return bool True if the items were successfully removed. False if there was an error.
*
* @throws \Psr\SimpleCache\InvalidArgumentException
* MUST be thrown if $keys is neither an array nor a Traversable,
* or if any of the $keys are not a legal value.
*/
public function deleteMultiple(iterable $keys): bool;
/**
* Determines whether an item is present in the cache.
*
* NOTE: It is recommended that has() is only to be used for cache warming type purposes
* and not to be used within your live applications operations for get/set, as this method
* is subject to a race condition where your has() will return true and immediately after,
* another script can remove it making the state of your app out of date.
*
* @param string $key The cache item key.
*
* @return bool
*
* @throws \Psr\SimpleCache\InvalidArgumentException
* MUST be thrown if the $key string is not a legal value.
*/
public function has(string $key): bool;
}
@@ -0,0 +1,13 @@
<?php
namespace Psr\SimpleCache;
/**
* Exception interface for invalid cache arguments.
*
* When an invalid argument is passed it must throw an exception which implements
* this interface
*/
interface InvalidArgumentException extends CacheException
{
}
@@ -0,0 +1,68 @@
name: Bug 反馈
description: 反馈您所遇到的问题,以帮助我们更好的改进
labels: ["bug"]
body:
- type: dropdown
id: addon
attributes:
label: 所属功能组件
options:
- 路由(Route)
- 控制器(Controller)
- 中间件(Middleware)
- 服务(Service)
- 门面(Facade)
- 事件(Event)
- 请求(Request)
- 缓存(Cache)
- 响应(Response)
- 视图(View)
- 异常(Exception)
- 日志(Log)
- 多语言(Lang)
- Session/Cookie
- 命令行(Command)
- 其它
description: |
* 模型(Model)和数据库(Db)功能请前往 https://github.com/top-think/think-orm/issues 反馈
* 多应用(MultiApp)功能请前往 https://github.com/top-think/think-multi-app/issues 反馈
* 容器(Container)功能请前往 https://github.com/top-think/think-container/issues 反馈
* 验证器(Validate)功能请前往 https://github.com/top-think/think-validate/issues 反馈
* 文件系统(Filesystem)功能请前往 https://github.com/top-think/think-filesystem/issues 反馈
* Swoole 功能请前往 https://github.com/top-think/think-swoole/issues 反馈
validations:
required: true
- type: input
id: version
attributes:
label: ThinkPHP 版本
description: 您所使用的 ThinkPHP 版本是?
placeholder: 如:8.0.3
validations:
required: true
- type: input
id: system
attributes:
label: 操作系统
description: 您代码在什么系统上运行?
placeholder: 如:Windows、Centos、Ubuntu、Debian
validations:
required: true
- type: textarea
attributes:
label: 错误信息
description: 如果有报错信息,请附上相关错误信息或截图。如:错误提示语、出错文件路径、出错行号和 Traces 等信息
placeholder: |
信息:控制器不存在
路径:vendor/topthink/framework/src/think/App.php
行号:313
Traces:
......
validations:
required: false
- type: textarea
attributes:
label: 其它说明
description: 如您还有其它需要补充,可在此输入。
validations:
required: false
@@ -0,0 +1,20 @@
---
name: 功能请求
about: 您对 ThinkPHP 有什么改进的想法或建议,可在此提出。
title: ''
labels: 'enhancement'
assignees: ''
---
**您的功能请求与问题相关吗?**
[是的话请在此描述]
**描述您想要的解决方案**
[有的话请在此描述]
**描述您考虑过的替代方案**
[有的话请在此描述]
**其它信息**
[其它相关信息或截图]
@@ -0,0 +1,10 @@
---
name: 其它问题
about: 其它问题可在此反馈
title: ''
labels: 'question'
assignees: ''
---
@@ -0,0 +1,8 @@
blank_issues_enabled: true
contact_links:
- name: ThinkPHP 完全开发手册
url: https://doc.thinkphp.cn/
about: 在创建 Issue 之前,请仔细查阅开发手册,以便对其有更深入的了解,和更好地分析问题。
- name: ThinkPHP 轻社区
url: https://q.thinkphp.cn/
about: 欢迎来到ThinkPHP轻社区和大家一起交流。
@@ -0,0 +1,48 @@
name: build
on:
push:
branches:
- "8.x"
pull_request:
schedule:
- cron: "0 0 * * *"
jobs:
tests:
runs-on: ubuntu-22.04
strategy:
fail-fast: true
matrix:
php: [8.0, 8.1, 8.2, 8.3, 8.4, 8.5]
name: PHP ${{ matrix.php }}
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 10
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer:v2
coverage: xdebug
- name: Install dependencies
uses: nick-fields/retry@v2
with:
timeout_minutes: 5
max_attempts: 5
command: composer update --prefer-dist --no-interaction --prefer-stable --no-suggest
- name: Execute tests
run: vendor/bin/phpunit --coverage-clover build/logs/clover.xml
- name: Upload Scrutinizer coverage
uses: sudo-bot/action-scrutinizer@latest
with:
cli-args: "--format=php-clover build/logs/clover.xml --revision=${{ github.event.pull_request.head.sha || github.sha }}"
@@ -0,0 +1,36 @@
name: PHP CS Fixer
on:
push:
branches:
- "8.x"
paths:
- '**.php'
pull_request:
branches:
- "8.x"
paths:
- '**.php'
jobs:
php-cs-fixer:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 10
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
tools: cs2pr,php-cs-fixer
- name: Run PHP CS Fixer
run: |
changed_files=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} -- '*.php')
for file in $changed_files; do
php-cs-fixer fix "$file" --dry-run --diff --format=checkstyle | cs2pr
done
@@ -0,0 +1,12 @@
/vendor
composer.phar
composer.lock
.DS_Store
Thumbs.db
/.idea
/.vscode
/.settings
/.buildpath
/.project
.phpunit.result.cache
.php-cs-fixer.cache
@@ -0,0 +1,48 @@
<?php
use PhpCsFixer\Config;
use PhpCsFixer\Finder;
$finder = (new Finder())
->in(__DIR__)
;
return (new Config())
->setRules([
'@PhpCsFixer' => true,
'@PHP8x0Migration' => true,
'binary_operator_spaces' => [
'default' => 'align_single_space_minimal',
'operators' => [
'=>' => 'align_single_space_minimal_by_scope',
],
],
'blank_line_before_statement' => [
'statements' => [
'continue',
'declare',
'return',
'throw',
'try',
],
],
'concat_space' => [
'spacing' => 'one',
],
'global_namespace_import' => [
'import_classes' => true,
'import_constants' => false,
'import_functions' => false,
],
'ordered_class_elements' => [
'order' => [
'use_trait',
'case',
'constant',
'property',
'construct',
],
],
])
->setFinder($finder)
;
@@ -0,0 +1,119 @@
如何贡献我的源代码
===
此文档介绍了 ThinkPHP 团队的组成以及运转机制,您提交的代码将给 ThinkPHP 项目带来什么好处,以及如何才能加入我们的行列。
## 通过 Github 贡献代码
ThinkPHP 目前使用 Git 来控制程序版本,如果你想为 ThinkPHP 贡献源代码,请先大致了解 Git 的使用方法。我们目前把项目托管在 GitHub 上,任何 GitHub 用户都可以向我们贡献代码。
参与的方式很简单,`fork`一份 ThinkPHP 的代码到你的仓库中,修改后提交,并向我们发起`pull request`申请,我们会及时对代码进行审查并处理你的申请并。审查通过后,你的代码将被`merge`进我们的仓库中,这样你就会自动出现在贡献者名单里了,非常方便。
我们希望你贡献的代码符合:
* ThinkPHP 的编码规范
* 适当的注释,能让其他人读懂
* 遵循 Apache2 开源协议
**如果想要了解更多细节或有任何疑问,请继续阅读下面的内容**
### 注意事项
* 本项目代码格式化标准选用 [**PER-CS2.0**](https://cs.symfony.com/doc/ruleSets/PER-CS2.0.html);
* 类名和类文件名遵循 [**PSR-4**](http://www.kancloud.cn/thinkphp/php-fig-psr/3144);
* 对于 Issues 的处理,请使用诸如 `fix #xxx(Issue ID)` 的 commit title 直接关闭 issue。
* 系统会自动在 PHP 8.0 ~ 8.3 版本上测试修改,请确保你的修改符合 PHP 版本的语法规范;
* 管理员不会合并造成 CI Failed 的修改,若出现 CI Failed 请检查自己的源代码或修改相应的[单元测试文件](tests);
## GitHub Issue
GitHub 提供了 Issue 功能,该功能可以用于:
* 提出 bug
* 提出功能改进
* 反馈使用体验
该功能不应该用于:
* 提出修改意见(涉及代码署名和修订追溯问题)
* 不友善的言论
## 快速修改
**GitHub 提供了快速编辑文件的功能**
1. 登录 GitHub 帐号;
2. 浏览项目文件,找到要进行修改的文件;
3. 点击右上角铅笔图标进行修改;
4. 填写 `Commit changes` 相关内容(Title 必填);
5. 提交修改,等待 CI 验证和管理员合并。
**若您需要一次提交大量修改,请继续阅读下面的内容**
## 完整流程
1. `fork`本项目;
2. 克隆(`clone`)你 `fork` 的项目到本地;
3. 新建分支(`branch`)并检出(`checkout`)新分支;
4. 添加本项目到你的本地 git 仓库作为上游(`upstream`);
5. 进行修改,若你的修改包含方法或函数的增减,请记得修改[单元测试文件](tests);
6. 变基(衍合 `rebase`)你的分支到上游 master 分支;
7. `push` 你的本地仓库到 GitHub;
8. 提交 `pull request`;
9. 等待 CI 验证(若不通过则重复 5~7,GitHub 会自动更新你的 `pull request`);
10. 等待管理员处理,并及时 `rebase` 你的分支到上游 master 分支(若上游 master 分支有修改)。
*若有必要,可以 `git push -f` 强行推送 rebase 后的分支到自己的 `fork`*
*绝对不可以使用 `git push -f` 强行推送修改到上游*
### 注意事项
* 若对上述流程有任何不清楚的地方,请查阅 GIT 教程,如 [这个](http://backlogtool.com/git-guide/cn/);
* 对于代码**不同方面**的修改,请在自己 `fork` 的项目中**创建不同的分支**(原因参见`完整流程`第9条备注部分);
* 变基及交互式变基操作参见 [Git 交互式变基](http://pakchoi.me/2015/03/17/git-interactive-rebase/)
## 推荐资源
### 开发环境
* [XAMPP](https://www.apachefriends.org/zh_cn/download.html) - Windows、Linux、Mac OS
* [WampServer](https://www.apachefriends.org/zh_cn/download.html) - Windows
* Docker - Windows、Linux、Mac OS
或自行安装
- Apache / Nginx
- PHP 8.0 ~ 8.3
- MySQL / MariaDB
*Windows 用户推荐添加 PHP bin 目录到 PATH,方便使用 composer*
*Linux 用户自行配置环境, Mac 用户推荐使用内置 Apache 配合 Homebrew 安装 PHP 和 MariaDB*
### 编辑器
Sublime Text 3 + phpfmt 插件
phpfmt 插件参数
```json
{
"autocomplete": true,
"enable_auto_align": true,
"format_on_save": true,
"indent_with_space": true,
"psr1_naming": false,
"psr2": true,
"version": 4
}
```
或其他 编辑器 / IDE 配合自动格式化工具
### Git GUI
* SourceTree
* GitHub Desktop
或其他 Git 图形界面客户端
@@ -0,0 +1,32 @@
ThinkPHP遵循Apache2开源协议发布,并提供免费使用。
版权所有Copyright © 2006-2023 by ThinkPHP (http://thinkphp.cn)
All rights reserved。
ThinkPHP® 商标和著作权所有者为上海顶想信息科技有限公司。
Apache Licence是著名的非盈利开源组织Apache采用的协议。
该协议和BSD类似,鼓励代码共享和尊重原作者的著作权,
允许代码修改,再作为开源或商业软件发布。需要满足
的条件:
1. 需要给代码的用户一份Apache Licence ;
2. 如果你修改了代码,需要在被修改的文件中说明;
3. 在延伸的代码中(修改和有源代码衍生的代码中)需要
带有原来代码中的协议,商标,专利声明和其他原来作者规
定需要包含的说明;
4. 如果再发布的产品中包含一个Notice文件,则在Notice文
件中需要带有本协议内容。你可以在Notice中增加自己的
许可,但不可以表现为对Apache Licence构成更改。
具体的协议参考:http://www.apache.org/licenses/LICENSE-2.0
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,85 @@
![](https://www.thinkphp.cn/uploads/images/20230630/300c856765af4d8ae758c503185f8739.png)
# ThinkPHP 8
[![build](https://github.com/top-think/framework/actions/workflows/build.yml/badge.svg?branch=8.0)](https://github.com/top-think/framework/actions)
[![Total Downloads](https://poser.pugx.org/topthink/framework/downloads)](https://packagist.org/packages/topthink/framework)
[![Latest Stable Version](https://poser.pugx.org/topthink/framework/v/stable)](https://packagist.org/packages/topthink/framework)
[![PHP Version](https://img.shields.io/badge/php-%3E%3D8.0-8892BF.svg)](http://www.php.net/)
[![License](https://poser.pugx.org/topthink/framework/license)](https://packagist.org/packages/topthink/framework)
## 主要特性
- 基于 PHP`8.0+`重构
- 升级`PSR`依赖
- 依赖`think-orm`3.0+ 版本
- 全新的`think-dumper`支持远程调试
- `6.0`/`6.1`无缝升级
> ThinkPHP8 的运行环境要求 PHP8.0+
现在开始,你可以使用官方提供的[ThinkChat](https://chat.topthink.com/),让你在学习 ThinkPHP 的旅途中享受私人 AI 助理服务!
[![](https://www.topthink.com/uploads/assistant/20230630/4d1a3f0ad2958b49bb8189b7ef824cb0.png)](https://chat.topthink.com/)
ThinkPHP 生态服务由[顶想云](https://www.topthink.com)(TOPThink Cloud)提供,为生态提供专业的开发者服务和价值之选。
## 文档
[完全开发手册](https://doc.thinkphp.cn)
基于官方手册的数据训练和提供精准解答服务
[官方专家智能体](https://chat.topthink.com/chat/eorole)
## 赞助商
全新的[赞助计划](https://www.thinkphp.cn/sponsor)可以让你通过我们的网站、手册、欢迎页及 GIT 仓库获得巨大曝光,同时提升企业的品牌声誉,也更好保障 ThinkPHP 的可持续发展。
[![](https://www.thinkphp.cn/sponsor/special.svg)](https://www.thinkphp.cn/sponsor/special)
[![](https://www.thinkphp.cn/sponsor.svg)](https://www.thinkphp.cn/sponsor)
## 安装
```
composer create-project topthink/think tp
```
启动服务
```
cd tp
php think run
```
然后就可以在浏览器中访问
```
http://localhost:8000
```
如果需要更新框架使用
```
composer update topthink/framework
```
## 命名规范
`ThinkPHP`遵循 PSR-2 命名规范和 PSR-4 自动加载规范。
## 参与开发
直接提交 PR 或者 Issue 即可
## 版权信息
ThinkPHP 遵循 Apache2 开源协议发布,并提供免费使用。
本项目包含的第三方源码和二进制文件之版权信息另行标注。
版权所有 Copyright © 2006-2025 by ThinkPHP (http://thinkphp.cn) All rights reserved。
ThinkPHP® 商标和著作权所有者为上海顶想信息科技有限公司。
更多细节参阅 [LICENSE.txt](LICENSE.txt)
@@ -0,0 +1,60 @@
{
"name": "topthink/framework",
"description": "The ThinkPHP Framework.",
"keywords": [
"framework",
"thinkphp",
"ORM"
],
"homepage": "http://thinkphp.cn/",
"license": "Apache-2.0",
"authors": [
{
"name": "liu21st",
"email": "liu21st@gmail.com"
},
{
"name": "yunwuxin",
"email": "448901948@qq.com"
}
],
"require": {
"php": ">=8.0.0",
"ext-json": "*",
"ext-mbstring": "*",
"ext-ctype": "*",
"psr/log": "^1.0|^2.0|^3.0",
"psr/simple-cache": "^1.0|^2.0|^3.0",
"psr/http-message": "^1.0|^2.0",
"topthink/think-orm": "^3.0|^4.0",
"topthink/think-helper": "^3.1",
"topthink/think-container": "^3.0",
"topthink/think-validate": "^3.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.92",
"guzzlehttp/psr7": "^2.1.0",
"mikey179/vfsstream": "^1.6",
"mockery/mockery": "^1.2",
"phpunit/phpunit": "^9.5"
},
"autoload": {
"files": [],
"psr-4": {
"think\\": "src/think/"
}
},
"autoload-dev": {
"psr-4": {
"think\\tests\\": "tests/"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"sort-packages": true
},
"scripts": {
"php-cs-fixer": "php-cs-fixer fix src/ --dry-run --diff"
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
backupGlobals="false"
backupStaticAttributes="false"
beStrictAboutTestsThatDoNotTestAnything="false"
bootstrap="tests/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
verbose="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src/think</directory>
</include>
</coverage>
<testsuites>
<testsuite name="ThinkPHP Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
</phpunit>
@@ -0,0 +1,677 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2025 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
declare (strict_types = 1);
//------------------------
// ThinkPHP 助手函数
//-------------------------
use think\App;
use think\Container;
use think\exception\HttpException;
use think\exception\HttpResponseException;
use think\facade\Cache;
use think\facade\Config;
use think\facade\Cookie;
use think\facade\Env;
use think\facade\Event;
use think\facade\Lang;
use think\facade\Log;
use think\facade\Request;
use think\facade\Route;
use think\facade\Session;
use think\Response;
use think\response\File;
use think\response\Json;
use think\response\Jsonp;
use think\response\Redirect;
use think\response\View;
use think\response\Xml;
use think\route\Url as UrlBuild;
use think\Validate;
use think\validate\ValidateRuleSet;
if (!function_exists('abort')) {
/**
* 抛出HTTP异常
* @param int|Response $code 状态码 或者 Response对象实例
* @param string $message 错误信息
* @param array $header 参数
*/
function abort($code, string $message = '', array $header = [])
{
if ($code instanceof Response) {
throw new HttpResponseException($code);
} else {
throw new HttpException($code, $message, null, $header);
}
}
}
if (!function_exists('app')) {
/**
* 快速获取容器中的实例 支持依赖注入
* @template T
* @param string|class-string<T> $name 类名或标识 默认获取当前应用实例
* @param array $args 参数
* @param bool $newInstance 是否每次创建新的实例
* @return T|object|App
*/
function app(string $name = '', array $args = [], bool $newInstance = false)
{
return Container::getInstance()->make($name ?: App::class, $args, $newInstance);
}
}
if (!function_exists('bind')) {
/**
* 绑定一个类到容器
* @param string|array $abstract 类标识、接口(支持批量绑定)
* @param mixed $concrete 要绑定的类、闭包或者实例
* @return Container
*/
function bind($abstract, $concrete = null)
{
return Container::getInstance()->bind($abstract, $concrete);
}
}
if (!function_exists('cache')) {
/**
* 缓存管理
* @param string $name 缓存名称
* @param mixed $value 缓存值
* @param mixed $options 缓存参数
* @param string $tag 缓存标签
* @return mixed
*/
function cache(?string $name = null, $value = '', $options = null, $tag = null)
{
if (is_null($name)) {
return app('cache');
}
if ('' === $value) {
// 获取缓存
return str_starts_with($name, '?') ? Cache::has(substr($name, 1)) : Cache::get($name);
} elseif (is_null($value)) {
// 删除缓存
return Cache::delete($name);
}
// 缓存数据
if (is_array($options)) {
$expire = $options['expire'] ?? null; //修复查询缓存无法设置过期时间
} else {
$expire = $options;
}
if (is_null($tag)) {
return Cache::set($name, $value, $expire);
} else {
return Cache::tag($tag)->set($name, $value, $expire);
}
}
}
if (!function_exists('config')) {
/**
* 获取和设置配置参数
* @param string|array $name 参数名
* @param mixed $value 参数值
* @return mixed
*/
function config($name = '', $value = null)
{
if (is_array($name)) {
return Config::set($name, $value);
}
return str_starts_with($name, '?') ? Config::has(substr($name, 1)) : Config::get($name, $value);
}
}
if (!function_exists('cookie')) {
/**
* Cookie管理
* @param string $name cookie名称
* @param mixed $value cookie值
* @param mixed $option 参数
* @return mixed
*/
function cookie(string $name, $value = '', $option = null)
{
if (is_null($value)) {
// 删除
Cookie::delete($name, $option ?: []);
} elseif ('' === $value) {
// 获取
return str_starts_with($name, '?') ? Cookie::has(substr($name, 1)) : Cookie::get($name);
} else {
// 设置
return Cookie::set($name, $value, $option);
}
}
}
if (!function_exists('download')) {
/**
* 获取\think\response\Download对象实例
* @param string $filename 要下载的文件
* @param string $name 显示文件名
* @param bool $content 是否为内容
* @param int $expire 有效期(秒)
* @return \think\response\File
*/
function download(string $filename, string $name = '', bool $content = false, int $expire = 180): File
{
return Response::create($filename, 'file')->name($name)->isContent($content)->expire($expire);
}
}
if (!function_exists('dump')) {
/**
* 浏览器友好的变量输出
* @param mixed $vars 要输出的变量
* @return void
*/
function dump(...$vars)
{
ob_start();
var_dump(...$vars);
$output = ob_get_clean();
$output = preg_replace('/\]\=\>\n(\s+)/m', '] => ', $output);
if (PHP_SAPI == 'cli') {
$output = PHP_EOL . $output . PHP_EOL;
} else {
if (!extension_loaded('xdebug')) {
$output = htmlspecialchars($output, ENT_SUBSTITUTE);
}
$output = '<pre>' . $output . '</pre>';
}
echo $output;
}
}
if (!function_exists('env')) {
/**
* 获取环境变量值
* @access public
* @param string $name 环境变量名(支持二级 .号分割)
* @param string $default 默认值
* @return mixed
*/
function env(?string $name = null, $default = null)
{
return Env::get($name, $default);
}
}
if (!function_exists('event')) {
/**
* 触发事件
* @param mixed $event 事件名(或者类名)
* @param mixed $args 参数
* @return mixed
*/
function event($event, $args = null)
{
return Event::trigger($event, $args);
}
}
if (!function_exists('halt')) {
/**
* 调试变量并且中断输出
* @param mixed $vars 调试变量或者信息
*/
function halt(...$vars)
{
dump(...$vars);
throw new HttpResponseException(Response::create());
}
}
if (!function_exists('input')) {
/**
* 获取输入数据 支持默认值和过滤
* @param string $key 获取的变量名
* @param mixed $default 默认值
* @param string|array|null $filter 过滤方法
* @return mixed
*/
function input(string $key = '', $default = null, $filter = '')
{
if (str_starts_with($key, '?')) {
$key = substr($key, 1);
$has = true;
}
if ($pos = strpos($key, '.')) {
// 指定参数来源
$method = substr($key, 0, $pos);
if (in_array($method, ['get', 'post', 'put', 'patch', 'delete', 'route', 'param', 'request', 'session', 'cookie', 'server', 'env', 'path', 'file'])) {
$key = substr($key, $pos + 1);
if ('server' == $method && is_null($default)) {
$default = '';
}
} else {
$method = 'param';
}
} else {
// 默认为自动判断
$method = 'param';
}
return isset($has) ?
request()->has($key, $method) :
request()->$method($key, $default, $filter);
}
}
if (!function_exists('invoke')) {
/**
* 调用反射实例化对象或者执行方法 支持依赖注入
* @param mixed $call 类名或者callable
* @param array $args 参数
* @return mixed
*/
function invoke($call, array $args = [])
{
if (is_callable($call)) {
return Container::getInstance()->invoke($call, $args);
}
return Container::getInstance()->invokeClass($call, $args);
}
}
if (!function_exists('json')) {
/**
* 获取\think\response\Json对象实例
* @param mixed $data 返回的数据
* @param int $code 状态码
* @param array $header 头部
* @param array $options 参数
* @return \think\response\Json
*/
function json($data = [], $code = 200, $header = [], $options = []): Json
{
return Response::create($data, 'json', $code)->header($header)->options($options);
}
}
if (!function_exists('jsonp')) {
/**
* 获取\think\response\Jsonp对象实例
* @param mixed $data 返回的数据
* @param int $code 状态码
* @param array $header 头部
* @param array $options 参数
* @return \think\response\Jsonp
*/
function jsonp($data = [], $code = 200, $header = [], $options = []): Jsonp
{
return Response::create($data, 'jsonp', $code)->header($header)->options($options);
}
}
if (!function_exists('lang')) {
/**
* 获取语言变量值
* @param string $name 语言变量名
* @param array $vars 动态变量值
* @param string $lang 语言
* @return mixed
*/
function lang(string $name, array $vars = [], string $lang = '')
{
return Lang::get($name, $vars, $lang);
}
}
if (!function_exists('parse_name')) {
/**
* 字符串命名风格转换
* type 0 将Java风格转换为C的风格 1 将C风格转换为Java的风格
* @param string $name 字符串
* @param int $type 转换类型
* @param bool $ucfirst 首字母是否大写(驼峰规则)
* @return string
*/
function parse_name(string $name, int $type = 0, bool $ucfirst = true): string
{
if ($type) {
$name = preg_replace_callback('/_([a-zA-Z])/', function ($match) {
return strtoupper($match[1]);
}, $name);
return $ucfirst ? ucfirst($name) : lcfirst($name);
}
return strtolower(trim(preg_replace('/[A-Z]/', '_\\0', $name), '_'));
}
}
if (!function_exists('redirect')) {
/**
* 获取\think\response\Redirect对象实例
* @param string $url 重定向地址
* @param int $code 状态码
* @return \think\response\Redirect
*/
function redirect(string $url = '', int $code = 302): Redirect
{
return Response::create($url, 'redirect', $code);
}
}
if (!function_exists('request')) {
/**
* 获取当前Request对象实例
* @return Request
*/
function request(): \think\Request
{
return app('request');
}
}
if (!function_exists('response')) {
/**
* 创建普通 Response 对象实例
* @param mixed $data 输出数据
* @param int|string $code 状态码
* @param array $header 头信息
* @param string $type
* @return Response
*/
function response($data = '', $code = 200, $header = [], $type = 'html'): Response
{
return Response::create($data, $type, $code)->header($header);
}
}
if (!function_exists('session')) {
/**
* Session管理
* @param string $name session名称
* @param mixed $value session值
* @return mixed
*/
function session($name = '', $value = '')
{
if (is_null($name)) {
// 清除
Session::clear();
} elseif ('' === $name) {
return Session::all();
} elseif (is_null($value)) {
// 删除
Session::delete($name);
} elseif ('' === $value) {
// 判断或获取
return str_starts_with($name, '?') ? Session::has(substr($name, 1)) : Session::get($name);
} else {
// 设置
Session::set($name, $value);
}
}
}
if (!function_exists('token')) {
/**
* 获取Token令牌
* @param string $name 令牌名称
* @param mixed $type 令牌生成方法
* @return string
*/
function token(string $name = '__token__', string $type = 'md5'): string
{
return Request::buildToken($name, $type);
}
}
if (!function_exists('token_field')) {
/**
* 生成令牌隐藏表单
* @param string $name 令牌名称
* @param mixed $type 令牌生成方法
* @return string
*/
function token_field(string $name = '__token__', string $type = 'md5'): string
{
$token = Request::buildToken($name, $type);
return '<input type="hidden" name="' . $name . '" value="' . $token . '" />';
}
}
if (!function_exists('token_meta')) {
/**
* 生成令牌meta
* @param string $name 令牌名称
* @param mixed $type 令牌生成方法
* @return string
*/
function token_meta(string $name = '__token__', string $type = 'md5'): string
{
$token = Request::buildToken($name, $type);
return '<meta name="csrf-token" content="' . $token . '">';
}
}
if (!function_exists('trace')) {
/**
* 记录日志信息
* @param mixed $log log信息 支持字符串和数组
* @param string $level 日志级别
* @return array|void
*/
function trace($log = '[think]', string $level = 'log')
{
if ('[think]' === $log) {
return Log::getLog();
}
Log::record($log, $level);
}
}
if (!function_exists('url')) {
/**
* Url生成
* @param string $url 路由地址
* @param array $vars 变量
* @param bool|string $suffix 生成的URL后缀
* @param bool|string $domain 域名
* @return UrlBuild
*/
function url(string $url = '', array $vars = [], $suffix = true, $domain = false): UrlBuild
{
return Route::buildUrl($url, $vars)->suffix($suffix)->domain($domain);
}
}
if (!function_exists('validate')) {
/**
* 生成验证对象
* @param string|array $validate 验证器类名或者验证规则数组
* @param array $message 错误提示信息
* @param bool $batch 是否批量验证
* @param bool $failException 是否抛出异常
* @return Validate
*/
function validate($validate = '', array $message = [], bool $batch = false, bool $failException = true): Validate
{
if (is_array($validate) || '' === $validate) {
$v = new Validate();
if (is_array($validate)) {
$v->rule($validate);
}
} else {
if (str_contains($validate, '.')) {
// 支持场景
[$validate, $scene] = explode('.', $validate);
}
$class = str_contains($validate, '\\') ? $validate : app()->parseClass('validate', $validate);
$v = new $class();
if (!empty($scene)) {
$v->scene($scene);
}
}
return $v->message($message)->batch($batch)->failException($failException);
}
}
if (!function_exists('rules')) {
/**
* 定义ValidateRuleSet规则集合
* @param array $rules 验证因子集
* @return ValidateRuleSet
*/
function rules(array $rules): ValidateRuleSet
{
return ValidateRuleSet::rules($rules);
}
}
if (!function_exists('view')) {
/**
* 渲染模板输出
* @param string $template 模板文件
* @param array $vars 模板变量
* @param int $code 状态码
* @param callable $filter 内容过滤
* @return \think\response\View
*/
function view(string $template = '', $vars = [], $code = 200, $filter = null): View
{
return Response::create($template, 'view', $code)->assign($vars)->filter($filter);
}
}
if (!function_exists('display')) {
/**
* 渲染模板输出
* @param string $content 渲染内容
* @param array $vars 模板变量
* @param int $code 状态码
* @param callable $filter 内容过滤
* @return \think\response\View
*/
function display(string $content, $vars = [], $code = 200, $filter = null): View
{
return Response::create($content, 'view', $code)->isContent(true)->assign($vars)->filter($filter);
}
}
if (!function_exists('xml')) {
/**
* 获取\think\response\Xml对象实例
* @param mixed $data 返回的数据
* @param int $code 状态码
* @param array $header 头部
* @param array $options 参数
* @return \think\response\Xml
*/
function xml($data = [], $code = 200, $header = [], $options = []): Xml
{
return Response::create($data, 'xml', $code)->header($header)->options($options);
}
}
if (!function_exists('app_path')) {
/**
* 获取当前应用目录
*
* @param string $path
* @return string
*/
function app_path($path = '')
{
return app()->getAppPath() . ($path ? $path . DIRECTORY_SEPARATOR : $path);
}
}
if (!function_exists('base_path')) {
/**
* 获取应用基础目录
*
* @param string $path
* @return string
*/
function base_path($path = '')
{
return app()->getBasePath() . ($path ? $path . DIRECTORY_SEPARATOR : $path);
}
}
if (!function_exists('config_path')) {
/**
* 获取应用配置目录
*
* @param string $path
* @return string
*/
function config_path($path = '')
{
return app()->getConfigPath() . ($path ? $path . DIRECTORY_SEPARATOR : $path);
}
}
if (!function_exists('public_path')) {
/**
* 获取web根目录
*
* @param string $path
* @return string
*/
function public_path($path = '')
{
return app()->getRootPath() . 'public' . DIRECTORY_SEPARATOR . ($path ? ltrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR : $path);
}
}
if (!function_exists('runtime_path')) {
/**
* 获取应用运行时目录
*
* @param string $path
* @return string
*/
function runtime_path($path = '')
{
return app()->getRuntimePath() . ($path ? $path . DIRECTORY_SEPARATOR : $path);
}
}
if (!function_exists('root_path')) {
/**
* 获取项目根目录
*
* @param string $path
* @return string
*/
function root_path($path = '')
{
return app()->getRootPath() . ($path ? $path . DIRECTORY_SEPARATOR : $path);
}
}
@@ -0,0 +1,157 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2025 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
// 核心中文语言包
return [
// 系统错误提示
'Undefined variable' => '未定义变量',
'Undefined index' => '未定义数组索引',
'Undefined offset' => '未定义数组下标',
'Parse error' => '语法解析错误',
'Type error' => '类型错误',
'Fatal error' => '致命错误',
'syntax error' => '语法错误',
// 框架核心错误提示
'dispatch type not support' => '不支持的调度类型',
'method param miss' => '方法参数错误',
'method not exists' => '方法不存在',
'function not exists' => '函数不存在',
'app not exists' => '应用不存在',
'controller not exists' => '控制器不存在',
'class not exists' => '类不存在',
'property not exists' => '类的属性不存在',
'template not exists' => '模板文件不存在',
'illegal controller name' => '非法的控制器名称',
'illegal action name' => '非法的操作名称',
'url suffix deny' => '禁止的URL后缀访问',
'Undefined cache config' => '缓存配置未定义',
'Route Not Found' => '当前访问路由未定义或不匹配',
'Undefined db config' => '数据库配置未定义',
'Undefined log config' => '日志配置未定义',
'Undefined db type' => '未定义数据库类型',
'variable type error' => '变量类型错误',
'PSR-4 error' => 'PSR-4 规范错误',
'not support type' => '不支持的分页索引字段类型',
'not support total' => '简洁模式下不能获取数据总数',
'not support last' => '简洁模式下不能获取最后一页',
'error session handler' => '错误的SESSION处理器类',
'not allow php tag' => '模板不允许使用PHP语法',
'not support' => '不支持',
'database config error' => '数据库配置信息错误',
'redisd master' => 'Redisd 主服务器错误',
'redisd slave' => 'Redisd 从服务器错误',
'must run at sae' => '必须在SAE运行',
'memcache init error' => '未开通Memcache服务,请在SAE管理平台初始化Memcache服务',
'KVDB init error' => '没有初始化KVDB,请在SAE管理平台初始化KVDB服务',
'fields not exists' => '数据表字段不存在',
'where express error' => '查询表达式错误',
'no data to update' => '没有任何数据需要更新',
'miss data to insert' => '缺少需要写入的数据',
'miss complex primary data' => '缺少复合主键数据',
'miss update condition' => '缺少更新条件',
'model data Not Found' => '模型数据不存在',
'table data not Found' => '表数据不存在',
'delete without condition' => '没有条件不会执行删除操作',
'miss relation data' => '缺少关联表数据',
'tag attr must' => '模板标签属性必须',
'tag error' => '模板标签错误',
'cache write error' => '缓存写入失败',
'sae mc write error' => 'SAE mc 写入错误',
'route name not exists' => '路由标识不存在(或参数不够)',
'invalid request' => '非法请求',
'bind attr has exists' => '模型的属性已经存在',
'relation data not exists' => '关联数据不存在',
'relation not support' => '关联不支持',
'chunk not support order' => 'Chunk不支持调用order方法',
'route pattern error' => '路由变量规则定义错误',
'route behavior will not support' => '路由行为废弃(使用中间件替代)',
'closure not support cache(true)' => '使用闭包查询不支持cache(true),请指定缓存Key',
// 上传错误信息
'unknown upload error' => '未知上传错误!',
'file write error' => '文件写入失败!',
'upload temp dir not found' => '找不到临时文件夹!',
'no file to uploaded' => '没有文件被上传!',
'only the portion of file is uploaded' => '文件只有部分被上传!',
'upload File size exceeds the maximum value' => '上传文件大小超过了最大值!',
'upload write error' => '文件上传保存错误!',
'has the same filename: {:filename}' => '存在同名文件:{:filename}',
'upload illegal files' => '非法上传文件',
'illegal image files' => '非法图片文件',
'extensions to upload is not allowed' => '上传文件后缀不允许',
'mimetype to upload is not allowed' => '上传文件MIME类型不允许!',
'filesize not match' => '上传文件大小不符!',
'directory {:path} creation failed' => '目录 {:path} 创建失败!',
'The middleware must return Response instance' => '中间件方法必须返回Response对象实例',
'The queue was exhausted, with no response returned' => '中间件队列为空',
// Validate Error Message
':attribute require' => ':attribute不能为空',
':attribute must' => ':attribute必须',
':attribute must be numeric' => ':attribute必须是数字',
':attribute must be integer' => ':attribute必须是整数',
':attribute must be float' => ':attribute必须是浮点数',
':attribute must be string' => ':attribute必须是字符串',
':attribute must be :rule enum' => ':attribute必须是有效的 :rule 枚举',
':attribute must start with :rule' => ':attribute必须以 :rule 开头',
':attribute must end with :rule' => ':attribute必须以 :rule 结尾',
':attribute must contain :rule' => ':attribute必须包含 :rule',
':attribute must be bool' => ':attribute必须是布尔值',
':attribute not a valid email address' => ':attribute格式不符',
':attribute not a valid mobile' => ':attribute格式不符',
':attribute must be a array' => ':attribute必须是数组',
':attribute must be yes,on,true or 1' => ':attribute必须是yes、on、true或者1',
':attribute must be no,off,false or 0' => ':attribute必须是no、off、false或者0',
':attribute not a valid datetime' => ':attribute不是一个有效的日期或时间格式',
':attribute not a valid file' => ':attribute不是有效的上传文件',
':attribute not a valid image' => ':attribute不是有效的图像文件',
':attribute must be alpha' => ':attribute只能是字母',
':attribute must be alpha-numeric' => ':attribute只能是字母和数字',
':attribute must be alpha-numeric, dash, underscore' => ':attribute只能是字母、数字和下划线_及破折号-',
':attribute not a valid domain or ip' => ':attribute不是有效的域名或者IP',
':attribute must be chinese' => ':attribute只能是汉字',
':attribute must be chinese or alpha' => ':attribute只能是汉字、字母',
':attribute must be chinese,alpha-numeric' => ':attribute只能是汉字、字母和数字',
':attribute must be chinese,alpha-numeric,underscore, dash' => ':attribute只能是汉字、字母、数字和下划线_及破折号-',
':attribute not a valid url' => ':attribute不是有效的URL地址',
':attribute not a valid ip' => ':attribute不是有效的IP地址',
':attribute must be dateFormat of :rule' => ':attribute必须使用日期格式 :rule',
':attribute must be in :rule' => ':attribute必须在 :rule 范围内',
':attribute be notin :rule' => ':attribute不能在 :rule 范围内',
':attribute must between :1 - :2' => ':attribute只能在 :1 - :2 之间',
':attribute not between :1 - :2' => ':attribute不能在 :1 - :2 之间',
'size of :attribute must be :rule' => ':attribute长度不符合要求 :rule',
'max size of :attribute must be :rule' => ':attribute长度不能超过 :rule',
'min size of :attribute must be :rule' => ':attribute长度不能小于 :rule',
':attribute cannot be less than :rule' => ':attribute日期不能小于 :rule',
':attribute cannot exceed :rule' => ':attribute日期不能超过 :rule',
':attribute not within :rule' => '不在有效期内 :rule',
'access IP is not allowed' => '不允许的IP访问',
'access IP denied' => '禁止的IP访问',
':attribute out of accord with :2' => ':attribute和确认字段:2不一致',
':attribute cannot be same with :2' => ':attribute和比较字段:2不能相同',
':attribute must greater than or equal :rule' => ':attribute必须大于等于 :rule',
':attribute must greater than :rule' => ':attribute必须大于 :rule',
':attribute must less than or equal :rule' => ':attribute必须小于等于 :rule',
':attribute must less than :rule' => ':attribute必须小于 :rule',
':attribute must equal :rule' => ':attribute必须等于 :rule',
':attribute must not be equal to :rule' => ':attribute不能等于 :rule',
':attribute has exists' => ':attribute已存在',
':attribute not conform to the rules' => ':attribute不符合指定规则',
':attribute must multiple :rule' => ':attribute必须是 :rule 的倍数',
'invalid Request method' => '无效的请求类型',
'invalid token' => '令牌数据无效',
'not conform to the rules' => '规则错误',
'record has update' => '记录已经被更新了',
];
@@ -0,0 +1,662 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2025 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
declare (strict_types = 1);
namespace think;
use Composer\InstalledVersions;
use think\event\AppInit;
use think\helper\Str;
use think\initializer\BootService;
use think\initializer\Error;
use think\initializer\RegisterService;
/**
* App 基础类
* @property Route $route
* @property Config $config
* @property Cache $cache
* @property Request $request
* @property Http $http
* @property Console $console
* @property Env $env
* @property Event $event
* @property Middleware $middleware
* @property Log $log
* @property Lang $lang
* @property Db $db
* @property Cookie $cookie
* @property Session $session
* @property Validate $validate
*/
class App extends Container
{
/**
* 核心框架版本
* @deprecated 已经废弃 请改用version()方法
*/
public const VERSION = '8.0.0';
/**
* 应用调试模式
* @var bool
*/
protected $appDebug = false;
/**
* 公共环境变量标识
* @var string
*/
protected $baseEnvName = '';
/**
* 环境变量标识
* @var string
*/
protected $envName = '';
/**
* 应用开始时间
* @var float
*/
protected $beginTime;
/**
* 应用内存初始占用
* @var int
*/
protected $beginMem;
/**
* 当前应用类库命名空间
* @var string
*/
protected $namespace = 'app';
/**
* 应用根目录
* @var string
*/
protected $rootPath = '';
/**
* 框架目录
* @var string
*/
protected $thinkPath = '';
/**
* 应用目录
* @var string
*/
protected $appPath = '';
/**
* Runtime目录
* @var string
*/
protected $runtimePath = '';
/**
* 路由定义目录
* @var string
*/
protected $routePath = '';
/**
* 配置后缀
* @var string
*/
protected $configExt = '.php';
/**
* 应用初始化器
* @var array
*/
protected $initializers = [
Error::class,
RegisterService::class,
BootService::class,
];
/**
* 注册的系统服务
* @var array
*/
protected $services = [];
/**
* 初始化
* @var bool
*/
protected $initialized = false;
/**
* 容器绑定标识
* @var array
*/
protected $bind = [
'app' => App::class,
'cache' => Cache::class,
'config' => Config::class,
'console' => Console::class,
'cookie' => Cookie::class,
'db' => Db::class,
'env' => Env::class,
'event' => Event::class,
'http' => Http::class,
'lang' => Lang::class,
'log' => Log::class,
'middleware' => Middleware::class,
'request' => Request::class,
'response' => Response::class,
'route' => Route::class,
'session' => Session::class,
'validate' => Validate::class,
'view' => View::class,
'think\DbManager' => Db::class,
'think\LogManager' => Log::class,
'think\CacheManager' => Cache::class,
// 接口依赖注入
'Psr\Log\LoggerInterface' => Log::class,
];
/**
* 架构方法
* @access public
* @param string $rootPath 应用根目录
*/
public function __construct(string $rootPath = '')
{
$this->thinkPath = realpath(dirname(__DIR__)) . DIRECTORY_SEPARATOR;
$this->rootPath = $rootPath ? rtrim($rootPath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR : $this->getDefaultRootPath();
$this->appPath = $this->rootPath . 'app' . DIRECTORY_SEPARATOR;
$this->runtimePath = $this->rootPath . 'runtime' . DIRECTORY_SEPARATOR;
if (is_file($this->appPath . 'provider.php')) {
$this->bind(include $this->appPath . 'provider.php');
}
static::setInstance($this);
$this->instance('app', $this);
$this->instance('think\Container', $this);
}
/**
* 注册服务
* @access public
* @param Service|string $service 服务
* @param bool $force 强制重新注册
* @return Service|null
*/
public function register(Service | string $service, bool $force = false)
{
$registered = $this->getService($service);
if ($registered && !$force) {
return $registered;
}
if (is_string($service)) {
$service = new $service($this);
}
if (method_exists($service, 'register')) {
$service->register();
}
if (property_exists($service, 'bind')) {
$this->bind($service->bind);
}
$this->services[] = $service;
}
/**
* 执行服务
* @access public
* @param Service $service 服务
* @return mixed
*/
public function bootService(Service $service)
{
if (method_exists($service, 'boot')) {
return $this->invoke([$service, 'boot']);
}
}
/**
* 获取服务
* @param string|Service $service
* @return Service|null
*/
public function getService(Service | string $service): ?Service
{
$name = is_string($service) ? $service : $service::class;
return array_values(array_filter($this->services, function ($value) use ($name) {
return $value instanceof $name;
}, ARRAY_FILTER_USE_BOTH))[0] ?? null;
}
/**
* 开启应用调试模式
* @access public
* @param bool $debug 开启应用调试模式
* @return $this
*/
public function debug(bool $debug = true)
{
$this->appDebug = $debug;
return $this;
}
/**
* 是否为调试模式
* @access public
* @return bool
*/
public function isDebug(): bool
{
return $this->appDebug;
}
/**
* 设置应用命名空间
* @access public
* @param string $namespace 应用命名空间
* @return $this
*/
public function setNamespace(string $namespace)
{
$this->namespace = $namespace;
return $this;
}
/**
* 获取应用类库命名空间
* @access public
* @return string
*/
public function getNamespace(): string
{
return $this->namespace;
}
/**
* 设置公共环境变量标识
* @access public
* @param string $name 环境标识
* @return $this
*/
public function setBaseEnvName(string $name)
{
$this->baseEnvName = $name;
return $this;
}
/**
* 设置环境变量标识
* @access public
* @param string $name 环境标识
* @return $this
*/
public function setEnvName(string $name)
{
$this->envName = $name;
return $this;
}
/**
* 获取框架版本
* @access public
* @return string
*/
public function version(): string
{
return ltrim(InstalledVersions::getPrettyVersion('topthink/framework'), 'v');
}
/**
* 获取应用根目录
* @access public
* @return string
*/
public function getRootPath(): string
{
return $this->rootPath;
}
/**
* 获取应用基础目录
* @access public
* @return string
*/
public function getBasePath(): string
{
return $this->rootPath . 'app' . DIRECTORY_SEPARATOR;
}
/**
* 获取当前应用目录
* @access public
* @return string
*/
public function getAppPath(): string
{
return $this->appPath;
}
/**
* 设置应用目录
* @param string $path 应用目录
*/
public function setAppPath(string $path)
{
$this->appPath = $path;
}
/**
* 获取应用运行时目录
* @access public
* @return string
*/
public function getRuntimePath(): string
{
return $this->runtimePath;
}
/**
* 设置runtime目录
* @param string $path 定义目录
*/
public function setRuntimePath(string $path): void
{
$this->runtimePath = $path;
}
/**
* 获取核心框架目录
* @access public
* @return string
*/
public function getThinkPath(): string
{
return $this->thinkPath;
}
/**
* 获取应用配置目录
* @access public
* @return string
*/
public function getConfigPath(): string
{
return $this->rootPath . 'config' . DIRECTORY_SEPARATOR;
}
/**
* 获取配置后缀
* @access public
* @return string
*/
public function getConfigExt(): string
{
return $this->configExt;
}
/**
* 获取应用开启时间
* @access public
* @return float
*/
public function getBeginTime(): float
{
return $this->beginTime;
}
/**
* 获取应用初始内存占用
* @access public
* @return int
*/
public function getBeginMem(): int
{
return $this->beginMem;
}
/**
* 加载环境变量定义
* @access public
* @param string $envName 环境标识
* @return void
*/
public function loadEnv(string $envName = ''): void
{
// 加载环境变量
$envFile = $envName ? $this->rootPath . '.env.' . $envName : $this->rootPath . '.env';
if (is_file($envFile)) {
$this->env->load($envFile);
}
}
/**
* 初始化应用
* @access public
* @return $this
*/
public function initialize()
{
$this->initialized = true;
$this->beginTime = microtime(true);
$this->beginMem = memory_get_usage();
// 加载环境变量
if ($this->baseEnvName) {
$this->loadEnv($this->baseEnvName);
}
$this->envName = $this->envName ?: (string) $this->env->get('env_name', '');
$this->loadEnv($this->envName);
$this->configExt = $this->env->get('config_ext', '.php');
$this->debugModeInit();
// 加载全局初始化文件
$this->load();
// 加载应用默认语言包
$this->loadLangPack();
// 监听AppInit
$this->event->trigger(AppInit::class);
date_default_timezone_set($this->config->get('app.default_timezone', 'Asia/Shanghai'));
// 初始化
foreach ($this->initializers as $initializer) {
$this->make($initializer)->init($this);
}
return $this;
}
/**
* 是否初始化过
* @return bool
*/
public function initialized()
{
return $this->initialized;
}
/**
* 加载语言包
* @return void
*/
public function loadLangPack(): void
{
// 加载默认语言包
$langSet = $this->lang->defaultLangSet();
$this->lang->switchLangSet($langSet);
}
/**
* 引导应用
* @access public
* @return void
*/
public function boot(): void
{
array_walk($this->services, function ($service) {
$this->bootService($service);
});
}
/**
* 加载应用文件和配置
* @access protected
* @return void
*/
protected function load(): void
{
$appPath = $this->getAppPath();
if (is_file($appPath . 'common.php')) {
include_once $appPath . 'common.php';
}
include_once $this->thinkPath . 'helper.php';
if (is_file($this->runtimePath . 'config.php')) {
$this->config->set(include $this->runtimePath . 'config.php');
} else {
$this->loadConfig();
}
if (is_file($appPath . 'event.php')) {
$this->loadEvent(include $appPath . 'event.php');
}
if (is_file($appPath . 'service.php')) {
$services = include $appPath . 'service.php';
foreach ($services as $service) {
$this->register($service);
}
}
}
/**
* 加载配置文件
* @return void
*/
public function loadConfig()
{
$configPath = $this->getConfigPath();
$files = [];
if (is_dir($configPath)) {
$files = glob($configPath . '*' . $this->configExt);
}
foreach ($files as $file) {
$this->config->load($file, pathinfo($file, PATHINFO_FILENAME));
}
}
/**
* 调试模式设置
* @access protected
* @return void
*/
protected function debugModeInit(): void
{
// 应用调试模式
if (!$this->appDebug) {
$this->appDebug = $this->env->get('app_debug') ? true : false;
}
if (!$this->appDebug) {
ini_set('display_errors', 'Off');
}
if (!$this->runningInConsole()) {
//重新申请一块比较大的buffer
if (ob_get_level() > 0) {
$output = ob_get_clean();
}
ob_start();
if (!empty($output)) {
echo $output;
}
}
}
/**
* 注册应用事件
* @access protected
* @param array $event 事件数据
* @return void
*/
public function loadEvent(array $event): void
{
if (isset($event['bind'])) {
$this->event->bind($event['bind']);
}
if (isset($event['listen'])) {
$this->event->listenEvents($event['listen']);
}
if (isset($event['subscribe'])) {
$this->event->subscribe($event['subscribe']);
}
}
/**
* 解析应用类的类名
* @access public
* @param string $layer 层名 controller model ...
* @param string $name 类名
* @return string
*/
public function parseClass(string $layer, string $name): string
{
$name = str_replace(['/', '.'], '\\', $name);
$array = explode('\\', $name);
$class = Str::studly(array_pop($array));
$path = $array ? implode('\\', $array) . '\\' : '';
return $this->namespace . '\\' . $layer . '\\' . $path . $class;
}
/**
* 是否运行在命令行下
* @return bool
*/
public function runningInConsole(): bool
{
return php_sapi_name() === 'cli' || php_sapi_name() === 'phpdbg';
}
/**
* 获取应用根目录
* @access protected
* @return string
*/
protected function getDefaultRootPath(): string
{
return dirname($this->thinkPath, 4) . DIRECTORY_SEPARATOR;
}
}
@@ -0,0 +1,200 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2025 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
declare(strict_types = 1);
namespace think;
use DateInterval;
use DateTimeInterface;
use Psr\SimpleCache\CacheInterface;
use think\cache\Driver;
use think\cache\TagSet;
use think\exception\InvalidArgumentException;
use think\helper\Arr;
/**
* 缓存管理类
* @mixin Driver
* @mixin \think\cache\driver\File
*/
class Cache extends Manager implements CacheInterface
{
protected $namespace = '\\think\\cache\\driver\\';
/**
* 默认驱动
* @return string|null
*/
public function getDefaultDriver(): ?string
{
return $this->getConfig('default');
}
/**
* 获取缓存配置
* @access public
* @param null|string $name 名称
* @param mixed $default 默认值
* @return mixed
*/
public function getConfig(?string $name = null, $default = null)
{
if (!is_null($name)) {
return $this->app->config->get('cache.' . $name, $default);
}
return $this->app->config->get('cache');
}
/**
* 获取驱动配置
* @param string $store
* @param string $name
* @param mixed $default
* @return array
*/
public function getStoreConfig(string $store, ?string $name = null, $default = null)
{
if ($config = $this->getConfig("stores.{$store}")) {
return Arr::get($config, $name, $default);
}
throw new \InvalidArgumentException("Store [$store] not found.");
}
protected function resolveType(string $name)
{
return $this->getStoreConfig($name, 'type', 'file');
}
protected function resolveConfig(string $name)
{
return $this->getStoreConfig($name);
}
/**
* 连接或者切换缓存
* @access public
* @param string|null $name 连接配置名
* @return Driver
*/
public function store(?string $name = null)
{
return $this->driver($name);
}
/**
* 清空缓冲池
* @access public
* @return bool
*/
public function clear(): bool
{
return $this->store()->clear();
}
/**
* 读取缓存
* @access public
* @param string $key 缓存变量名
* @param mixed $default 默认值
* @return mixed
*/
public function get($key, mixed $default = null): mixed
{
return $this->store()->get($key, $default);
}
/**
* 写入缓存
* @access public
* @param string $key 缓存变量名
* @param mixed $value 存储数据
* @param int|DateTimeInterface|DateInterval $ttl 有效时间 0为永久
* @return bool
*/
public function set($key, $value, $ttl = null): bool
{
return $this->store()->set($key, $value, $ttl);
}
/**
* 删除缓存
* @access public
* @param string $key 缓存变量名
* @return bool
*/
public function delete($key): bool
{
return $this->store()->delete($key);
}
/**
* 读取缓存
* @access public
* @param iterable $keys 缓存变量名
* @param mixed $default 默认值
* @return iterable
* @throws InvalidArgumentException
*/
public function getMultiple($keys, $default = null): iterable
{
return $this->store()->getMultiple($keys, $default);
}
/**
* 写入缓存
* @access public
* @param iterable $values 缓存数据
* @param null|int|\DateInterval $ttl 有效时间 0为永久
* @return bool
*/
public function setMultiple($values, $ttl = null): bool
{
return $this->store()->setMultiple($values, $ttl);
}
/**
* 删除缓存
* @access public
* @param iterable $keys 缓存变量名
* @return bool
* @throws InvalidArgumentException
*/
public function deleteMultiple($keys): bool
{
return $this->store()->deleteMultiple($keys);
}
/**
* 判断缓存是否存在
* @access public
* @param string $key 缓存变量名
* @return bool
*/
public function has($key): bool
{
return $this->store()->has($key);
}
/**
* 缓存标签
* @access public
* @param string|array $name 标签名
* @return TagSet
*/
public function tag($name)
{
return $this->store()->tag($name);
}
}
@@ -0,0 +1,218 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2025 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
declare (strict_types = 1);
namespace think;
use Closure;
/**
* 配置管理类
* @package think
*/
class Config
{
/**
* 配置参数
* @var array
*/
protected $config = [];
/**
* 注册配置获取器
* @var Closure[]
*/
protected $hook = [];
/**
* 构造方法
* @access public
*/
public function __construct(protected string $path = '', protected string $ext = '.php')
{
}
public static function __make(App $app)
{
$path = $app->getConfigPath();
$ext = $app->getConfigExt();
return new static($path, $ext);
}
/**
* 加载配置文件(多种格式)
* @access public
* @param string $file 配置文件名
* @param string $name 一级配置名
* @return array
*/
public function load(string $file, string $name = ''): array
{
if (is_file($file)) {
$filename = $file;
} elseif (is_file($this->path . $file . $this->ext)) {
$filename = $this->path . $file . $this->ext;
}
if (isset($filename)) {
return $this->parse($filename, $name);
}
return $this->config;
}
/**
* 解析配置文件
* @access public
* @param string $file 配置文件名
* @param string $name 一级配置名
* @return array
*/
protected function parse(string $file, string $name): array
{
$type = pathinfo($file, PATHINFO_EXTENSION);
$config = [];
$config = match ($type) {
'php' => include $file,
'yml', 'yaml' => function_exists('yaml_parse_file') ? yaml_parse_file($file) : [],
'ini' => parse_ini_file($file, true, INI_SCANNER_TYPED) ?: [],
'json' => json_decode(file_get_contents($file), true),
default => [],
};
return is_array($config) ? $this->set($config, strtolower($name)) : [];
}
/**
* 检测配置是否存在
* @access public
* @param string $name 配置参数名(支持多级配置 .号分割)
* @return bool
*/
public function has(string $name): bool
{
if (!str_contains($name, '.') && !isset($this->config[strtolower($name)])) {
return false;
}
return !is_null($this->get($name));
}
/**
* 获取一级配置
* @access protected
* @param string $name 一级配置名
* @return array
*/
protected function pull(string $name): array
{
return $this->config[$name] ?? [];
}
/**
* 注册配置获取器
* @access public
* @param Closure $callback
* @param string|null $key
* @return void
*/
public function hook(Closure $callback, ?string $key = null)
{
$this->hook[$key ?? 'global'] = $callback;
}
/**
* 获取配置参数 为空则获取所有配置
* @access public
* @param string $name 配置参数名(支持多级配置 .号分割)
* @param mixed $default 默认值
* @return mixed
*/
public function get(?string $name = null, $default = null)
{
// 无参数时获取所有
if (empty($name)) {
return $this->config;
}
if (!str_contains($name, '.')) {
$name = strtolower($name);
$result = $this->pull($name);
return $this->hook ? $this->lazy($name, $result, []) : $result;
}
$item = explode('.', $name);
$item[0] = strtolower($item[0]);
$config = $this->config;
foreach ($item as $val) {
if (isset($config[$val])) {
$config = $config[$val];
} else {
return $this->hook ? $this->lazy($name, null, $default) : $default;
}
}
return $this->hook ? $this->lazy($name, $config, $default) : $config;
}
/**
* 通过获取器加载配置
* @access public
* @param string $name 配置参数
* @param mixed $value 配置值
* @param mixed $default 默认值
* @return mixed
*/
protected function lazy(string $name, $value = null, $default = null)
{
// 通过获取器返回
$key = strpos($name, '.') ? strstr($name, '.', true) : $name;
if (isset($this->hook[$key])) {
$call = $this->hook[$key];
} elseif (isset($this->hook['global'])) {
$call = $this->hook['global'];
}
if (isset($call)) {
$result = call_user_func_array($call, [$name, $value]);
if (is_null($result)) {
return $default;
}
}
return $result ?? ($value ?: $default);
}
/**
* 设置配置参数 name为数组则为批量设置
* @access public
* @param array $config 配置参数
* @param string $name 配置名
* @return array
*/
public function set(array $config, ?string $name = null): array
{
if (empty($name)) {
$this->config = array_merge($this->config, array_change_key_case($config));
return $this->config;
}
if (isset($this->config[$name])) {
$result = array_merge($this->config[$name], $config);
} else {
$result = $config;
}
$this->config[$name] = $result;
return $result;
}
}
@@ -0,0 +1,790 @@
<?php
// +----------------------------------------------------------------------
// | TopThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2025 http://www.topthink.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: zhangyajun <448901948@qq.com>
// +----------------------------------------------------------------------
declare (strict_types = 1);
namespace think;
use Closure;
use InvalidArgumentException;
use LogicException;
use think\console\Command;
use think\console\command\Clear;
use think\console\command\Help;
use think\console\command\Help as HelpCommand;
use think\console\command\Lists;
use think\console\command\make\Command as MakeCommand;
use think\console\command\make\Controller;
use think\console\command\make\Event;
use think\console\command\make\Listener;
use think\console\command\make\Middleware;
use think\console\command\make\Model;
use think\console\command\make\Service;
use think\console\command\make\Subscribe;
use think\console\command\make\Validate;
use think\console\command\optimize\Config;
use think\console\command\optimize\Optimize;
use think\console\command\optimize\Route;
use think\console\command\optimize\Schema;
use think\console\command\RouteList;
use think\console\command\RunServer;
use think\console\command\ServiceDiscover;
use think\console\command\VendorPublish;
use think\console\command\Version;
use think\console\Input;
use think\console\input\Argument as InputArgument;
use think\console\input\Definition as InputDefinition;
use think\console\input\Option as InputOption;
use think\console\Output;
use think\console\output\driver\Buffer;
/**
* 控制台应用管理类
*/
class Console
{
/** @var Command[] */
protected $commands = [];
protected $wantHelps = false;
protected $catchExceptions = true;
protected $autoExit = true;
protected $definition;
protected $defaultCommand = 'list';
protected $defaultCommands = [
'help' => Help::class,
'list' => Lists::class,
'clear' => Clear::class,
'make:command' => MakeCommand::class,
'make:controller' => Controller::class,
'make:model' => Model::class,
'make:middleware' => Middleware::class,
'make:validate' => Validate::class,
'make:event' => Event::class,
'make:listener' => Listener::class,
'make:service' => Service::class,
'make:subscribe' => Subscribe::class,
'optimize' => Optimize::class,
'optimize:config' => Config::class,
'optimize:route' => Route::class,
'optimize:schema' => Schema::class,
'run' => RunServer::class,
'version' => Version::class,
'route:list' => RouteList::class,
'service:discover' => ServiceDiscover::class,
'vendor:publish' => VendorPublish::class,
];
/**
* 启动器
* @var array
*/
protected static $startCallbacks = [];
public function __construct(protected App $app)
{
$this->initialize();
$this->definition = $this->getDefaultInputDefinition();
//加载指令
$this->loadCommands();
// 设置执行用户
$user = $this->app->config->get('console.user');
if (!empty($user)) {
$this->setUser($user);
}
$this->start();
}
/**
* 初始化
*/
protected function initialize():void
{
if (!$this->app->initialized()) {
$this->app->initialize();
}
$this->makeRequest();
}
/**
* 构造request
*/
protected function makeRequest():void
{
$url = $this->app->config->get('app.url', 'http://localhost');
$components = parse_url($url);
$server = $_SERVER;
if (isset($components['path'])) {
$server = array_merge($server, [
'SCRIPT_FILENAME' => $components['path'],
'SCRIPT_NAME' => $components['path'],
'REQUEST_URI' => $components['path'],
]);
}
if (isset($components['host'])) {
$server['SERVER_NAME'] = $components['host'];
$server['HTTP_HOST'] = $components['host'];
}
if (isset($components['scheme'])) {
if ('https' === $components['scheme']) {
$server['HTTPS'] = 'on';
$server['SERVER_PORT'] = 443;
} else {
unset($server['HTTPS']);
$server['SERVER_PORT'] = 80;
}
}
if (isset($components['port'])) {
$server['SERVER_PORT'] = $components['port'];
$server['HTTP_HOST'] .= ':' . $components['port'];
}
/** @var Request $request */
$request = $this->app->make('request');
$request->withServer($server);
}
/**
* 添加初始化器
* @param Closure $callback
*/
public static function starting(Closure $callback): void
{
static::$startCallbacks[] = $callback;
}
/**
* 清空启动器
*/
public static function flushStartCallbacks(): void
{
static::$startCallbacks = [];
}
/**
* 设置执行用户
* @param $user
*/
public static function setUser(string $user): void
{
if (extension_loaded('posix')) {
$user = posix_getpwnam($user);
if (!empty($user)) {
posix_setgid($user['gid']);
posix_setuid($user['uid']);
}
}
}
/**
* 启动
*/
protected function start(): void
{
foreach (static::$startCallbacks as $callback) {
$callback($this);
}
}
/**
* 加载指令
* @access protected
*/
protected function loadCommands(): void
{
$commands = $this->app->config->get('console.commands', []);
$commands = array_merge($this->defaultCommands, $commands);
$this->addCommands($commands);
}
/**
* @access public
* @param string $command
* @param array $parameters
* @param string $driver
* @return Output|Buffer
*/
public function call(string $command, array $parameters = [], string $driver = 'buffer')
{
array_unshift($parameters, $command);
$input = new Input($parameters);
$output = new Output($driver);
$this->setCatchExceptions(false);
$this->find($command)->run($input, $output);
return $output;
}
/**
* 执行当前的指令
* @access public
* @return int
* @throws \Exception
* @api
*/
public function run()
{
$input = new Input();
$output = new Output();
$this->configureIO($input, $output);
try {
$exitCode = $this->doRun($input, $output);
} catch (\Exception $e) {
if (!$this->catchExceptions) {
throw $e;
}
$output->renderException($e);
$exitCode = $e->getCode();
if (is_numeric($exitCode)) {
$exitCode = (int) $exitCode;
if (0 === $exitCode) {
$exitCode = 1;
}
} else {
$exitCode = 1;
}
}
if ($this->autoExit) {
if ($exitCode > 255) {
$exitCode = 255;
}
exit($exitCode);
}
return $exitCode;
}
/**
* 执行指令
* @access public
* @param Input $input
* @param Output $output
* @return int
*/
public function doRun(Input $input, Output $output)
{
if (true === $input->hasParameterOption(['--version', '-V'])) {
$output->writeln($this->getLongVersion());
return 0;
}
$name = $this->getCommandName($input);
if (true === $input->hasParameterOption(['--help', '-h'])) {
if (!$name) {
$name = 'help';
$input = new Input(['help']);
} else {
$this->wantHelps = true;
}
}
if (!$name) {
$name = $this->defaultCommand;
$input = new Input([$this->defaultCommand]);
}
$command = $this->find($name);
return $this->doRunCommand($command, $input, $output);
}
/**
* 设置输入参数定义
* @access public
* @param InputDefinition $definition
*/
public function setDefinition(InputDefinition $definition): void
{
$this->definition = $definition;
}
/**
* 获取输入参数定义
* @access public
* @return InputDefinition The InputDefinition instance
*/
public function getDefinition(): InputDefinition
{
return $this->definition;
}
/**
* Gets the help message.
* @access public
* @return string A help message.
*/
public function getHelp(): string
{
return $this->getLongVersion();
}
/**
* 是否捕获异常
* @access public
* @param bool $boolean
* @api
*/
public function setCatchExceptions(bool $boolean): void
{
$this->catchExceptions = $boolean;
}
/**
* 是否自动退出
* @access public
* @param bool $boolean
* @api
*/
public function setAutoExit(bool $boolean): void
{
$this->autoExit = $boolean;
}
/**
* 获取完整的版本号
* @access public
* @return string
*/
public function getLongVersion(): string
{
if ($this->app->version()) {
return sprintf('version <comment>%s</comment>', $this->app->version());
}
return '<info>Console Tool</info>';
}
/**
* 添加指令集
* @access public
* @param array $commands
*/
public function addCommands(array $commands): void
{
foreach ($commands as $key => $command) {
if (is_subclass_of($command, Command::class)) {
// 注册指令
$this->addCommand($command, is_numeric($key) ? '' : $key);
}
}
}
/**
* 添加一个指令
* @access public
* @param string|Command $command 指令对象或者指令类名
* @param string $name 指令名 留空则自动获取
* @return Command|void
*/
public function addCommand(string|Command $command, string $name = '')
{
if ($name) {
$this->commands[$name] = $command;
return;
}
if (is_string($command)) {
$command = $this->app->invokeClass($command);
}
$command->setConsole($this);
if (!$command->isEnabled()) {
$command->setConsole(null);
return;
}
$command->setApp($this->app);
if (null === $command->getDefinition()) {
throw new LogicException(sprintf('Command class "%s" is not correctly initialized. You probably forgot to call the parent constructor.', $command::class));
}
$this->commands[$command->getName()] = $command;
foreach ($command->getAliases() as $alias) {
$this->commands[$alias] = $command;
}
return $command;
}
/**
* 获取指令
* @access public
* @param string $name 指令名称
* @return Command
* @throws InvalidArgumentException
*/
public function getCommand(string $name): Command
{
if (!isset($this->commands[$name])) {
throw new InvalidArgumentException(sprintf('The command "%s" does not exist.', $name));
}
$command = $this->commands[$name];
if (is_string($command)) {
$command = $this->app->invokeClass($command);
/** @var Command $command */
$command->setConsole($this);
$command->setApp($this->app);
}
if ($this->wantHelps) {
$this->wantHelps = false;
/** @var HelpCommand $helpCommand */
$helpCommand = $this->getCommand('help');
$helpCommand->setCommand($command);
return $helpCommand;
}
return $command;
}
/**
* 某个指令是否存在
* @access public
* @param string $name 指令名称
* @return bool
*/
public function hasCommand(string $name): bool
{
return isset($this->commands[$name]);
}
/**
* 获取所有的命名空间
* @access public
* @return array
*/
public function getNamespaces(): array
{
$namespaces = [];
foreach ($this->commands as $key => $command) {
if (is_string($command)) {
$namespaces = array_merge($namespaces, $this->extractAllNamespaces($key));
} else {
$namespaces = array_merge($namespaces, $this->extractAllNamespaces($command->getName()));
foreach ($command->getAliases() as $alias) {
$namespaces = array_merge($namespaces, $this->extractAllNamespaces($alias));
}
}
}
return array_values(array_unique(array_filter($namespaces)));
}
/**
* 查找注册命名空间中的名称或缩写。
* @access public
* @param string $namespace
* @return string
* @throws InvalidArgumentException
*/
public function findNamespace(string $namespace): string
{
$allNamespaces = $this->getNamespaces();
$expr = preg_replace_callback('{([^:]+|)}', function ($matches) {
return preg_quote($matches[1]) . '[^:]*';
}, $namespace);
$namespaces = preg_grep('{^' . $expr . '}', $allNamespaces);
if (empty($namespaces)) {
$message = sprintf('There are no commands defined in the "%s" namespace.', $namespace);
if ($alternatives = $this->findAlternatives($namespace, $allNamespaces)) {
if (1 == count($alternatives)) {
$message .= "\n\nDid you mean this?\n ";
} else {
$message .= "\n\nDid you mean one of these?\n ";
}
$message .= implode("\n ", $alternatives);
}
throw new InvalidArgumentException($message);
}
$exact = in_array($namespace, $namespaces, true);
if (count($namespaces) > 1 && !$exact) {
throw new InvalidArgumentException(sprintf('The namespace "%s" is ambiguous (%s).', $namespace, $this->getAbbreviationSuggestions(array_values($namespaces))));
}
return $exact ? $namespace : reset($namespaces);
}
/**
* 查找指令
* @access public
* @param string $name 名称或者别名
* @return Command
* @throws InvalidArgumentException
*/
public function find(string $name): Command
{
$allCommands = array_keys($this->commands);
$expr = preg_replace_callback('{([^:]+|)}', function ($matches) {
return preg_quote($matches[1]) . '[^:]*';
}, $name);
$commands = preg_grep('{^' . $expr . '}', $allCommands);
if (empty($commands) || count(preg_grep('{^' . $expr . '$}', $commands)) < 1) {
if (false !== $pos = strrpos($name, ':')) {
$this->findNamespace(substr($name, 0, $pos));
}
$message = sprintf('Command "%s" is not defined.', $name);
if ($alternatives = $this->findAlternatives($name, $allCommands)) {
if (1 == count($alternatives)) {
$message .= "\n\nDid you mean this?\n ";
} else {
$message .= "\n\nDid you mean one of these?\n ";
}
$message .= implode("\n ", $alternatives);
}
throw new InvalidArgumentException($message);
}
$exact = in_array($name, $commands, true);
if (count($commands) > 1 && !$exact) {
$suggestions = $this->getAbbreviationSuggestions(array_values($commands));
throw new InvalidArgumentException(sprintf('Command "%s" is ambiguous (%s).', $name, $suggestions));
}
return $this->getCommand($exact ? $name : reset($commands));
}
/**
* 获取所有的指令
* @access public
* @param string $namespace 命名空间
* @return Command[]
* @api
*/
public function all(?string $namespace = null): array
{
if (null === $namespace) {
return $this->commands;
}
$commands = [];
foreach ($this->commands as $name => $command) {
if ($this->extractNamespace($name, substr_count($namespace, ':') + 1) === $namespace) {
$commands[$name] = $command;
}
}
return $commands;
}
/**
* 配置基于用户的参数和选项的输入和输出实例。
* @access protected
* @param Input $input 输入实例
* @param Output $output 输出实例
*/
protected function configureIO(Input $input, Output $output): void
{
if (true === $input->hasParameterOption(['--ansi'])) {
$output->setDecorated(true);
} elseif (true === $input->hasParameterOption(['--no-ansi'])) {
$output->setDecorated(false);
}
if (true === $input->hasParameterOption(['--no-interaction', '-n'])) {
$input->setInteractive(false);
}
if (true === $input->hasParameterOption(['--quiet', '-q'])) {
$output->setVerbosity(Output::VERBOSITY_QUIET);
} elseif ($input->hasParameterOption('-vvv') || $input->hasParameterOption('--verbose=3') || $input->getParameterOption('--verbose') === 3) {
$output->setVerbosity(Output::VERBOSITY_DEBUG);
} elseif ($input->hasParameterOption('-vv') || $input->hasParameterOption('--verbose=2') || $input->getParameterOption('--verbose') === 2) {
$output->setVerbosity(Output::VERBOSITY_VERY_VERBOSE);
} elseif ($input->hasParameterOption('-v') || $input->hasParameterOption('--verbose=1') || $input->hasParameterOption('--verbose') || $input->getParameterOption('--verbose')) {
$output->setVerbosity(Output::VERBOSITY_VERBOSE);
}
}
/**
* 执行指令
* @access protected
* @param Command $command 指令实例
* @param Input $input 输入实例
* @param Output $output 输出实例
* @return int
* @throws \Exception
*/
protected function doRunCommand(Command $command, Input $input, Output $output)
{
return $command->run($input, $output);
}
/**
* 获取指令的基础名称
* @access protected
* @param Input $input
* @return string
*/
protected function getCommandName(Input $input): string
{
return $input->getFirstArgument() ?: '';
}
/**
* 获取默认输入定义
* @access protected
* @return InputDefinition
*/
protected function getDefaultInputDefinition(): InputDefinition
{
return new InputDefinition([
new InputArgument('command', InputArgument::REQUIRED, 'The command to execute'),
new InputOption('--help', '-h', InputOption::VALUE_NONE, 'Display this help message'),
new InputOption('--version', '-V', InputOption::VALUE_NONE, 'Display this console version'),
new InputOption('--quiet', '-q', InputOption::VALUE_NONE, 'Do not output any message'),
new InputOption('--verbose', '-v|vv|vvv', InputOption::VALUE_NONE, 'Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug'),
new InputOption('--ansi', '', InputOption::VALUE_NONE, 'Force ANSI output'),
new InputOption('--no-ansi', '', InputOption::VALUE_NONE, 'Disable ANSI output'),
new InputOption('--no-interaction', '-n', InputOption::VALUE_NONE, 'Do not ask any interactive question'),
]);
}
/**
* 获取可能的建议
* @access private
* @param array $abbrevs
* @return string
*/
private function getAbbreviationSuggestions(array $abbrevs): string
{
return sprintf('%s, %s%s', $abbrevs[0], $abbrevs[1], count($abbrevs) > 2 ? sprintf(' and %d more', count($abbrevs) - 2) : '');
}
/**
* 返回命名空间部分
* @access public
* @param string $name 指令
* @param int $limit 部分的命名空间的最大数量
* @return string
*/
public function extractNamespace(string $name, int $limit = 0): string
{
$parts = explode(':', $name);
array_pop($parts);
return implode(':', 0 === $limit ? $parts : array_slice($parts, 0, $limit));
}
/**
* 查找可替代的建议
* @access private
* @param string $name
* @param array|\Traversable $collection
* @return array
*/
private function findAlternatives(string $name, array|\Traversable $collection): array
{
$threshold = 1e3;
$alternatives = [];
$collectionParts = [];
foreach ($collection as $item) {
$collectionParts[$item] = explode(':', $item);
}
foreach (explode(':', $name) as $i => $subname) {
foreach ($collectionParts as $collectionName => $parts) {
$exists = isset($alternatives[$collectionName]);
if (!isset($parts[$i]) && $exists) {
$alternatives[$collectionName] += $threshold;
continue;
} elseif (!isset($parts[$i])) {
continue;
}
$lev = levenshtein($subname, $parts[$i]);
if ($lev <= strlen($subname) / 3 || '' !== $subname && str_contains($parts[$i], $subname)) {
$alternatives[$collectionName] = $exists ? $alternatives[$collectionName] + $lev : $lev;
} elseif ($exists) {
$alternatives[$collectionName] += $threshold;
}
}
}
foreach ($collection as $item) {
$lev = levenshtein($name, $item);
if ($lev <= strlen($name) / 3 || str_contains($item, $name)) {
$alternatives[$item] = isset($alternatives[$item]) ? $alternatives[$item] - $lev : $lev;
}
}
$alternatives = array_filter($alternatives, function ($lev) use ($threshold) {
return $lev < 2 * $threshold;
});
asort($alternatives);
return array_keys($alternatives);
}
/**
* 返回所有的命名空间
* @access private
* @param string $name
* @return array
*/
private function extractAllNamespaces(string $name): array
{
$parts = explode(':', $name, -1);
$namespaces = [];
foreach ($parts as $part) {
if (count($namespaces)) {
$namespaces[] = end($namespaces) . ':' . $part;
} else {
$namespaces[] = $part;
}
}
return $namespaces;
}
}
@@ -0,0 +1,223 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2025 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace think;
use DateTimeInterface;
/**
* Cookie管理类
* @package think
*/
class Cookie
{
/**
* 配置参数
* @var array
*/
protected $config = [
// cookie 保存时间
'expire' => 0,
// cookie 保存路径
'path' => '/',
// cookie 有效域名
'domain' => '',
// cookie 启用安全传输
'secure' => false,
// httponly设置
'httponly' => false,
// samesite 设置,支持 'strict' 'lax'
'samesite' => '',
];
/**
* Cookie写入数据
* @var array
*/
protected $cookie = [];
/**
* 构造方法
* @access public
*/
public function __construct(protected Request $request, array $config = [])
{
$this->config = array_merge($this->config, array_change_key_case($config));
}
public static function __make(Request $request, Config $config)
{
return new static($request, $config->get('cookie'));
}
/**
* 获取cookie
* @access public
* @param mixed $name 数据名称
* @param string $default 默认值
* @return mixed
*/
public function get(string $name = '', $default = null)
{
return $this->request->cookie($name, $default);
}
/**
* 是否存在Cookie参数
* @access public
* @param string $name 变量名
* @return bool
*/
public function has(string $name): bool
{
return $this->request->has($name, 'cookie');
}
/**
* Cookie 设置
*
* @access public
* @param string $name cookie名称
* @param string $value cookie值
* @param mixed $option 可选参数
* @return void
*/
public function set(string $name, string $value, $option = null): void
{
// 参数设置(会覆盖黙认设置)
if (!is_null($option)) {
if (is_numeric($option) || $option instanceof DateTimeInterface) {
$option = ['expire' => $option];
}
$config = array_merge($this->config, array_change_key_case($option));
} else {
$config = $this->config;
}
if ($config['expire'] instanceof DateTimeInterface) {
$expire = $config['expire']->getTimestamp();
} else {
$expire = !empty($config['expire']) ? time() + intval($config['expire']) : 0;
}
$this->setCookie($name, $value, $expire, $config);
$this->request->setCookie($name, $value);
}
/**
* Cookie 保存
*
* @access public
* @param string $name cookie名称
* @param string $value cookie值
* @param int $expire 有效期
* @param array $option 可选参数
* @return void
*/
protected function setCookie(string $name, string $value, int $expire, array $option = []): void
{
$this->cookie[$name] = [$value, $expire, $option];
}
/**
* 永久保存Cookie数据
* @access public
* @param string $name cookie名称
* @param string $value cookie值
* @param mixed $option 可选参数 可能会是 null|int|string
* @return void
*/
public function forever(string $name, string $value = '', $option = null): void
{
if (is_null($option) || is_numeric($option)) {
$option = [];
}
$option['expire'] = 315360000;
$this->set($name, $value, $option);
}
/**
* Cookie删除
* @access public
* @param string $name cookie名称
* @param array $options cookie参数
* @return void
*/
public function delete(string $name, array $options = []): void
{
$config = array_merge($this->config, array_change_key_case($options));
$this->setCookie($name, '', time() - 3600, $config);
$this->request->setCookie($name, null);
}
/**
* 获取cookie保存数据
* @access public
* @return array
*/
public function getCookie(): array
{
return $this->cookie;
}
/**
* 保存Cookie
* @access public
* @return void
*/
public function save(): void
{
foreach ($this->cookie as $name => $val) {
[$value, $expire, $option] = $val;
$this->saveCookie(
(string) $name,
$value,
$expire,
$option['path'],
$option['domain'],
(bool) $option['secure'],
(bool) $option['httponly'],
$option['samesite'],
);
}
}
/**
* 保存Cookie
* @access public
* @param string $name cookie名称
* @param string $value cookie值
* @param int $expire cookie过期时间
* @param string $path 有效的服务器路径
* @param string $domain 有效域名/子域名
* @param bool $secure 是否仅仅通过HTTPS
* @param bool $httponly 仅可通过HTTP访问
* @param string $samesite 防止CSRF攻击和用户追踪
* @return void
*/
protected function saveCookie(string $name, string $value, int $expire, string $path, string $domain, bool $secure, bool $httponly, string $samesite): void
{
setcookie($name, $value, [
'expires' => $expire,
'path' => $path,
'domain' => $domain,
'secure' => $secure,
'httponly' => $httponly,
'samesite' => $samesite,
]);
}
}
@@ -0,0 +1,117 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2025 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
declare(strict_types=1);
namespace think;
/**
* 数据库管理类
* @package think
* @property Config $config
*/
class Db extends DbManager
{
/**
* @param Event $event
* @param Config $config
* @param Log $log
* @param Cache $cache
* @return Db
* @codeCoverageIgnore
*/
public static function __make(Event $event, Config $config, Log $log, Cache $cache)
{
$db = new static();
$db->setConfig($config);
$db->setEvent($event);
$db->setLog($log);
$store = $db->getConfig('cache_store');
$db->setCache($cache->store($store));
$db->triggerSql();
return $db;
}
/**
* 注入模型对象
* @access public
* @return void
*/
protected function modelMaker(): void
{
}
/**
* 设置配置对象
* @access public
* @param Config $config 配置对象
* @return void
*/
public function setConfig($config): void
{
$this->config = $config;
}
/**
* 获取配置参数
* @access public
* @param string $name 配置参数
* @param mixed $default 默认值
* @return mixed
*/
public function getConfig(string $name = '', $default = null)
{
if ('' !== $name) {
return $this->config->get('database.' . $name, $default);
}
return $this->config->get('database', []);
}
/**
* 设置Event对象
* @param Event $event
*/
public function setEvent(Event $event): void
{
$this->event = $event;
}
/**
* 注册回调方法
* @access public
* @param string $event 事件名
* @param callable $callback 回调方法
* @return void
*/
public function event(string $event, callable $callback): void
{
if ($this->event) {
$this->event->listen('db.' . $event, $callback);
}
}
/**
* 触发事件
* @access public
* @param string $event 事件名
* @param mixed $params 传入参数
* @param bool $once
* @return mixed
*/
public function trigger(string $event, $params = null, bool $once = false)
{
if ($this->event) {
return $this->event->trigger('db.' . $event, $params, $once);
}
}
}
@@ -0,0 +1,199 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2025 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
declare(strict_types=1);
namespace think;
use ArrayAccess;
/**
* Env管理类
* @package think
*/
class Env implements ArrayAccess
{
/**
* 环境变量数据
* @var array
*/
protected $data = [];
/**
* 数据转换映射
* @var array
*/
protected $convert = [
'true' => true,
'false' => false,
'off' => false,
'on' => true,
];
public function __construct()
{
$this->data = $_ENV;
}
/**
* 读取环境变量定义文件
* @access public
* @param string $file 环境变量定义文件
* @return void
*/
public function load(string $file): void
{
$env = parse_ini_file($file, true, INI_SCANNER_RAW) ?: [];
$this->set($env);
}
/**
* 获取环境变量值
* @access public
* @param string $name 环境变量名
* @param mixed $default 默认值
* @return mixed
*/
public function get(?string $name = null, $default = null)
{
if (is_null($name)) {
return $this->data;
}
$name = strtoupper(str_replace('.', '_', $name));
if (isset($this->data[$name])) {
$result = $this->data[$name];
if (is_string($result) && isset($this->convert[$result])) {
return $this->convert[$result];
}
return $result;
}
return $this->getEnv($name, $default);
}
protected function getEnv(string $name, $default = null)
{
$result = getenv('PHP_' . $name);
if (false === $result) {
return $default;
}
if (isset($this->convert[$result])) {
$result = $this->convert[$result];
}
if (!isset($this->data[$name])) {
$this->data[$name] = $result;
}
return $result;
}
/**
* 设置环境变量值
* @access public
* @param string|array $env 环境变量
* @param mixed $value 值
* @return void
*/
public function set($env, $value = null): void
{
if (is_array($env)) {
$env = array_change_key_case($env, CASE_UPPER);
foreach ($env as $key => $val) {
if (is_array($val)) {
foreach ($val as $k => $v) {
if (is_string($k)) {
$this->data[$key . '_' . strtoupper($k)] = $v;
} else {
$this->data[$key][$k] = $v;
}
}
} else {
$this->data[$key] = $val;
}
}
} else {
$name = strtoupper(str_replace('.', '_', $env));
$this->data[$name] = $value;
}
}
/**
* 检测是否存在环境变量
* @access public
* @param string $name 参数名
* @return bool
*/
public function has(string $name): bool
{
return !is_null($this->get($name));
}
/**
* 设置环境变量
* @access public
* @param string $name 参数名
* @param mixed $value 值
*/
public function __set(string $name, $value): void
{
$this->set($name, $value);
}
/**
* 获取环境变量
* @access public
* @param string $name 参数名
* @return mixed
*/
public function __get(string $name)
{
return $this->get($name);
}
/**
* 检测是否存在环境变量
* @access public
* @param string $name 参数名
* @return bool
*/
public function __isset(string $name): bool
{
return $this->has($name);
}
// ArrayAccess
public function offsetSet(mixed $name, mixed $value): void
{
$this->set($name, $value);
}
public function offsetExists(mixed $name): bool
{
return $this->__isset($name);
}
public function offsetUnset(mixed $name): void
{
throw new Exception('not support: unset');
}
public function offsetGet(mixed $name): mixed
{
return $this->get($name);
}
}
@@ -0,0 +1,296 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2025 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
declare (strict_types = 1);
namespace think;
use ReflectionClass;
use ReflectionMethod;
use think\helper\Str;
/**
* 事件管理类
* @package think
*/
class Event
{
/**
* 监听者
* @var array
*/
protected $listener = [];
/**
* 观察者
* @var array
*/
protected $observer = [];
/**
* 事件别名
* @var array
*/
protected $bind = [
'AppInit' => event\AppInit::class,
'HttpRun' => event\HttpRun::class,
'HttpEnd' => event\HttpEnd::class,
'RouteLoaded' => event\RouteLoaded::class,
'LogWrite' => event\LogWrite::class,
'LogRecord' => event\LogRecord::class,
];
/**
* 应用对象
* @var App
*/
protected $app;
public function __construct(App $app)
{
$this->app = $app;
}
/**
* 批量注册事件监听
* @access public
* @param array $events 事件定义
* @return $this
*/
public function listenEvents(array $events)
{
foreach ($events as $event => $listeners) {
if (isset($this->bind[$event])) {
$event = $this->bind[$event];
}
$this->listener[$event] = array_merge($this->listener[$event] ?? [], $listeners);
}
return $this;
}
/**
* 注册事件监听
* @access public
* @param string $event 事件名称
* @param mixed $listener 监听操作(或者类名)
* @param bool $first 是否优先执行
* @return $this
*/
public function listen(string $event, $listener, bool $first = false)
{
if (isset($this->bind[$event])) {
$event = $this->bind[$event];
}
if ($first && isset($this->listener[$event])) {
array_unshift($this->listener[$event], $listener);
} else {
$this->listener[$event][] = $listener;
}
return $this;
}
/**
* 是否存在事件监听
* @access public
* @param string $event 事件名称
* @return bool
*/
public function hasListener(string $event): bool
{
if (isset($this->bind[$event])) {
$event = $this->bind[$event];
}
return isset($this->listener[$event]);
}
/**
* 移除事件监听
* @access public
* @param string $event 事件名称
* @return void
*/
public function remove(string $event): void
{
if (isset($this->bind[$event])) {
$event = $this->bind[$event];
}
unset($this->listener[$event]);
}
/**
* 指定事件别名标识 便于调用
* @access public
* @param array $events 事件别名
* @return $this
*/
public function bind(array $events)
{
$this->bind = array_merge($this->bind, $events);
return $this;
}
/**
* 注册事件订阅者
* @access public
* @param mixed $subscriber 订阅者
* @return $this
*/
public function subscribe($subscriber)
{
$subscribers = is_object($subscriber) ? [$subscriber] : (array) $subscriber;
foreach ($subscribers as $name => $subscriber) {
if (is_string($subscriber)) {
$subscriber = $this->app->make($subscriber);
}
if (method_exists($subscriber, 'subscribe')) {
// 手动订阅
$subscriber->subscribe($this);
} elseif (!is_numeric($name)) {
// 注册观察者
$this->observer[$name] = $subscriber;
} else {
// 智能订阅
$this->observe($subscriber);
}
}
return $this;
}
/**
* 自动注册事件监听
* @access public
* @param string|object $observer 观察者
* @param null|string $prefix 事件名前缀
* @return $this
*/
public function observe($observer, string $prefix = '')
{
if (is_string($observer)) {
$observer = $this->app->make($observer);
}
$reflect = new ReflectionClass($observer);
$methods = $reflect->getMethods(ReflectionMethod::IS_PUBLIC);
if (empty($prefix) && $reflect->hasProperty('eventPrefix')) {
$reflectProperty = $reflect->getProperty('eventPrefix');
if (PHP_VERSION_ID < 80100) {
// 8.0 版本时调用
$reflectProperty->setAccessible(true);
}
$prefix = $reflectProperty->getValue($observer);
}
foreach ($methods as $method) {
$name = $method->getName();
if (str_starts_with($name, 'on')) {
$this->listen($prefix . substr($name, 2), [$observer, $name]);
}
}
return $this;
}
/**
* 触发事件
* @access public
* @param string|object $event 事件名称
* @param mixed $params 传入参数
* @param bool $once 只获取一个有效返回值
* @return mixed
*/
public function trigger($event, $params = null, bool $once = false)
{
if (is_object($event)) {
$params = $event;
$event = $event::class;
}
if (isset($this->bind[$event])) {
$event = $this->bind[$event];
}
$result = [];
$listeners = $this->listener[$event] ?? [];
if (str_contains($event, '.')) {
[$prefix, $name] = explode('.', $event, 2);
if (isset($this->observer[$prefix])) {
// 检查观察者事件响应方法
$observer = $this->observer[$prefix];
$method = 'on' . Str::studly($name);
if (method_exists($observer, $method)) {
return $this->dispatch([$observer, $method], $params);
}
}
$name = substr($event, 0, strrpos($event, '.'));
if (isset($this->listener[$name . '.*'])) {
$listeners = array_merge($listeners, $this->listener[$name . '.*']);
}
}
$listeners = array_unique($listeners, SORT_REGULAR);
foreach ($listeners as $key => $listener) {
$result[$key] = $this->dispatch($listener, $params);
if (false === $result[$key] || (!is_null($result[$key]) && $once)) {
break;
}
}
return $once ? end($result) : $result;
}
/**
* 触发事件(只获取一个有效返回值)
* @param $event
* @param null $params
* @return mixed
*/
public function until($event, $params = null)
{
return $this->trigger($event, $params, true);
}
/**
* 执行事件调度
* @access protected
* @param mixed $event 事件方法
* @param mixed $params 参数
* @return mixed
*/
protected function dispatch($event, $params = null)
{
if (!is_string($event)) {
$call = $event;
} elseif (str_contains($event, '::')) {
$call = $event;
} else {
$obj = $this->app->make($event);
$call = [$obj, 'handle'];
}
return $this->app->invoke($call, [$params]);
}
}
@@ -0,0 +1,59 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2025 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://zjzit.cn>
// +----------------------------------------------------------------------
declare(strict_types=1);
namespace think;
/**
* 异常基础类
* @package think
*/
class Exception extends \Exception
{
/**
* 保存异常页面显示的额外Debug数据
* @var array
*/
protected $data = [];
/**
* 设置异常额外的Debug数据
* 数据将会显示为下面的格式
*
* Exception Data
* --------------------------------------------------
* Label 1
* key1 value1
* key2 value2
* Label 2
* key1 value1
* key2 value2
*
* @access protected
* @param string $label 数据分类,用于异常页面显示
* @param array $data 需要显示的数据,必须为关联数组
*/
final protected function setData(string $label, array $data)
{
$this->data[$label] = $data;
}
/**
* 获取异常额外Debug数据
* 主要用于输出到异常页面便于调试
* @access public
* @return array 由setData设置的Debug数据
*/
final public function getData(): array
{
return $this->data;
}
}
@@ -0,0 +1,198 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2025 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
declare(strict_types=1);
namespace think;
use SplFileInfo;
use Closure;
use think\exception\FileException;
/**
* 文件上传类
* @package think
*/
class File extends SplFileInfo
{
/**
* 文件hash规则
* @var array
*/
protected $hash = [];
protected $hashName;
/**
* 保存的文件后缀
* @var string
*/
protected $extension;
public function __construct(string $path, bool $checkPath = true)
{
if ($checkPath && !is_file($path)) {
throw new FileException(sprintf('The file "%s" does not exist', $path));
}
parent::__construct($path);
}
/**
* 获取文件的哈希散列值
* @access public
* @param string $type
* @return string
*/
public function hash(string $type = 'sha1'): string
{
if (!isset($this->hash[$type])) {
$this->hash[$type] = hash_file($type, $this->getPathname());
}
return $this->hash[$type];
}
/**
* 获取文件的MD5值
* @access public
* @return string
*/
public function md5(): string
{
return $this->hash('md5');
}
/**
* 获取文件的SHA1值
* @access public
* @return string
*/
public function sha1(): string
{
return $this->hash('sha1');
}
/**
* 获取文件类型信息
* @access public
* @return string
*/
public function getMime(): string
{
$finfo = finfo_open(FILEINFO_MIME_TYPE);
return finfo_file($finfo, $this->getPathname());
}
/**
* 移动文件
* @access public
* @param string $directory 保存路径
* @param string|null $name 保存的文件名
* @return File
*/
public function move(string $directory, ?string $name = null): File
{
$target = $this->getTargetFile($directory, $name);
set_error_handler(function ($type, $msg) use (&$error) {
$error = $msg;
});
$renamed = rename($this->getPathname(), (string) $target);
restore_error_handler();
if (!$renamed) {
throw new FileException(sprintf('Could not move the file "%s" to "%s" (%s)', $this->getPathname(), $target, strip_tags($error)));
}
@chmod((string) $target, 0666 & ~umask());
return $target;
}
/**
* 实例化一个新文件
* @param string $directory
* @param null|string $name
* @return File
*/
protected function getTargetFile(string $directory, ?string $name = null): File
{
if (!is_dir($directory)) {
if (false === @mkdir($directory, 0777, true) && !is_dir($directory)) {
throw new FileException(sprintf('Unable to create the "%s" directory', $directory));
}
} elseif (!is_writable($directory)) {
throw new FileException(sprintf('Unable to write in the "%s" directory', $directory));
}
$target = rtrim($directory, '/\\') . \DIRECTORY_SEPARATOR . (null === $name ? $this->getBasename() : $this->getName($name));
return new self($target, false);
}
/**
* 获取文件名
* @param string $name
* @return string
*/
protected function getName(string $name): string
{
$originalName = str_replace('\\', '/', $name);
$pos = strrpos($originalName, '/');
$originalName = false === $pos ? $originalName : substr($originalName, $pos + 1);
return $originalName;
}
/**
* 文件扩展名
* @return string
*/
public function extension(): string
{
return $this->getExtension();
}
/**
* 指定保存文件的扩展名
* @param string $extension
* @return void
*/
public function setExtension(string $extension): void
{
$this->extension = $extension;
}
/**
* 自动生成文件名
* @access public
* @param string|Closure|null $rule
* @return string
*/
public function hashName(string|Closure|null $rule = null): string
{
if (!$this->hashName) {
if ($rule instanceof Closure) {
$this->hashName = call_user_func_array($rule, [$this]);
} else {
$this->hashName = match (true) {
in_array($rule, hash_algos()) && $hash = $this->hash($rule) => substr($hash, 0, 2) . DIRECTORY_SEPARATOR . substr($hash, 2),
is_callable($rule) => call_user_func($rule),
default => date('Ymd') . DIRECTORY_SEPARATOR . md5(microtime(true) . $this->getPathname()),
};
}
}
$extension = $this->extension ?? $this->extension();
return $this->hashName . ($extension ? '.' . $extension : '');
}
}
@@ -0,0 +1,284 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2025 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
declare(strict_types=1);
namespace think;
use think\event\HttpEnd;
use think\event\HttpRun;
use think\event\RouteLoaded;
use think\exception\Handle;
use Throwable;
/**
* Web应用管理类
* @package think
*/
class Http
{
/**
* 应用名称
* @var string
*/
protected $name;
/**
* 应用路径
* @var string
*/
protected $path;
/**
* 路由路径
* @var string
*/
protected $routePath;
/**
* 是否绑定应用
* @var bool
*/
protected $isBind = false;
public function __construct(protected App $app)
{
$this->routePath = $this->app->getRootPath() . 'route' . DIRECTORY_SEPARATOR;
}
/**
* 设置应用名称
* @access public
* @param string $name 应用名称
* @return $this
*/
public function name(string $name)
{
$this->name = $name;
return $this;
}
/**
* 获取应用名称
* @access public
* @return string
*/
public function getName(): string
{
return $this->name ?: '';
}
/**
* 设置应用目录
* @access public
* @param string $path 应用目录
* @return $this
*/
public function path(string $path)
{
if (!str_ends_with($path, DIRECTORY_SEPARATOR)) {
$path .= DIRECTORY_SEPARATOR;
}
$this->path = $path;
return $this;
}
/**
* 获取应用路径
* @access public
* @return string
*/
public function getPath(): string
{
return $this->path ?: '';
}
/**
* 获取路由目录
* @access public
* @return string
*/
public function getRoutePath(): string
{
return $this->routePath;
}
/**
* 设置路由目录
* @access public
* @param string $path 路由定义目录
*/
public function setRoutePath(string $path): void
{
$this->routePath = $path;
}
/**
* 设置应用绑定
* @access public
* @param bool $bind 是否绑定
* @return $this
*/
public function setBind(bool $bind = true)
{
$this->isBind = $bind;
return $this;
}
/**
* 是否绑定应用
* @access public
* @return bool
*/
public function isBind(): bool
{
return $this->isBind;
}
/**
* 执行应用程序
* @access public
* @param Request|null $request
* @return Response
*/
public function run(?Request $request = null): Response
{
//初始化
$this->initialize();
//自动创建request对象
$request = $request ?? $this->app->make('request', [], true);
$this->app->instance('request', $request);
try {
$response = $this->runWithRequest($request);
} catch (Throwable $e) {
$this->reportException($e);
$response = $this->renderException($request, $e);
}
return $response;
}
/**
* 初始化
*/
protected function initialize()
{
if (!$this->app->initialized()) {
$this->app->initialize();
}
}
/**
* 执行应用程序
* @param Request $request
* @return mixed
*/
protected function runWithRequest(Request $request)
{
// 加载全局中间件
$this->loadMiddleware();
// 监听HttpRun
$this->app->event->trigger(HttpRun::class);
return $this->app->middleware->pipeline()
->send($request)
->then(function ($request) {
return $this->dispatchToRoute($request);
});
}
protected function dispatchToRoute($request)
{
$withRoute = $this->app->config->get('app.with_route', true) ? function () {
$this->loadRoutes();
} : false;
return $this->app->route->dispatch($request, $withRoute);
}
/**
* 加载全局中间件
*/
protected function loadMiddleware(): void
{
if (is_file($this->app->getBasePath() . 'middleware.php')) {
$this->app->middleware->import(include $this->app->getBasePath() . 'middleware.php');
}
}
/**
* 加载路由
* @access protected
* @return void
*/
protected function loadRoutes(): void
{
// 加载路由定义
$routePath = $this->getRoutePath();
if (is_dir($routePath)) {
$files = glob($routePath . '*.php');
foreach ($files as $file) {
include $file;
}
}
$this->app->event->trigger(RouteLoaded::class);
}
/**
* Report the exception to the exception handler.
*
* @param Throwable $e
* @return void
*/
protected function reportException(Throwable $e)
{
$this->app->make(Handle::class)->report($e);
}
/**
* Render the exception to a response.
*
* @param Request $request
* @param Throwable $e
* @return Response
*/
protected function renderException($request, Throwable $e)
{
return $this->app->make(Handle::class)->render($request, $e);
}
/**
* HttpEnd
* @param Response $response
* @return void
*/
public function end(Response $response): void
{
try {
// 触发HttpEnd事件
$this->app->event->trigger(HttpEnd::class, $response);
// 执行中间件
$this->app->middleware->end($response);
} catch (Throwable $e) {
// 记录异常
$this->app->log->error($e->getMessage());
}
// 写入日志
$this->app->log->save();
}
}
@@ -0,0 +1,273 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2025 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
declare (strict_types = 1);
namespace think;
/**
* 多语言管理类
* @package think
*/
class Lang
{
protected $app;
/**
* 配置参数
* @var array
*/
protected $config = [
// 默认语言
'default_lang' => 'zh-cn',
// 自动侦测浏览器语言
'auto_detect_browser' => true,
// 允许的语言列表
'allow_lang_list' => [],
// 是否使用Cookie记录
'use_cookie' => true,
// 扩展语言包
'extend_list' => [],
// 多语言cookie变量
'cookie_var' => 'think_lang',
// 多语言header变量
'header_var' => 'think-lang',
// 多语言自动侦测变量名
'detect_var' => 'lang',
// Accept-Language转义为对应语言包名称
'accept_language' => [
'zh-hans-cn' => 'zh-cn',
],
// 是否支持语言分组
'allow_group' => false,
];
/**
* 多语言信息
* @var array
*/
private $lang = [];
/**
* 当前语言
* @var string
*/
private $range = 'zh-cn';
/**
* 构造方法
* @access public
* @param array $config
*/
public function __construct(App $app, array $config = [])
{
$this->config = array_merge($this->config, array_change_key_case($config));
$this->range = $this->config['default_lang'];
$this->app = $app;
}
public static function __make(App $app, Config $config)
{
return new static($app, $config->get('lang'));
}
/**
* 获取当前语言配置
* @access public
* @return array
*/
public function getConfig(): array
{
return $this->config;
}
/**
* 设置当前语言
* @access public
* @param string $lang 语言
* @return void
*/
public function setLangSet(string $lang): void
{
$this->range = $lang;
}
/**
* 获取当前语言
* @access public
* @return string
*/
public function getLangSet(): string
{
return $this->range;
}
/**
* 获取默认语言
* @access public
* @return string
*/
public function defaultLangSet()
{
return $this->config['default_lang'];
}
/**
* 切换语言
* @access public
* @param string $langset 语言
* @return void
*/
public function switchLangSet(string $langset)
{
if (empty($langset)) {
return;
}
$this->setLangSet($langset);
// 加载系统语言包
$this->load([
$this->app->getThinkPath() . 'lang' . DIRECTORY_SEPARATOR . $langset . '.php',
]);
// 加载应用语言包(支持多种类型)
$files = glob($this->app->getAppPath() . 'lang' . DIRECTORY_SEPARATOR . $langset . '.*');
$this->load($files);
// 加载扩展(自定义)语言包
$list = $this->app->config->get('lang.extend_list', []);
if (isset($list[$langset])) {
$this->load($list[$langset]);
}
}
/**
* 加载语言定义(不区分大小写)
* @access public
* @param string|array $file 语言文件
* @param string $range 语言作用域
* @return array
*/
public function load($file, $range = ''): array
{
$range = $range ?: $this->range;
if (!isset($this->lang[$range])) {
$this->lang[$range] = [];
}
$lang = [];
foreach ((array) $file as $name) {
if (is_file($name)) {
$result = $this->parse($name);
$lang = array_change_key_case($result) + $lang;
}
}
if (!empty($lang)) {
$this->lang[$range] = $lang + $this->lang[$range];
}
return $this->lang[$range];
}
/**
* 解析语言文件
* @access protected
* @param string $file 语言文件名
* @return array
*/
protected function parse(string $file): array
{
$type = pathinfo($file, PATHINFO_EXTENSION);
$result = match ($type) {
'php' => include $file,
'yml', 'yaml' => function_exists('yaml_parse_file') ? yaml_parse_file($file) : [],
'json' => json_decode(file_get_contents($file), true),
default => [],
};
return is_array($result) ? $result : [];
}
/**
* 判断是否存在语言定义(不区分大小写)
* @access public
* @param string $name 语言变量
* @param string $range 语言作用域
* @return bool
*/
public function has(string $name, string $range = ''): bool
{
$range = $range ?: $this->range;
if ($this->config['allow_group'] && str_contains($name, '.')) {
[$name1, $name2] = explode('.', $name, 2);
return isset($this->lang[$range][strtolower($name1)][$name2]);
}
return isset($this->lang[$range][strtolower($name)]);
}
/**
* 获取语言定义(不区分大小写)
* @access public
* @param string|null $name 语言变量
* @param array $vars 变量替换
* @param string $range 语言作用域
* @return mixed
*/
public function get(?string $name = null, array $vars = [], string $range = '')
{
$range = $range ?: $this->range;
if (!isset($this->lang[$range])) {
$this->switchLangSet($range);
}
// 空参数返回所有定义
if (is_null($name)) {
return $this->lang[$range] ?? [];
}
if ($this->config['allow_group'] && str_contains($name, '.')) {
[$name1, $name2] = explode('.', $name, 2);
$value = $this->lang[$range][strtolower($name1)][$name2] ?? $name;
} else {
$value = $this->lang[$range][strtolower($name)] ?? $name;
}
// 变量解析
if (!empty($vars) && is_array($vars)) {
/**
* Notes:
* 为了检测的方便,数字索引的判断仅仅是参数数组的第一个元素的key为数字0
* 数字索引采用的是系统的 sprintf 函数替换,用法请参考 sprintf 函数
*/
if (key($vars) === 0) {
// 数字索引解析
array_unshift($vars, $value);
$value = call_user_func_array('sprintf', $vars);
} else {
// 关联索引解析
$replace = array_keys($vars);
foreach ($replace as &$v) {
$v = "{:{$v}}";
}
$value = str_replace($replace, $vars, $value);
}
}
return $value;
}
}
@@ -0,0 +1,249 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2025 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
declare(strict_types=1);
namespace think;
use InvalidArgumentException;
use Psr\Log\LoggerInterface;
use Psr\Log\LoggerTrait;
use Stringable;
use think\event\LogWrite;
use think\helper\Arr;
use think\log\Channel;
use think\log\ChannelSet;
/**
* 日志管理类
* @package think
* @mixin Channel
*/
class Log extends Manager implements LoggerInterface
{
use LoggerTrait;
const EMERGENCY = 'emergency';
const ALERT = 'alert';
const CRITICAL = 'critical';
const ERROR = 'error';
const WARNING = 'warning';
const NOTICE = 'notice';
const INFO = 'info';
const DEBUG = 'debug';
const SQL = 'sql';
protected $namespace = '\\think\\log\\driver\\';
/**
* 默认驱动
* @return string|null
*/
public function getDefaultDriver(): ?string
{
return $this->getConfig('default');
}
/**
* 获取日志配置
* @access public
* @param null|string $name 名称
* @param mixed $default 默认值
* @return mixed
*/
public function getConfig(?string $name = null, $default = null)
{
if (!is_null($name)) {
return $this->app->config->get('log.' . $name, $default);
}
return $this->app->config->get('log');
}
/**
* 获取渠道配置
* @param string $channel
* @param string $name
* @param mixed $default
* @return array
*/
public function getChannelConfig(string $channel, ?string $name = null, $default = null)
{
if ($config = $this->getConfig("channels.{$channel}")) {
return Arr::get($config, $name, $default);
}
throw new InvalidArgumentException("Channel [$channel] not found.");
}
/**
* driver()的别名
* @param string|array $name 渠道名
* @return Channel|ChannelSet
*/
public function channel(string|array|null $name = null)
{
if (is_array($name)) {
return new ChannelSet($this, $name);
}
return $this->driver($name);
}
protected function resolveType(string $name)
{
return $this->getChannelConfig($name, 'type', 'file');
}
public function createDriver(string $name)
{
$driver = parent::createDriver($name);
$lazy = !$this->getChannelConfig($name, "realtime_write", false) && !$this->app->runningInConsole();
$allow = array_merge($this->getConfig("level", []), $this->getChannelConfig($name, "level", []));
return new Channel($name, $driver, $allow, $lazy, $this->app->event);
}
protected function resolveConfig(string $name)
{
return $this->getChannelConfig($name);
}
/**
* 清空日志信息
* @access public
* @param string|array $channel 日志通道名
* @return $this
*/
public function clear(string|array $channel = '*')
{
if ('*' == $channel) {
$channel = array_keys($this->drivers);
}
$this->channel($channel)->clear();
return $this;
}
/**
* 关闭本次请求日志写入
* @access public
* @param string|array $channel 日志通道名
* @return $this
*/
public function close(string|array $channel = '*')
{
if ('*' == $channel) {
$channel = array_keys($this->drivers);
}
$this->channel($channel)->close();
return $this;
}
/**
* 获取日志信息
* @access public
* @param string $channel 日志通道名
* @return array
*/
public function getLog(?string $channel = null): array
{
return $this->channel($channel)->getLog();
}
/**
* 保存日志信息
* @access public
* @return bool
*/
public function save(): bool
{
/** @var Channel $channel */
foreach ($this->drivers as $channel) {
$channel->save();
}
return true;
}
/**
* 记录日志信息
* @access public
* @param mixed $msg 日志信息
* @param string $type 日志级别
* @param array $context 替换内容
* @param bool $lazy
* @return $this
*/
public function record($msg, string $type = 'info', array $context = [], bool $lazy = true)
{
$channel = $this->getConfig('type_channel.' . $type);
$this->channel($channel)->record($msg, $type, $context, $lazy);
return $this;
}
/**
* 实时写入日志信息
* @access public
* @param mixed $msg 调试信息
* @param string $type 日志级别
* @param array $context 替换内容
* @return $this
*/
public function write($msg, string $type = 'info', array $context = [])
{
return $this->record($msg, $type, $context, false);
}
/**
* 注册日志写入事件监听
* @param $listener
* @return Event
*/
public function listen($listener)
{
return $this->app->event->listen(LogWrite::class, $listener);
}
/**
* 记录日志信息
* @access public
* @param mixed $level 日志级别
* @param string|Stringable $message 日志信息
* @param array $context 替换内容
* @return void
*/
public function log($level, $message, array $context = []): void
{
$this->record($message, $level, $context);
}
/**
* 记录sql信息
* @access public
* @param string|Stringable $message 日志信息
* @param array $context 替换内容
* @return void
*/
public function sql($message, array $context = []): void
{
$this->log(__FUNCTION__, $message, $context);
}
public function __call($method, $parameters)
{
$this->log($method, ...$parameters);
}
}
@@ -0,0 +1,173 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2025 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: yunwuxin <448901948@qq.com>
// +----------------------------------------------------------------------
declare(strict_types=1);
namespace think;
use InvalidArgumentException;
use think\helper\Str;
abstract class Manager
{
/**
* 驱动
* @var array
*/
protected $drivers = [];
/**
* 驱动的命名空间
* @var string
*/
protected $namespace = null;
public function __construct(protected App $app)
{
}
/**
* 获取驱动实例
* @param null|string $name
* @return mixed
*/
protected function driver(?string $name = null)
{
$name = $name ?: $this->getDefaultDriver();
if (is_null($name)) {
throw new InvalidArgumentException(sprintf(
'Unable to resolve NULL driver for [%s].',
static::class
));
}
return $this->drivers[$name] = $this->getDriver($name);
}
/**
* 获取驱动实例
* @param string $name
* @return mixed
*/
protected function getDriver(string $name)
{
return $this->drivers[$name] ?? $this->createDriver($name);
}
/**
* 获取驱动类型
* @param string $name
* @return mixed
*/
protected function resolveType(string $name)
{
return $name;
}
/**
* 获取驱动配置
* @param string $name
* @return mixed
*/
protected function resolveConfig(string $name)
{
return $name;
}
/**
* 获取驱动类
* @param string $type
* @return string
*/
protected function resolveClass(string $type): string
{
if ($this->namespace || str_contains($type, '\\')) {
$class = str_contains($type, '\\') ? $type : $this->namespace . Str::studly($type);
if (class_exists($class)) {
return $class;
}
}
throw new InvalidArgumentException("Driver [$type] not supported.");
}
/**
* 获取驱动参数
* @param $name
* @return array
*/
protected function resolveParams($name): array
{
$config = $this->resolveConfig($name);
return [$config];
}
/**
* 创建驱动
*
* @param string $name
* @return mixed
*
*/
protected function createDriver(string $name)
{
$type = $this->resolveType($name);
$method = 'create' . Str::studly($type) . 'Driver';
$params = $this->resolveParams($name);
if (method_exists($this, $method)) {
return $this->$method(...$params);
}
$class = $this->resolveClass($type);
return $this->app->invokeClass($class, $params);
}
/**
* 移除一个驱动实例
*
* @param array|string|null $name
* @return $this
*/
public function forgetDriver($name = null)
{
$name = $name ?? $this->getDefaultDriver();
foreach ((array) $name as $cacheName) {
if (isset($this->drivers[$cacheName])) {
unset($this->drivers[$cacheName]);
}
}
return $this;
}
/**
* 默认驱动
* @return string|null
*/
abstract public function getDefaultDriver();
/**
* 动态调用
* @param string $method
* @param array $parameters
* @return mixed
*/
public function __call($method, $parameters)
{
return $this->driver()->$method(...$parameters);
}
}
@@ -0,0 +1,248 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2025 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Slince <taosikai@yeah.net>
// +----------------------------------------------------------------------
declare(strict_types=1);
namespace think;
use Closure;
use LogicException;
use think\exception\Handle;
use Throwable;
/**
* 中间件管理类
* @package think
*/
class Middleware
{
/**
* 中间件执行队列
* @var array
*/
protected $queue = [];
public function __construct(protected App $app)
{
}
/**
* 导入中间件
* @access public
* @param array $middlewares
* @param string $type 中间件类型
* @return void
*/
public function import(array $middlewares = [], string $type = 'global'): void
{
foreach ($middlewares as $middleware) {
$this->add($middleware, $type);
}
}
/**
* 注册中间件
* @access public
* @param mixed $middleware
* @param string $type 中间件类型
* @return void
*/
public function add(array|string|Closure $middleware, string $type = 'global'): void
{
$middleware = $this->buildMiddleware($middleware, $type);
if (!empty($middleware)) {
$this->queue[$type][] = $middleware;
$this->queue[$type] = array_unique($this->queue[$type], SORT_REGULAR);
}
}
/**
* 注册路由中间件
* @access public
* @param mixed $middleware
* @return void
*/
public function route(array|string|Closure $middleware): void
{
$this->add($middleware, 'route');
}
/**
* 注册控制器中间件
* @access public
* @param mixed $middleware
* @return void
*/
public function controller(array|string|Closure $middleware): void
{
$this->add($middleware, 'controller');
}
/**
* 注册中间件到开始位置
* @access public
* @param mixed $middleware
* @param string $type 中间件类型
*/
public function unshift(array|string|Closure $middleware, string $type = 'global')
{
$middleware = $this->buildMiddleware($middleware, $type);
if (!empty($middleware)) {
if (!isset($this->queue[$type])) {
$this->queue[$type] = [];
}
array_unshift($this->queue[$type], $middleware);
}
}
/**
* 获取注册的中间件
* @access public
* @param string $type 中间件类型
* @return array
*/
public function all(string $type = 'global'): array
{
return $this->queue[$type] ?? [];
}
/**
* 调度管道
* @access public
* @param string $type 中间件类型
* @return Pipeline
*/
public function pipeline(string $type = 'global')
{
return (new Pipeline())
->through(array_map(function ($middleware) {
return function ($request, $next) use ($middleware) {
[$call, $params] = $middleware;
if (is_array($call) && is_string($call[0])) {
$call = [$this->app->make($call[0]), $call[1]];
}
$response = call_user_func($call, $request, $next, ...$params);
if (!$response instanceof Response) {
throw new LogicException('The middleware must return Response instance');
}
return $response;
};
}, $this->sortMiddleware($this->queue[$type] ?? [])))
->whenException([$this, 'handleException']);
}
/**
* 结束调度
* @param Response $response
*/
public function end(Response $response)
{
foreach ($this->queue as $queue) {
foreach ($queue as $middleware) {
[$call] = $middleware;
if (is_array($call) && is_string($call[0])) {
$instance = $this->app->make($call[0]);
if (method_exists($instance, 'end')) {
$instance->end($response);
}
}
}
}
}
/**
* 异常处理
* @param Request $passable
* @param Throwable $e
* @return Response
*/
public function handleException($passable, Throwable $e)
{
/** @var Handle $handler */
$handler = $this->app->make(Handle::class);
$handler->report($e);
return $handler->render($passable, $e);
}
/**
* 解析中间件
* @access protected
* @param array|string|Closure $middleware
* @param string $type 中间件类型
* @return array
*/
protected function buildMiddleware(array|string|Closure $middleware, string $type): array
{
if (empty($middleware)) {
return [];
}
if (is_array($middleware)) {
[$middleware, $params] = $middleware;
}
if ($middleware instanceof Closure) {
return [$middleware, $params ?? []];
}
//中间件别名检查
$alias = $this->app->config->get('middleware.alias', []);
if (isset($alias[$middleware])) {
$middleware = $alias[$middleware];
}
if (is_array($middleware)) {
$this->import($middleware, $type);
return [];
}
return [[$middleware, 'handle'], $params ?? []];
}
/**
* 中间件排序
* @param array $middlewares
* @return array
*/
protected function sortMiddleware(array $middlewares)
{
$priority = $this->app->config->get('middleware.priority', []);
uasort($middlewares, function ($a, $b) use ($priority) {
$aPriority = $this->getMiddlewarePriority($priority, $a);
$bPriority = $this->getMiddlewarePriority($priority, $b);
return $bPriority - $aPriority;
});
return $middlewares;
}
/**
* 获取中间件优先级
* @param $priority
* @param $middleware
* @return int
*/
protected function getMiddlewarePriority($priority, $middleware)
{
[$call] = $middleware;
if (is_array($call) && is_string($call[0])) {
$index = array_search($call[0], array_reverse($priority));
return false === $index ? -1 : $index;
}
return -1;
}
}
@@ -0,0 +1,106 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2025 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: yunwuxin <448901948@qq.com>
// +----------------------------------------------------------------------
namespace think;
use Closure;
use Exception;
use Throwable;
class Pipeline
{
protected $passable;
protected $pipes = [];
protected $exceptionHandler;
/**
* 初始数据
* @param $passable
* @return $this
*/
public function send($passable)
{
$this->passable = $passable;
return $this;
}
/**
* 调用栈
* @param $pipes
* @return $this
*/
public function through($pipes)
{
$this->pipes = is_array($pipes) ? $pipes : func_get_args();
return $this;
}
/**
* 执行
* @param Closure $destination
* @return mixed
*/
public function then(Closure $destination)
{
$pipeline = array_reduce(
array_reverse($this->pipes),
$this->carry(),
function ($passable) use ($destination) {
try {
return $destination($passable);
} catch (Throwable | Exception $e) {
return $this->handleException($passable, $e);
}
}
);
return $pipeline($this->passable);
}
/**
* 设置异常处理器
* @param callable $handler
* @return $this
*/
public function whenException($handler)
{
$this->exceptionHandler = $handler;
return $this;
}
protected function carry()
{
return function ($stack, $pipe) {
return function ($passable) use ($stack, $pipe) {
try {
return $pipe($passable, $stack);
} catch (Throwable | Exception $e) {
return $this->handleException($passable, $e);
}
};
};
}
/**
* 异常处理
* @param $passable
* @param $e
* @return mixed
*/
protected function handleException($passable, Throwable $e)
{
if ($this->exceptionHandler) {
return call_user_func($this->exceptionHandler, $passable, $e);
}
throw $e;
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,431 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2025 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
declare(strict_types=1);
namespace think;
use Throwable;
/**
* 响应输出基础类
* @package think
*/
abstract class Response
{
/**
* 原始数据
* @var mixed
*/
protected $data;
/**
* 当前contentType
* @var string
*/
protected $contentType = 'text/html';
/**
* 字符集
* @var string
*/
protected $charset = 'utf-8';
/**
* 状态码
* @var int
*/
protected $code = 200;
/**
* 是否允许请求缓存
* @var bool
*/
protected $allowCache = true;
/**
* 输出参数
* @var array
*/
protected $options = [];
/**
* header参数
* @var array
*/
protected $header = [];
/**
* 输出内容
* @var string
*/
protected $content = null;
/**
* Cookie对象
* @var Cookie
*/
protected $cookie;
/**
* Session对象
* @var Session
*/
protected $session;
/**
* 初始化
* @access protected
* @param mixed $data 输出数据
* @param int $code 状态码
*/
protected function init($data = '', int $code = 200)
{
$this->data($data);
$this->code = $code;
$this->contentType($this->contentType, $this->charset);
}
/**
* 创建Response对象
* @access public
* @param mixed $data 输出数据
* @param string $type 输出类型
* @param int $code 状态码
* @return Response
*/
public static function create($data = '', string $type = 'html', int $code = 200): Response
{
$class = str_contains($type, '\\') ? $type : '\\think\\response\\' . ucfirst(strtolower($type));
return Container::getInstance()->invokeClass($class, [$data, $code]);
}
/**
* 设置Session对象
* @access public
* @param Session $session Session对象
* @return $this
*/
public function setSession(Session $session)
{
$this->session = $session;
return $this;
}
/**
* 发送数据到客户端
* @access public
* @return void
* @throws \InvalidArgumentException
*/
public function send(): void
{
try {
// 处理输出数据
$data = $this->getContent();
if (!headers_sent()) {
if (!empty($this->header)) {
// 发送状态码
http_response_code($this->code);
// 发送头部信息
foreach ($this->header as $name => $val) {
header($name . (!is_null($val) ? ':' . $val : ''));
}
}
if ($this->cookie) {
$this->cookie->save();
}
}
$this->sendData($data);
if (function_exists('fastcgi_finish_request')) {
// 提高页面响应
fastcgi_finish_request();
}
} catch (Throwable $e) {
// 继续执行,不中断响应发送
Container::getInstance()->log->error($e->getMessage());
}
}
/**
* 处理数据
* @access protected
* @param mixed $data 要处理的数据
* @return mixed
*/
protected function output($data)
{
return $data;
}
/**
* 输出数据
* @access protected
* @param string $data 要处理的数据
* @return void
*/
protected function sendData(string $data): void
{
echo $data;
}
/**
* 输出的参数
* @access public
* @param mixed $options 输出参数
* @return $this
*/
public function options(array $options = [])
{
$this->options = array_merge($this->options, $options);
return $this;
}
/**
* 输出数据设置
* @access public
* @param mixed $data 输出数据
* @return $this
*/
public function data($data)
{
$this->data = $data;
return $this;
}
/**
* 是否允许请求缓存
* @access public
* @param bool $cache 允许请求缓存
* @return $this
*/
public function allowCache(bool $cache)
{
$this->allowCache = $cache;
return $this;
}
/**
* 是否允许请求缓存
* @access public
* @return bool
*/
public function isAllowCache()
{
return $this->allowCache;
}
/**
* 设置Cookie
* @access public
* @param string $name cookie名称
* @param string $value cookie值
* @param mixed $option 可选参数
* @return $this
*/
public function cookie(string $name, string $value, $option = null)
{
$this->cookie->set($name, $value, $option);
return $this;
}
/**
* 设置响应头
* @access public
* @param array $header 参数
* @return $this
*/
public function header(array $header = [])
{
$this->header = array_merge($this->header, $header);
return $this;
}
/**
* 设置页面输出内容
* @access public
* @param mixed $content
* @return $this
*/
public function content($content)
{
if (
null !== $content && !is_string($content) && !is_numeric($content) && !is_callable([
$content,
'__toString',
])
) {
throw new \InvalidArgumentException(sprintf('variable type error: %s', gettype($content)));
}
$this->content = (string) $content;
return $this;
}
/**
* 发送HTTP状态
* @access public
* @param int $code 状态码
* @return $this
*/
public function code(int $code)
{
$this->code = $code;
return $this;
}
/**
* LastModified
* @access public
* @param string $time
* @return $this
*/
public function lastModified(string $time)
{
$this->header['Last-Modified'] = $time;
return $this;
}
/**
* Expires
* @access public
* @param string $time
* @return $this
*/
public function expires(string $time)
{
$this->header['Expires'] = $time;
return $this;
}
/**
* ETag
* @access public
* @param string $eTag
* @return $this
*/
public function eTag(string $eTag)
{
$this->header['ETag'] = $eTag;
return $this;
}
/**
* 页面缓存控制
* @access public
* @param string $cache 状态码
* @return $this
*/
public function cacheControl(string $cache)
{
$this->header['Cache-control'] = $cache;
return $this;
}
/**
* 页面输出类型
* @access public
* @param string $contentType 输出类型
* @param string $charset 输出编码
* @return $this
*/
public function contentType(string $contentType, string $charset = 'utf-8')
{
$this->header['Content-Type'] = $contentType . '; charset=' . $charset;
return $this;
}
/**
* 获取头部信息
* @access public
* @param string $name 头部名称
* @return mixed
*/
public function getHeader(string $name = '')
{
if (!empty($name)) {
return $this->header[$name] ?? null;
}
return $this->header;
}
/**
* 获取原始数据
* @access public
* @return mixed
*/
public function getData()
{
return $this->data;
}
/**
* 获取输出数据
* @access public
* @return string
*/
public function getContent(): string
{
if (null == $this->content) {
$content = $this->output($this->data);
if (
null !== $content && !is_string($content) && !is_numeric($content) && !is_callable([
$content,
'__toString',
])
) {
throw new \InvalidArgumentException(sprintf('variable type error: %s', gettype($content)));
}
$this->content = (string) $content;
}
return $this->content;
}
/**
* 获取状态码
* @access public
* @return int
*/
public function getCode(): int
{
return $this->code;
}
/**
* 获取Cookie对象
* @access public
* @return Cookie
*/
public function getCookie()
{
return $this->cookie;
}
}
@@ -0,0 +1,889 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2025 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
declare (strict_types = 1);
namespace think;
use Closure;
use think\exception\RouteNotFoundException;
use think\route\Dispatch;
use think\route\dispatch\Callback;
use think\route\Domain;
use think\route\Resource;
use think\route\ResourceRegister;
use think\route\Rule;
use think\route\RuleGroup;
use think\route\RuleItem;
use think\route\RuleName;
use think\route\Url as UrlBuild;
/**
* 路由管理类
* @package think
*/
class Route
{
/**
* REST定义
* @var array
*/
protected $rest = [
'index' => ['get', '', 'index'],
'create' => ['get', '/create', 'create'],
'edit' => ['get', '/<id>/edit', 'edit'],
'read' => ['get', '/<id>', 'read'],
'save' => ['post', '', 'save'],
'update' => ['put', '/<id>', 'update'],
'delete' => ['delete', '/<id>', 'delete'],
];
/**
* 配置参数
* @var array
*/
protected $config = [
// pathinfo分隔符
'pathinfo_depr' => '/',
// 是否开启路由延迟解析
'url_lazy_route' => false,
// 是否强制使用路由
'url_route_must' => false,
// 是否区分大小写
'url_case_sensitive' => false,
// 合并路由规则
'route_rule_merge' => false,
// 路由是否完全匹配
'route_complete_match' => false,
// 子目录是否自动路由分组
'route_auto_group' => false,
// 去除斜杠
'remove_slash' => false,
// 默认的路由变量规则
'default_route_pattern' => '[\w\.]+',
// URL伪静态后缀
'url_html_suffix' => 'html',
// 访问控制器层名称
'controller_layer' => 'controller',
// 空控制器名
'empty_controller' => 'Error',
// 是否使用控制器后缀
'controller_suffix' => false,
// 默认模块名
'default_module' => 'index',
// 默认控制器名
'default_controller' => 'Index',
// 默认操作名
'default_action' => 'index',
// 操作方法后缀
'action_suffix' => '',
// 非路由变量是否使用普通参数方式(用于URL生成)
'url_common_param' => true,
// 操作方法的参数绑定方式 route get param
'action_bind_param' => 'get',
// API版本header变量
'api_version' => 'Api-Version',
];
/**
* 请求对象
* @var Request
*/
protected $request;
/**
* @var RuleName
*/
protected $ruleName;
/**
* 当前HOST
* @var string
*/
protected $host;
/**
* 当前分组对象
* @var RuleGroup
*/
protected $group;
/**
* 域名对象
* @var Domain[]
*/
protected $domains = [];
/**
* 跨域路由规则
* @var RuleGroup
*/
protected $cross;
/**
* 路由是否延迟解析
* @var bool
*/
protected $lazy = false;
/**
* (分组)路由规则是否合并解析
* @var bool
*/
protected $mergeRuleRegex = false;
/**
* 是否去除URL最后的斜线
* @var bool
*/
protected $removeSlash = false;
public function __construct(protected App $app)
{
$this->ruleName = new RuleName();
$this->setDefaultDomain();
if (is_file($this->app->getRuntimePath() . 'route.php')) {
// 读取路由映射文件
$this->import(include $this->app->getRuntimePath() . 'route.php');
}
$this->config = array_merge($this->config, $this->app->config->get('route'));
$this->init();
}
protected function init()
{
if (!empty($this->config['middleware'])) {
$this->app->middleware->import($this->config['middleware'], 'route');
}
$this->lazy($this->config['url_lazy_route']);
$this->mergeRuleRegex = $this->config['route_rule_merge'];
$this->removeSlash = $this->config['remove_slash'];
$this->group->removeSlash($this->removeSlash);
// 注册全局MISS路由
$this->miss(function () {
return Response::create('', 'html', 204)->header(['Allow' => 'GET, POST, PUT, DELETE']);
}, 'options');
}
public function config(?string $name = null)
{
if (is_null($name)) {
return $this->config;
}
return $this->config[$name] ?? null;
}
/**
* 设置路由域名及分组(包括资源路由)是否延迟解析
* @access public
* @param bool $lazy 路由是否延迟解析
* @return $this
*/
public function lazy(bool $lazy = true)
{
$this->lazy = $lazy;
return $this;
}
/**
* 设置路由域名及分组(包括资源路由)是否合并解析
* @access public
* @param bool $merge 路由是否合并解析
* @return $this
*/
public function mergeRuleRegex(bool $merge = true)
{
$this->mergeRuleRegex = $merge;
$this->group->mergeRuleRegex($merge);
return $this;
}
/**
* 初始化默认域名
* @access protected
* @return void
*/
protected function setDefaultDomain(): void
{
// 注册默认域名
$domain = new Domain($this);
$this->domains['-'] = $domain;
// 默认分组
$this->group = $domain;
}
/**
* 设置当前分组
* @access public
* @param RuleGroup $group 域名
* @return void
*/
public function setGroup(RuleGroup $group): void
{
$this->group = $group;
}
/**
* 获取指定标识的路由分组 不指定则获取当前分组
* @access public
* @param string $name 分组标识
* @return RuleGroup
*/
public function getGroup(?string $name = null)
{
return $name ? $this->ruleName->getGroup($name) : $this->group;
}
/**
* 注册变量规则
* @access public
* @param array $pattern 变量规则
* @return $this
*/
public function pattern(array $pattern)
{
$this->group->pattern($pattern);
return $this;
}
/**
* 注册路由参数
* @access public
* @param array $option 参数
* @return $this
*/
public function option(array $option)
{
$this->group->option($option);
return $this;
}
/**
* 注册域名路由
* @access public
* @param string|array $name 子域名
* @param mixed $rule 路由规则
* @return Domain
*/
public function domain(string | array $name, $rule = null): Domain
{
// 支持多个域名使用相同路由规则
$domainName = is_array($name) ? array_shift($name) : $name;
if (!isset($this->domains[$domainName])) {
$domain = (new Domain($this, $domainName, $rule, $this->lazy))
->removeSlash($this->removeSlash)
->mergeRuleRegex($this->mergeRuleRegex);
$this->domains[$domainName] = $domain;
} else {
$domain = $this->domains[$domainName];
$domain->parseGroupRule($rule);
}
if (is_array($name) && !empty($name)) {
foreach ($name as $item) {
$this->domains[$item] = $domainName;
}
}
// 返回域名对象
return $domain;
}
/**
* 获取域名
* @access public
* @return array
*/
public function getDomains(): array
{
return $this->domains;
}
/**
* 获取域名路由的绑定信息
* @access public
* @param string $domain 子域名
* @return string|null
*/
public function getDomainBind(?string $domain = null)
{
if ($domain && isset($this->domains[$domain])) {
$item = $this->domains[$domain];
if (is_string($item)) {
$item = $this->domains[$item];
}
return $item->getBind();
}
}
/**
* 获取RuleName对象
* @access public
* @return RuleName
*/
public function getRuleName(): RuleName
{
return $this->ruleName;
}
/**
* 读取路由标识
* @access public
* @param string $name 路由标识
* @param string $domain 域名
* @param string $method 请求类型
* @return array
*/
public function getName(?string $name = null, ?string $domain = null, string $method = '*'): array
{
return $this->ruleName->getName($name, $domain, $method);
}
/**
* 批量导入路由标识
* @access public
* @param array $name 路由标识
* @return void
*/
public function import(array $name): void
{
$this->ruleName->import($name);
}
/**
* 注册路由标识
* @access public
* @param string $name 路由标识
* @param RuleItem $ruleItem 路由规则
* @param bool $first 是否优先
* @return void
*/
public function setName(string $name, RuleItem $ruleItem, bool $first = false): void
{
$this->ruleName->setName($name, $ruleItem, $first);
}
/**
* 保存路由规则
* @access public
* @param string $rule 路由规则
* @param RuleItem $ruleItem RuleItem对象
* @return void
*/
public function setRule(string $rule, ?RuleItem $ruleItem = null): void
{
$this->ruleName->setRule($rule, $ruleItem);
}
/**
* 读取路由
* @access public
* @param string $rule 路由规则
* @return RuleItem[]
*/
public function getRule(string $rule): array
{
return $this->ruleName->getRule($rule);
}
/**
* 读取路由列表
* @access public
* @return array
*/
public function getRuleList(): array
{
return $this->ruleName->getRuleList();
}
/**
* 清空路由规则
* @access public
* @return void
*/
public function clear(): void
{
$this->ruleName->clear();
if ($this->group) {
$this->group->clear();
}
}
/**
* 注册路由规则
* @access public
* @param string $rule 路由规则
* @param mixed $route 路由地址
* @param string $method 请求类型
* @return RuleItem
*/
public function rule(string $rule, $route = null, string $method = '*'): RuleItem
{
return $this->group->addRule($rule, $route, $method);
}
/**
* 设置路由规则全局有效
* @access public
* @param Rule $rule 路由规则
* @return $this
*/
public function setCrossDomainRule(Rule $rule)
{
if (!isset($this->cross)) {
$this->cross = (new RuleGroup($this))->mergeRuleRegex($this->mergeRuleRegex);
}
$this->cross->addRuleItem($rule);
return $this;
}
/**
* 注册路由分组
* @access public
* @param string|Closure $name 分组名称或者参数
* @param mixed $route 分组路由
* @return RuleGroup
*/
public function group(string | Closure $name, $route = null): RuleGroup
{
if ($name instanceof Closure) {
$route = $name;
$name = '';
}
return (new RuleGroup($this, $this->group, $name, $route, $this->lazy))
->removeSlash($this->removeSlash)
->mergeRuleRegex($this->mergeRuleRegex);
}
/**
* 注册路由
* @access public
* @param string $rule 路由规则
* @param mixed $route 路由地址
* @return RuleItem
*/
public function any(string $rule, $route): RuleItem
{
return $this->rule($rule, $route, '*');
}
/**
* 注册GET路由
* @access public
* @param string $rule 路由规则
* @param mixed $route 路由地址
* @return RuleItem
*/
public function get(string $rule, $route): RuleItem
{
return $this->rule($rule, $route, 'GET');
}
/**
* 注册POST路由
* @access public
* @param string $rule 路由规则
* @param mixed $route 路由地址
* @return RuleItem
*/
public function post(string $rule, $route): RuleItem
{
return $this->rule($rule, $route, 'POST');
}
/**
* 注册PUT路由
* @access public
* @param string $rule 路由规则
* @param mixed $route 路由地址
* @return RuleItem
*/
public function put(string $rule, $route): RuleItem
{
return $this->rule($rule, $route, 'PUT');
}
/**
* 注册DELETE路由
* @access public
* @param string $rule 路由规则
* @param mixed $route 路由地址
* @return RuleItem
*/
public function delete(string $rule, $route): RuleItem
{
return $this->rule($rule, $route, 'DELETE');
}
/**
* 注册PATCH路由
* @access public
* @param string $rule 路由规则
* @param mixed $route 路由地址
* @return RuleItem
*/
public function patch(string $rule, $route): RuleItem
{
return $this->rule($rule, $route, 'PATCH');
}
/**
* 注册HEAD路由
* @access public
* @param string $rule 路由规则
* @param mixed $route 路由地址
* @return RuleItem
*/
public function head(string $rule, $route): RuleItem
{
return $this->rule($rule, $route, 'HEAD');
}
/**
* 注册OPTIONS路由
* @access public
* @param string $rule 路由规则
* @param mixed $route 路由地址
* @return RuleItem
*/
public function options(string $rule, $route): RuleItem
{
return $this->rule($rule, $route, 'OPTIONS');
}
/**
* 注册资源路由
* @access public
* @param string $rule 路由规则
* @param string $route 路由地址
* @param Closure $extend 扩展规则
* @return Resource|ResourceRegister
*/
public function resource(string $rule, string $route, ?Closure $extend = null)
{
$resource = (new Resource($this, $this->group, $rule, $route, $this->rest))->extend($extend);
if (!$this->lazy) {
return new ResourceRegister($resource);
}
return $resource;
}
/**
* 注册视图路由
* @access public
* @param string $rule 路由规则
* @param string $template 路由模板地址
* @param array $vars 模板变量
* @return RuleItem
*/
public function view(string $rule, string $template = '', array $vars = []): RuleItem
{
return $this->rule($rule, function () use ($vars, $template) {
return Response::create($template, 'view')->assign($vars);
}, 'GET');
}
/**
* 注册重定向路由
* @access public
* @param string $rule 路由规则
* @param string $route 路由地址
* @param int $status 状态码
* @return RuleItem
*/
public function redirect(string $rule, string $route = '', int $status = 301): RuleItem
{
return $this->rule($rule, function (Request $request) use ($status, $route) {
$search = $replace = [];
$matches = $request->rule()->getVars();
foreach ($matches as $key => $value) {
$search[] = '<' . $key . '>';
$replace[] = $value;
$search[] = '{' . $key . '}';
$replace[] = $value;
$search[] = ':' . $key;
$replace[] = $value;
}
$route = str_replace($search, $replace, $route);
return Response::create($route, 'redirect')->code($status);
}, '*');
}
/**
* rest方法定义和修改
* @access public
* @param string|array $name 方法名称
* @param array|bool $resource 资源
* @return $this
*/
public function rest(string | array $name, array | bool $resource = [])
{
if (is_array($name)) {
$this->rest = $resource ? $name : array_merge($this->rest, $name);
} else {
$this->rest[$name] = $resource;
}
return $this;
}
/**
* 获取rest方法定义的参数
* @access public
* @param string $name 方法名称
* @return array|null
*/
public function getRest(?string $name = null)
{
if (is_null($name)) {
return $this->rest;
}
return $this->rest[$name] ?? null;
}
/**
* 注册未匹配路由规则后的处理
* @access public
* @param string|Closure $route 路由地址
* @param string $method 请求类型
* @return RuleItem
*/
public function miss(string | Closure $route, string $method = '*'): RuleItem
{
return $this->group->miss($route, $method);
}
/**
* 路由调度
* @param Request $request
* @param Closure|bool $withRoute
* @return Response
*/
public function dispatch(Request $request, Closure | bool $withRoute = true)
{
$this->request = $request;
$this->host = $this->request->host(true);
$completeMatch = (bool) $this->config['route_complete_match'];
$url = str_replace($this->config['pathinfo_depr'], '|', $this->path());
if ($withRoute) {
if ($withRoute instanceof Closure) {
$withRoute();
}
// 路由检测
$dispatch = $this->check($url, $completeMatch);
}
if (empty($dispatch)) {
// 默认URL调度
$dispatch = $this->checkUrlDispatch($url);
}
$dispatch->init($this->app);
return $this->app->middleware->pipeline('route')
->send($request)
->then(function () use ($dispatch) {
return $dispatch->run();
});
}
/**
* 检测URL路由
* @access public
* @param bool $completeMatch
* @return Dispatch|false
* @throws RouteNotFoundException
*/
public function check(string $url, bool $completeMatch = false)
{
// 检测域名路由
$result = $this->checkDomain()->check($this->request, $url, $completeMatch);
if (false === $result && !empty($this->cross)) {
// 检测跨域路由
$result = $this->cross->check($this->request, $url, $completeMatch);
}
if (false === $result && $this->config['url_route_must']) {
// 开启强制路由
throw new RouteNotFoundException();
}
return $result;
}
/**
* 获取当前请求URL的pathinfo信息(不含URL后缀)
* @access protected
* @return string
*/
protected function path(): string
{
$suffix = $this->config['url_html_suffix'];
$pathinfo = $this->request->pathinfo();
if (false === $suffix) {
// 禁止伪静态访问
$path = $pathinfo;
} elseif ($suffix) {
// 去除正常的URL后缀
$path = preg_replace('/\.(' . ltrim($suffix, '.') . ')$/i', '', $pathinfo);
} else {
// 允许任何后缀访问
$path = preg_replace('/\.' . $this->request->ext() . '$/i', '', $pathinfo);
}
return $path;
}
/**
* 自动多模块URL路由 如使用多模块在路由定义文件最后定义
* @access public
* @param string $rule 路由规则
* @param mixed $route 路由地址
* @param bool $middleware 自动注册中间件
* @return RuleItem
*/
public function auto(string $rule = '[:__module__]/[:__controller__]/[:__action__]', $route = ':__module__/:__controller__/:__action__', bool $middleware = false): RuleItem
{
return $this->rule($rule, $route)
->name('__think_auto_route__')
->pattern([
'__module__' => '[A-Za-z0-9\.\_]+',
'__controller__' => '[A-Za-z0-9\.\_]+',
'__action__' => '[A-Za-z0-9\_]+',
])->default([
'__module__' => $this->config['default_module'],
'__controller__' => $this->config['default_controller'],
'__action__' => $this->config['default_action'],
])->autoMiddleware($middleware);
}
/**
* 检测默认URL解析路由
* @access public
* @param string $url URL
* @return Dispatch
*/
protected function checkUrlDispatch(string $url): Dispatch
{
if ($this->request->method() == 'OPTIONS') {
// 自动响应options请求
return new Callback($this->request, $this->group, function () {
return Response::create('', 'html', 204)->header(['Allow' => 'GET, POST, PUT, DELETE']);
});
}
return $this->group->auto()->checkBind($this->request, $url);
}
/**
* 检测域名的路由规则
* @access protected
* @return Domain
*/
protected function checkDomain(): Domain
{
$item = false;
if (count($this->domains) > 1) {
// 获取当前子域名
$subDomain = $this->request->subDomain();
$domain = $subDomain ? explode('.', $subDomain) : [];
$domain2 = $domain ? array_pop($domain) : '';
if ($domain) {
// 存在三级域名
$domain3 = array_pop($domain);
}
if (isset($this->domains[$this->host])) {
// 子域名配置
$item = $this->domains[$this->host];
} elseif (isset($this->domains[$subDomain])) {
$item = $this->domains[$subDomain];
} elseif (isset($this->domains['*.' . $domain2]) && !empty($domain3)) {
// 泛三级域名
$item = $this->domains['*.' . $domain2];
$panDomain = $domain3;
} elseif (isset($this->domains['*']) && !empty($domain2)) {
// 泛二级域名
if ('www' != $domain2) {
$item = $this->domains['*'];
$panDomain = $domain2;
}
}
if (isset($panDomain)) {
// 保存当前泛域名
$this->request->setPanDomain($panDomain);
}
}
if (false === $item) {
// 检测全局域名规则
$item = $this->domains['-'];
}
if (is_string($item)) {
$item = $this->domains[$item];
}
return $item;
}
/**
* URL生成 支持路由反射
* @access public
* @param string $url 路由地址
* @param array $vars 参数 ['a'=>'val1', 'b'=>'val2']
* @return UrlBuild
*/
public function buildUrl(string $url = '', array $vars = []): UrlBuild
{
return $this->app->make(UrlBuild::class, [$this, $this->app, $url, $vars], true);
}
/**
* 设置全局的路由分组参数
* @access public
* @param string $method 方法名
* @param array $args 调用参数
* @return RuleGroup
*/
public function __call($method, $args)
{
return call_user_func_array([$this->group, $method], $args);
}
}
@@ -0,0 +1,63 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2025 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: yunwuxin <448901948@qq.com>
// +----------------------------------------------------------------------
declare(strict_types=1);
namespace think;
use Closure;
use think\event\RouteLoaded;
/**
* 系统服务基础类
* @method void register()
* @method void boot()
*/
abstract class Service
{
public function __construct(protected App $app)
{
}
/**
* 加载路由
* @access protected
* @param string $path 路由路径
*/
protected function loadRoutesFrom(string $path)
{
$this->registerRoutes(function () use ($path) {
include $path;
});
}
/**
* 注册路由
* @param Closure $closure
*/
protected function registerRoutes(Closure $closure)
{
$this->app->event->listen(RouteLoaded::class, $closure);
}
/**
* 添加指令
* @access protected
* @param array|string $commands 指令
*/
protected function commands($commands)
{
$commands = is_array($commands) ? $commands : func_get_args();
Console::starting(function (Console $console) use ($commands) {
$console->addCommands($commands);
});
}
}
@@ -0,0 +1,65 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2025 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
declare(strict_types=1);
namespace think;
use think\helper\Arr;
use think\session\Store;
/**
* Session管理类
* @package think
* @mixin Store
*/
class Session extends Manager
{
protected $namespace = '\\think\\session\\driver\\';
protected function createDriver(string $name)
{
$handler = parent::createDriver($name);
return new Store($this->getConfig('name') ?: 'PHPSESSID', $handler, $this->getConfig('serialize'));
}
/**
* 获取Session配置
* @access public
* @param null|string $name 名称
* @param mixed $default 默认值
* @return mixed
*/
public function getConfig(?string $name = null, $default = null)
{
if (!is_null($name)) {
return $this->app->config->get('session.' . $name, $default);
}
return $this->app->config->get('session');
}
protected function resolveConfig(string $name)
{
$config = $this->app->config->get('session', []);
Arr::forget($config, 'type');
return $config;
}
/**
* 默认驱动
* @return string|null
*/
public function getDefaultDriver()
{
return $this->app->config->get('session.type', 'file');
}
}
@@ -0,0 +1,187 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2025 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
declare(strict_types=1);
namespace think;
use think\contract\TemplateHandlerInterface;
use think\helper\Arr;
/**
* 视图类
* @package think
*/
class View extends Manager
{
protected $namespace = '\\think\\view\\driver\\';
/**
* 模板变量
* @var array
*/
protected $data = [];
/**
* 内容过滤
* @var mixed
*/
protected $filter;
/**
* 获取模板引擎
* @access public
* @param string $type 模板引擎类型
* @return TemplateHandlerInterface
*/
public function engine(?string $type = null)
{
return $this->driver($type);
}
/**
* 模板变量赋值
* @access public
* @param string|array $name 模板变量
* @param mixed $value 变量值
* @return $this
*/
public function assign(string|array $name, $value = null)
{
if (is_array($name)) {
$this->data = array_merge($this->data, $name);
} else {
$this->data[$name] = $value;
}
return $this;
}
/**
* 视图过滤
* @access public
* @param Callable $filter 过滤方法或闭包
* @return $this
*/
public function filter(?callable $filter = null)
{
$this->filter = $filter;
return $this;
}
/**
* 解析和获取模板内容 用于输出
* @access public
* @param string $template 模板文件名或者内容
* @param array $vars 模板变量
* @return string
* @throws \Exception
*/
public function fetch(string $template = '', array $vars = []): string
{
return $this->getContent(function () use ($vars, $template) {
$this->engine()->fetch($template, array_merge($this->data, $vars));
});
}
/**
* 渲染内容输出
* @access public
* @param string $content 内容
* @param array $vars 模板变量
* @return string
*/
public function display(string $content, array $vars = []): string
{
return $this->getContent(function () use ($vars, $content) {
$this->engine()->display($content, array_merge($this->data, $vars));
});
}
/**
* 获取模板引擎渲染内容
* @param $callback
* @return string
* @throws \Exception
*/
protected function getContent($callback): string
{
// 页面缓存
ob_start();
ob_implicit_flush(false);
// 渲染输出
try {
$callback();
} catch (\Exception $e) {
ob_end_clean();
throw $e;
}
// 获取并清空缓存
$content = ob_get_clean();
if ($this->filter) {
$content = call_user_func_array($this->filter, [$content]);
}
return $content;
}
/**
* 模板变量赋值
* @access public
* @param string $name 变量名
* @param mixed $value 变量值
*/
public function __set($name, $value)
{
$this->data[$name] = $value;
}
/**
* 取得模板显示变量的值
* @access protected
* @param string $name 模板变量
* @return mixed
*/
public function __get($name)
{
return $this->data[$name];
}
/**
* 检测模板变量是否设置
* @access public
* @param string $name 模板变量名
* @return bool
*/
public function __isset($name)
{
return isset($this->data[$name]);
}
protected function resolveConfig(string $name)
{
$config = $this->app->config->get('view', []);
Arr::forget($config, 'type');
return $config;
}
/**
* 默认驱动
* @return string|null
*/
public function getDefaultDriver()
{
return $this->app->config->get('view.type', 'php');
}
}
@@ -0,0 +1,385 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2025 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
declare (strict_types = 1);
namespace think\cache;
use Closure;
use DateInterval;
use DateTime;
use DateTimeInterface;
use Exception;
use think\Container;
use think\contract\CacheHandlerInterface;
use think\exception\InvalidArgumentException;
use think\exception\InvalidCacheException;
use Throwable;
/**
* 缓存基础类
*/
abstract class Driver implements CacheHandlerInterface
{
/**
* 驱动句柄
* @var object
*/
protected $handler = null;
/**
* 缓存读取次数
* @var int
*/
protected $readTimes = 0;
/**
* 缓存写入次数
* @var int
*/
protected $writeTimes = 0;
/**
* 缓存参数
* @var array
*/
protected $options = [];
/**
* 缓存标签
* @var array
*/
protected $tag = [];
/**
* 获取有效期
* @access protected
* @param int|DateInterval|DateTimeInterface $expire 有效期
* @return int
*/
protected function getExpireTime(int | DateInterval | DateTimeInterface $expire): int
{
if ($expire instanceof DateTimeInterface) {
$expire = $expire->getTimestamp() - time();
} elseif ($expire instanceof DateInterval) {
$expire = DateTime::createFromFormat('U', (string) time())
->add($expire)
->format('U') - time();
}
return $expire;
}
/**
* 获取实际的缓存标识
* @access public
* @param string $name 缓存名
* @return string
*/
public function getCacheKey(string $name): string
{
return $this->options['prefix'] . $name;
}
/**
* 读取缓存并删除
* @access public
* @param string $name 缓存变量名
* @param mixed $default 默认值
* @return mixed
*/
public function pull($name, $default = null)
{
if ($this->has($name)) {
$result = $this->get($name, $default);
$this->delete($name);
return $result;
}
return $this->getDefaultValue($name, $default);
}
/**
* 追加(数组)缓存
* @access public
* @param string $name 缓存变量名
* @param mixed $value 存储数据
* @return void
*/
public function push($name, $value): void
{
$item = $this->get($name, []);
if (!is_array($item)) {
throw new InvalidArgumentException('only array cache can be push');
}
$item[] = $value;
if (count($item) > 1000) {
array_shift($item);
}
$item = array_unique($item);
$this->set($name, $item);
}
/**
* 追加TagSet数据
* @access public
* @param string $name 缓存变量名
* @param mixed $value 存储数据
* @return void
*/
public function append($name, $value): void
{
$this->push($name, $value);
}
/**
* 如果不存在则写入缓存
* @access public
* @param string $name 缓存变量名
* @param mixed $value 存储数据
* @param int|DateInterval|DateTimeInterface $expire 有效时间 0为永久
* @return mixed
*/
public function remember($name, $value, $expire = null)
{
if ($this->has($name)) {
if (($hit = $this->get($name)) !== null) {
return $hit;
}
}
$time = time();
while ($time + 5 > time() && $this->has($name . '_lock')) {
// 存在锁定则等待
usleep(200000);
}
try {
// 锁定
$this->set($name . '_lock', true);
if ($value instanceof Closure) {
// 获取缓存数据
$value = Container::getInstance()->invokeFunction($value);
}
// 缓存数据
$this->set($name, $value, $expire);
// 解锁
$this->delete($name . '_lock');
} catch (Exception | Throwable $e) {
$this->delete($name . '_lock');
throw $e;
}
return $value;
}
/**
* 缓存标签
* @access public
* @param string|array $name 标签名
* @return TagSet
*/
public function tag($name)
{
$name = (array) $name;
$key = implode('-', $name);
if (!isset($this->tag[$key])) {
$this->tag[$key] = new TagSet($name, $this);
}
return $this->tag[$key];
}
/**
* 获取标签包含的缓存标识
* @access public
* @param string $tag 标签标识
* @return array
*/
public function getTagItems(string $tag): array
{
$name = $this->getTagKey($tag);
return $this->get($name, []);
}
/**
* 获取实际标签名
* @access public
* @param string $tag 标签名
* @return string
*/
public function getTagKey(string $tag): string
{
return $this->options['tag_prefix'] . md5($tag);
}
/**
* 序列化数据
* @access protected
* @param mixed $data 缓存数据
* @return string
*/
protected function serialize($data)
{
if (is_numeric($data)) {
return $data;
}
$serialize = $this->options['serialize'][0] ?? "serialize";
return $serialize($data);
}
/**
* 反序列化数据
* @access protected
* @param string $data 缓存数据
* @return mixed
*/
protected function unserialize($data)
{
if (is_numeric($data)) {
return $data;
}
try {
$unserialize = $this->options['serialize'][1] ?? "unserialize";
$content = $unserialize($data);
if (is_null($content)) {
throw new InvalidCacheException;
} else {
return $content;
}
} catch (Exception | Throwable $e) {
throw new InvalidCacheException;
}
}
/**
* 获取默认值
* @access protected
* @param string $name 缓存标识
* @param mixed $default 默认值
* @param bool $fail 是否有异常
* @return mixed
*/
protected function getDefaultValue($name, $default, $fail = false)
{
if ($fail && $this->options['fail_delete']) {
$this->delete($name);
}
return $default instanceof Closure ? $default() : $default;
}
/**
* 返回句柄对象,可执行其它高级方法
*
* @access public
* @return object
*/
public function handler()
{
return $this->handler;
}
/**
* 返回缓存读取次数
* @return int
* @deprecated
* @access public
*/
public function getReadTimes(): int
{
return $this->readTimes;
}
/**
* 返回缓存写入次数
* @return int
* @deprecated
* @access public
*/
public function getWriteTimes(): int
{
return $this->writeTimes;
}
/**
* 读取缓存
* @access public
* @param iterable $keys 缓存变量名
* @param mixed $default 默认值
* @return iterable
* @throws InvalidArgumentException
*/
public function getMultiple($keys, $default = null): iterable
{
$result = [];
foreach ($keys as $key) {
$result[$key] = $this->get($key, $default);
}
return $result;
}
/**
* 写入缓存
* @access public
* @param iterable $values 缓存数据
* @param null|int|\DateInterval|DateTimeInterface $ttl 有效时间 0为永久
* @return bool
*/
public function setMultiple($values, $ttl = null): bool
{
foreach ($values as $key => $val) {
$result = $this->set($key, $val, $ttl);
if (false === $result) {
return false;
}
}
return true;
}
/**
* 删除缓存
* @access public
* @param iterable $keys 缓存变量名
* @return bool
* @throws InvalidArgumentException
*/
public function deleteMultiple($keys): bool
{
foreach ($keys as $key) {
$result = $this->delete($key);
if (false === $result) {
return false;
}
}
return true;
}
public function __call($method, $args)
{
return call_user_func_array([$this->handler, $method], $args);
}
}

Some files were not shown because too many files have changed in this diff Show More