{"id":35194347,"url":"https://github.com/basic-hub/es-core","last_synced_at":"2026-05-27T04:09:52.948Z","repository":{"id":322416843,"uuid":"1089380499","full_name":"basic-hub/es-core","owner":"basic-hub","description":"新版核心业务逻辑实现，EasySwoole项目公共组件","archived":false,"fork":false,"pushed_at":"2026-04-10T02:32:05.000Z","size":1454,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-04-10T04:24:49.807Z","etag":null,"topics":["aes","cloud-lib","easyswoole","geo","jwt","notify","php","rsa","swoole","websocket"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/basic-hub.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-11-04T09:09:50.000Z","updated_at":"2026-04-10T02:30:54.000Z","dependencies_parsed_at":null,"dependency_job_id":"60237c0c-9bde-478c-bb35-6bf183e6cda4","html_url":"https://github.com/basic-hub/es-core","commit_stats":null,"previous_names":["basic-hub/es-core"],"tags_count":369,"template":false,"template_full_name":null,"purl":"pkg:github/basic-hub/es-core","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/basic-hub%2Fes-core","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/basic-hub%2Fes-core/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/basic-hub%2Fes-core/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/basic-hub%2Fes-core/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/basic-hub","download_url":"https://codeload.github.com/basic-hub/es-core/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/basic-hub%2Fes-core/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31926260,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-17T10:35:34.458Z","status":"ssl_error","status_checked_at":"2026-04-17T10:35:09.472Z","response_time":62,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aes","cloud-lib","easyswoole","geo","jwt","notify","php","rsa","swoole","websocket"],"created_at":"2025-12-29T06:46:45.304Z","updated_at":"2026-05-27T04:09:52.942Z","avatar_url":"https://github.com/basic-hub.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"## 简介\n\n    基于Easyswoole封装的一些Trait和Class，放到Composer仓库以实现多项目共用一套代码\n\n## 开始\n\n\u003e composer require basic-hub/es-core\n\n## 需要掌握的基础知识：\n\n- [EasySwoole](http://www.easyswoole.com)\n- [Swoole](https://wiki.swoole.com)\n- [Composer](https://getcomposer.org)\n\n## 目录结构及常用介绍\n\n    src 理解为EasySwoole的App目录\n     ├── Common  主要放一些非EasySwoole的东西\n     |      ├── Classes 自定义类\n     │      │     ├── CtxManager 二次封装的EasySwoole\\Component\\Context\\ContextManager类，增加一些快捷方法\n     │      │     ├── DateUtils 时间日期时区等处理\n     │      │     ├── ExceptionTrigger 自定义异常处理器，将异常上报至redis或http\n     │      │     ├── FdManager  WebSocket连接符管理，共享内存(Swoole\\Table)实现\n     │      │     ├── Jwt \n     │      │     ├── Mysqli 对MysqlClient的二次封装\n     │      │     ├── TablePart 定时建分区、续分区\n     │      │     ├── Tree 数行结构处理\n     │      │     └── XlsWriter 数据导入和导出\n     │      ├── CloudLib 云商各产品相关实现类，目前均已支持腾讯云、阿里云，可扩展\n     │      ├── Exception 各种自定义异常\n     │      ├── Http Http相关的配置\n     │      │     └── Code Http响应状态码，项目的Code请`继承`它\n     │      ├── Language I18N国际化目录\n     │      │     ├── Dictionary 国际化字典，项目请`继承`它\n     │      │     └── Languages I18n助手类，主要用来注册、设置\n     │      │\n     │      ├── Logs 自定义日志处理器\n     │      ├── Geo IP解析相关\n     │      ├── Openssl 加密解密处理，支持RSA、AES，可扩展\n     │      └── OrmCache 模型缓存组件，已实现 String、Hash、Set、SplArray\n     ├── Consumer  一些自定义进程实现，Base抽象类实现了基本Redis队列监听数据消费，但自定义进程能做的事情远不止如此，可自行发挥\n     ├── Crontab  内置定时任务实现，可后台控制开关、运行环境、传递参数 等\n     │\n     ├── HttpController\n     │        ├── Admin\n     │        │     ├── BaseTrait 继承BaseController\n     │        │     ├── AuthTrait 继承BaseTrait引用类，是其他控制器的父类，主要实现一些CURD等基础操作，子类可写最少代码实现相关功能\n     │        │     └── ... 其他业务控制器\n     │        ├── Api\n     │        └── BaseController 所有控制器的基类\n     ├── HttpTracker 链路追踪\n     │        ├── Index 继承自PointContext，目的是为了默认开启autoSave及设置saveHandler，实例化时用它替代PointContext\n     │        └── SaveHandler 实现SaveHandlerInterface接口\n     ├── Model\n     │     ├── BaseModelTrait 所有Model的基类\n     │     └── ... 其他业务模型\n     ├── Notify 通知类实现，内置飞书、钉钉、微信通知\n     │      \n     ├── Task 异步任务\n     │     ├── Crontab 通用的异步任务模板\n     │     └── ... 异步任务类\n     ├── Template 简单的模板引擎实现，可选\n     ├── WebSocket 同 HttpController\n     ├── ... 其他业务\n     ├── EventInitialize 对EasySwooleEvent::initialize事件的一些封装\n     ├── EventMainServerCreate  对EasySwooleEvent::mainServerCreate事件的一些封装\n     └── function.php 常用函数，项目可预定义对应函数以实现不同逻辑\n\nController\n\n```php\n\u003c?php\nuse BasicHub\\EsCore\\HttpController\\Admin\\AdminTrait;\n\nclass MyAdminController\n{\n\tuse AdminTrait;\n    \n\t// here are some methods from AdminTrait ....\n}\n\n```\n\nModel\n\n```php\n\u003c?php\nuse BasicHub\\EsCore\\Model\\AdminModelTrait;\n\nclass MyAdminModel\n{\n\tuse AdminModelTrait;\n    \n\t// here are some methods from AdminModelTrait ....\n}\n\n```\n\n## 答疑解惑\n\nfunction.php 为何不写在此项目的composer.json\n\n    function.php应该由项目的composer.json去定义引入的顺序\n    位置一定得是在项目的函数引入之后，否则无法预定义函数，而放在此项目的composer.json会被优先加载\n\n为何多数文件选择trait而不使用继承\n\n    trait和继承各有优劣，选择trait目的是为了EasySwoole推荐的继承关系不被破坏\n\ntrait有哪些坑\n\n    1. 不允许重写属性，所以基本都定义了一个setTraitProtected方法去修改trait属性\n    2. 不允许重载方法，当某些项目可能比方法多一个小逻辑时，需要及时调整代码的封装，否则需要整个复制多一份，日积月累，反而可能更难维护\n    3. 由于 2 的限制，现将普通控制器方法的public方法名默认添加一个固定前缀，通过基础控制器 /src/HttpController/BaseControllerTrait.php 的 actionNotFound 方法来实现更加灵活的调用方式\n\n\n## 与老版本变化\n\n- 扩展参数不再直接修改EasySwoole的Request对象，而是存储在控制器的属性中。\n    \n    \n    改动原因：直接修改原Request会导致一些需要所有参数参与签名的地方无法处理\n\n- rsa密文解密参数独立rsa属性，强制某些数据必须是经过rsa解密得到。\n\n    \n    改动原因：例如： envkeydata=xxxxxxxxx\u0026name=Joyboo 。传递的envkeydata密文中是不包含 `name` 字段的，通过解密再合并到input中，此时 在业务层是无法区分name是不是由rsa解密的来的，只能区分有没有经过rsa解密和name字段有没有值，如果被外部恶意攻击关键字段，这里就是隐患。\n\n- 重写链路日志相关实现\n- 重写jwt token相关函数和类\n- 重写协程上下文管理器\n- 重写Openssl相关方法，支持多种加密方式，且可扩展\n- 重写GeoIP解析相关函数，支持多渠道，且可扩展\n- 模型相关的调整\n- 移除所有eval动态解析\n- 增加客户端使用临时密钥直传对象存储方法，以支持超大文件上传，理论上无上限\n- 优化Redis集群模式下分key规则及数据散列\n- CloudLib增加火山云支持\n\n\n    火山云SDK暂搁置，原因为：\n    1. 截止目前（2025-12-22）不支持邮件推送服务\n    2. 截止目前（2025-12-22）不支持云验证码服务\n    3. CDN系列接口没有SDK实现，需自主实现原生HTTP请求\n    4. DNS系列接口没有SDK实现，需自主实现原生HTTP请求\n    5. STS系列接口SDK方式基础库过大，原生支持困难，待有空再整理\n\n    基于上述原因，且现在不是强依赖，如果耗时对接完成之后，火山云方面更新SDK版本之后，还得再更新一次。当然，欢迎有能力和有需求的小伙伴提PR ！\n\n- \u003cspan style=\"color: red\"\u003e重要更新\u003c/span\u003e：可选依赖现改为在业务项目内引入，不再在此组件内统一引入，大幅减小构建vendor体积。\n\n    \n    影响以下目录：\n    1. Common/CloudLib\n\n    \n    例如：项目A是用的腾讯云相关接口，那么阿里云、火山云等依赖是不需要引入的，因为真的有些依赖库是压缩后都有大几十MB的，而vendor与node_modules区别在于没有编译，5个G的node_modules编译后产物实际只有几MB，而vendor目录是会直接发布到生产环境服务器，这意味着每次CI/CD都带着一大堆用不上的代码，无法接受。\n    请主动到各个类声明中复制 composer require xxxx 来安装引入需要使用的依赖。\n\n- 重构自定义消费进程，支持同进程处理多个任务，避免开太多闲置进程\n- 支持子链路和异步task里的链路追踪，通过协程上下文传递 `parent_id` 即可\n\n## TODO\n\n- [x] 创建定时任务Crontab和消费任务Consumer，src/Common/Classes/Crontab移动至src/Crontab目录\n- [x] 重写ShardTable类，已重写为TablePart类\n- [x] WebSocket相关类，事件、解析、Caller、连接符管理等\n- [x] Crontab支持database、file、http等方式获取\n- [x] es-orm-cache 组件封装，替换原有的cacheinfo系列方法\n- [x] 重写verify_token为面向对象风格，验证与生成token解耦\n- [x] CloudLib相关Composer依赖由业务层项目安装，移除本仓库所有相关依赖\n\n## 常用命令\n\n查看进程信息\n\u003ephp easyswoole process show -d\n\n杀死指定进程\n\u003ephp easyswoole process kill --pid=PID\n\n杀死指定进程组\n\u003ephp easyswoole process kill --group=GROUP_NAME\n\n杀死所有进程\n\u003ephp easyswoole process killAll\n\n强制杀死进程：带上 -f 参数\n\n查看Task进程状态\n\u003ephp easyswoole task status\n\n## 其他\n\n- [trait冲突解决](https://www.php.net/manual/zh/language.oop5.traits.php)\n- [XlsWriter](https://xlswriter-docs.viest.me/zh-cn)\n\n## 感谢\n\n[\u003cimg src=\"https://resources.jetbrains.com/storage/products/company/brand/logos/jetbrains.png\" alt=\"JetBrains Logo (Main) logo.\" height=\"50\" /\u003e](https://www.jetbrains.com/)\n\n## 贡献\n\n\u003ca href=\"https://openomy.com/basic-hub/es-core\" target=\"_blank\" style=\"display: block; width: 100%;margin-bottom: 1rem;\" align=\"center\"\u003e\n  \u003cimg src=\"https://openomy.com/svg?repo=basic-hub/es-core\u0026chart=bubble\u0026latestMonth=12\" target=\"_blank\" alt=\"Contribution Leaderboard\" style=\"display: block; width: 100%;\" /\u003e\n\u003c/a\u003e\n\n\u003ca href=\"https://github.com/basic-hub/es-core/graphs/contributors\"\u003e\n  \u003cimg alt=\"Contributors\" src=\"https://contrib.rocks/image?repo=basic-hub/es-core\" /\u003e\n\u003c/a\u003e\n\n## Star History\n\n[![Star History Chart](https://api.star-history.com/svg?repos=basic-hub/es-core\u0026type=Date)](https://star-history.com/#basic-hub/es-core\u0026Date)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbasic-hub%2Fes-core","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbasic-hub%2Fes-core","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbasic-hub%2Fes-core/lists"}