hhaojin/zorro
Composer 安装命令:
composer create-project hhaojin/zorro
包简介
High performance AOP and Coroutine PHP Framework
README 文档
README
Zorro
zorro是一款轻量灵活的高性能http框架,支持路由分组,中间件,自定义注解,自定义验证器,参数绑定.
install
composer require hhaojin/zorro
quick start
1、路由
<?php require "./vendor/autoload.php"; $zorror = new \Zorro\Zorro(); //注册路由, curl -x POST http://localhost:8080/test/xxx -d '{"order_id": "world"}' $zorror->Post("/test/{name}", function (\Zorro\Context $context) { $context->json(200, ["hello" => "world"]); //使用json响应 }); $zorror->Run(8080); //启动服务, 监听8080端口 //使用workerman启动 php main.php //使用swoole启动 php main.php --SERVER=swoole
2、路由分组
<?php require "./vendor/autoload.php"; $zorror = new \Zorro\Zorro(); $zorror->Use(new \Example\RecoveryMiddleware()); //全局中间件 $orderGroup := $zorror->Group("/order"); //分组路由 { //curl http://localhost:8080/order/detail?order_id=100 $orderGroup->Get("/detail", [\Example\Handler\Order::class, "detail"]); }
3、参数绑定
<?php require "./vendor/autoload.php"; $zorror = new \Zorro\Zorro(); //注册路由, curl -x POST http://localhost:8080/test/xxx -d '{"order_id": 123}' $zorror->Post("/test/{name}", function (\Zorro\Context $context) { //对body里面的参数进行校验,并映射到实体里 /**@var \Example\Handler\OrderDeatilReq $requestParam */ $requestParam := $context->bindJson(\Example\Handler\OrderDeatilReq::class) $context->json(200, ["order_id" => $requestParam->order_id)]); //使用json响应 });
一、自定义注解
1、定义注解处理类
namespace Example\CustomAttribute; use Zorro\Aspect\JoinPoint; use Zorro\Attribute\CustomAttributeInterface; class LogHandler implements CustomAttributeInterface { public function handle($reflect, $instance, $attribute): \Closure { return function (JoinPoint $joinPoint, array $args) use ($reflect) { echo "before -> " . $reflect->getName() . PHP_EOL; $joinPoint->process($args); echo "after -> " . $reflect->getName() . PHP_EOL; }; } }
2、定义注解类
#[Attribute] #[CustomAttribute(LogHandler::class)] class TestLog { public $name; public function __construct($name) { $this->name = $name } }
3、使用注解
class OrderProduct { #[TestLog("prodList")] public function prodList($num) { echo "prodList ----->" . $num . PHP_EOL; return [ "php从入门到放弃", "k8s从放弃到佛系" ]; } } //在框架启动的时候扫描注解,会使用切面来处理,在handle中使用,会输出以下内容 \Zorro\BeanFactory::getBean(OrderProduct::class)->prodList(123); /** before -> prodList prodList -----> 123 after -> prodList * /
二、验证器
1、使用
class OrderDeatilReq { #[\Zorro\Validation\Validate("intType;between=50,100;")] public $order_id; } //在控制器中直接使用bind方法, order_id必须是数字,并且50<= order_id <=100 /**@var \Zorro\Context $context*/ $req = $context->bindJson(OrderDeatilReq::class); var_dump($req);
2、自定义规则
class EqTag extends Zorro\Validation\CustomTagAbstract { protected $tag = "eq"; public function validate($input, $value): bool { var_dump($input,$value); if ($input === $value) { return true; } return false; } } \Zorro\Validation\Validator::registerValidation(new \Example\CustomAttribute\EqTag()); //使用, 匿名类的order_id 属性必须在50-100区间,并且必须等于88 $obj = new class { #[Validate("between=50,100;eq=88", "order_id 不符合要求")] public $order_id = 100; }; \Zorro\Validation\Validator::validate($obj); // Zorro\Validation\ValidateException: order_id 不符合要求, property=order_id, // tag=eq in D:\code\program\zorro\src\Validation\Validator.php:78
hhaojin/zorro 适用场景与选型建议
hhaojin/zorro 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 2, 最近一次更新时间为 2022 年 07 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「framework」 「php」 「swoole」 「workerman」 「zorro」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 hhaojin/zorro 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 hhaojin/zorro 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 hhaojin/zorro 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
annotations-scan-plugin
SForum
Alfabank REST API integration
think-orm协程化版本, 仅在swoole协程环境使用
This is a PHP Framework base on Swoole
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2022-07-08