getwarp / laminas-hydrator-bridge
Laminas Hydrator与其他Warp组件的集成
3.1.3
2023-03-15 08:22 UTC
Requires
- php: ^7.4|^8.0
- laminas/laminas-hydrator: ^4.0
Requires (Dev)
- getwarp/data-source: ^3.1
- getwarp/type: ^3.1
- getwarp/value-object: ^3.1
- phpunit/phpunit: ^9.5
- roave/security-advisories: dev-latest
Suggests
- getwarp/data-source: Used with BlameStrategy
- getwarp/type: Used with CasterStrategy
- getwarp/value-object: Used with ValueObjectStrategy
README
getwarp/laminas-hydrator-bridge
Laminas Hydrator与其他Warp组件的集成 Laminas Hydrator
安装
通过Composer
$ composer require getwarp/laminas-hydrator-bridge
用法
use Warp\LaminasHydratorBridge\StdClassHydrator; use Warp\LaminasHydratorBridge\NamingStrategy\AliasNamingStrategy; use Warp\LaminasHydratorBridge\Strategy\BooleanStrategy; use Warp\LaminasHydratorBridge\Strategy\ScalarStrategy; use Warp\LaminasHydratorBridge\Strategy\NullableStrategy; use Warp\Type\BuiltinType; $hydrator = new StdClassHydrator(); $hydrator->setNamingStrategy(new AliasNamingStrategy([ 'firstName' => ['first_name', 'firstname'], 'lastName' => ['last_name', 'lastname'], 'rulesAccepted' => ['rules_accepted'], ])); $hydrator->addStrategy('age', new NullableStrategy(new ScalarStrategy(BuiltinType::INT))); $hydrator->addStrategy('rulesAccepted', new BooleanStrategy(['Y', 'y', 1], 'N', false)); $john = $hydrator->hydrate([ 'first_name' => 'John', 'last_name' => 'Doe', 'rules_accepted' => 'y', 'age' => '25', ], new stdClass()); // $john->firstName === 'John'; // $john->lastName === 'Doe'; // $john->rulesAccepted === true; // $john->age === 25; $jane = $hydrator->hydrate([ 'firstname' => 'Jane', 'lastname' => 'Doe', 'rules_accepted' => '', 'age' => null, ], new stdClass()); // $jane->firstName === 'John'; // $jane->lastName === 'Doe'; // $jane->rulesAccepted === false; // $jane->age === null;
变更日志
有关最近更改的更多信息,请参阅 CHANGELOG。
贡献
报告问题 和 发送Pull Requests 在 main warp 仓库 中。有关详细信息,请参阅 CONTRIBUTING 和 CODE_OF_CONDUCT。
致谢
许可证
MIT许可证(MIT)。有关更多信息,请参阅 许可证文件。