grzesie2k / hydrator
此包已被 废弃 并不再维护。未建议替代包。
适用于现代应用的 PHP PSR-7 兼容可缓存 hydrator。
0.0.1
2018-03-10 22:24 UTC
Requires
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.10
- php-coveralls/php-coveralls: ^2.0
- phpunit/phpunit: ^7.0
This package is auto-updated.
Last update: 2020-02-26 10:33:50 UTC
README
适用于现代应用的 PHP7 PSR-5 兼容可缓存 hydrator。
安装
composer install grzesie2k/hydrator
示例
- 验证基本类型
<?php $hydrator = $hydratorFactory->createHydrator('int[]'); // any valid type $intList = $hydrator->hydrator([1, 2, 3]); // ✓ OK $intList = $hydrator->hydrator([1, 'a', 2]); // ☹ exception
- 通过构造函数 hydrate 类
<?php class Example { /** * @param int $id * @param string $name we can read types from PHPDoc */ public function __construct(int $id, $name) // or from type hints { // ... some operation } } $hydrator = $hydratorFactory->createHydrator(Example::class); $hydrator->hydrate(\json_decode('{"id":2,"name":"Adam"}')); // ✓ OK $hydrator->hydrate(\json_decode('{"id":"Nope","name":"Janek"}')); // ☹ exception
待办事项
- 创建 hydrator 策略以处理复合类型(例如 int|string)
- 创建替代对象 hydrate 策略(无构造函数)
- 为一些内置类型(例如 DateTime)创建 hydrator 策略
- 使用内部类和更好的消息处理 hydrate 异常
- 创建 symfony/laravel 包
- 添加示例和更好的文档