battis/hydratable
最新稳定版本:v0.1.1
Composer 安装命令:
composer require battis/hydratable
包简介
Hydrate serialized objects with defaults and overrides
README 文档
README
Hydrate serialized objects with defaults and overrides
This is meant to make it easier to take DRY arguments and hydrate them based on preset defaults.
Install
composer require battis/hydratable
Use
This can either be added as a trait to a class or as an invokable class.
use Battis\Hydratable\Hydratable; class MyObject { use Hydratable; private static $DEFAULTS = [ 'foo' => 'bar', 'argle' => 'bargle' ] private $options; public function __construct(array $params = []) { $this->options = $this->hydrate($params, self::$DEFAULTS); } }
One could then instantiate an instance of MyObject:
$o = new MyObject(['baz' => 123, 'argle' = 'BaRgLe']); /* $o->options = [ 'foo' => 'bar', 'baz' => 123, 'argle' => 'BaRgLe' ] */
Alternatively, we could simply instantiate Hydrate and use it as a one-off:
$hydrate = new Battis\Hydratable\Hydrate(); $options = $hydrate($params, $defaults);
统计信息
- 总下载量: 640
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0
- 更新时间: 2020-08-03