guennichi/mapper
最新稳定版本:2.1.3
Composer 安装命令:
composer require guennichi/mapper
包简介
A lightweight library to map array data to PHP immutable objects
README 文档
README
A lightweight library to map array data into PHP immutable objects, collections and strongly typed arrays via constructors.
Benchmark
Check benchmark/ directory for more details about the implementation.
| Benchmark | Revs | Its | mem_peak | Mode | rstdev |
|---|---|---|---|---|---|
unserialize() |
5000 | 5 | 1.724mb | 9.547μs | ±1.51% |
symfony/serializer |
5000 | 5 | 3.489mb | 122.343μs | ±0.84% |
guennichi/mapper |
5000 | 5 | 2.972mb | 16.638μs | ±0.41% |
Installation
composer require guennichi/mapper
Usage
use Guennichi\Collection\Collection; final class Person { public function __construct(public readonly string $name) {} } /** * @extends Collection<Person> */ final class PersonCollection extends Collection { public function __construct(Person ...$elements) { parent::__construct(...$elements); } } $input = [ ['name' => 'Person1'], ['name' => 'Person2'], ['name' => 'Person3'], ]; $mapper = new Guennichi\Mapper\Mapper(/** dependencies */) $output = $mapper->map($input, PersonCollection::class); // Result instance of PersonCollection(Person{"name": "Person1"}, Person{"name": "Person2"}, Person{"name": "Person3"})
Dedication
Special thanks to my colleague @Gabriel Ostrolucký for his support and advices to make this happen.
统计信息
- 总下载量: 12.5k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 12
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-09-12