alexandr-mironov / multikeyhashmap
多键hashmap,用于具有多个唯一可能键的一组实体
v0.1
2022-12-23 19:34 UTC
Requires
- php: ^8
Requires (Dev)
- phpstan/phpstan: ^1.9
- phpunit/phpunit: ^9
README
多键hashmap,用于具有多个唯一可能键的一组实体
此集合具有主要价值,并且可以拥有多个键映射,这意味着您可以通过选择集合中的任意一个唯一值来创建映射(基于此集合)
例如
我们有一些数据如下
| id | slug | ... other properties |
| 1 | alpha | .................... |
| 2 | beta | .................... |
我们创建集合
<?php $collection = new Collection(SomeCLass::class, 'id', 'slug'); foreach ($iterator as $item) { $instance = new SomeClass($item); // just example of entity creating $collection->push($instance); } // after that you can get map by passing name of key $idMappedCollection = $collection->getMap('id'); // array with ID as key and SomeClass entity as value $slugMappedCollection = $collection->getMap('slug'); // array with SLUG as key and SomeClass entity as value