myschoolmanagement/bindto
Composer 安装命令:
composer require myschoolmanagement/bindto
包简介
Simple way to bind Request to DTO/Commands
README 文档
README
Simplest way to bind Request to DTO/Commands.
Bindto helps you to work with API and data validation using DTO and Commands.
Is really fast (it doesn't use Reflection) and binds the Request against your class.
It's the smartest way to stop using the slow and complex Symfony Form component for API.
Install
composer require pugx/bindto
Usage
Example, you have to create a Post/Patch/Put Api
1. Create a simple class that is the body of a request
protip: you can use with Symfony validation component annotations
use Symfony\Component\Validator\Constraints as Assert; Class CreateFeedback { /** * @Assert\NotBlank(groups={"POST"}) * @Assert\Type(type="string") */ public $subject; /** * @Assert\NotNull(groups={"POST"}) * @Assert\Type(type="string") * @Assert\Length( * min = 10, * max = 500) */ public $body; }
2. In your controller
if you use Silex you may want to enforce the input validation, improving the example at http://silex.sensiolabs.org/doc/usage.html#example-post-route:
require_once __DIR__.'/../vendor/autoload.php'; use Bindto\Binder; $app = new Silex\Application(); $app->post('/feedback', function (Request $request) { $binder = Binder::createSimpleProductionBinder(); $result = $binder->bind($request, CreateFeedback::class); if (!$result->isValid()) { throw new \Exception($result->getViolations()); } $createFeedBack = $result->getData(); mail($createFeedBack->subject, '[YourSite] Feedback', $createFeedBack->body); return new Response('Thank you for your feedback!', 201); }); $app->run();
PATCH support with partial modification
Use the validation groups if you want to PATCH partially:
/** * @Assert\NotNull(groups={"POST"}) * @Assert\Type(type="string") * @Assert\Length( * min = 10, * max = 500) */ public $body;
With a POST request all the assertions will be used,
with a PUT and PATCH only the Type and Length assertions.
TODO
- recursive binder?
- collection?
- twig helper?
- tests decouple maptest from bindertest
- silex provider?
- sf bundle?
Run tests
composer dump-autoload bin/phpunit
myschoolmanagement/bindto 适用场景与选型建议
myschoolmanagement/bindto 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 128 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 01 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 myschoolmanagement/bindto 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 myschoolmanagement/bindto 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 128
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-01-25