konkod / evenly-distribute
任何事物的均匀分布的通用服务
1.0.0
2024-06-13 09:22 UTC
Requires
- php: >=8.3
Requires (Dev)
- phpstan/phpstan: ^1.11
- phpunit/phpunit: ^9.5
- spatie/phpunit-snapshot-assertions: ^4.2
README
任何事物的均匀分布的通用服务
特性
-
按字段非唯一实体ID进行排序
-
根据池ID中定义的值进行均匀分配
-
- (删除池ID的每个元素,并使用唯一的本地池ID构建数组)
用法
// See EvenlyDistributeServiceTest::testExampleWorksFine $input = [ ['poolId' => 'A', 'uniqueEntityId' => '123', 'nonUniqueEntityId' => 1, 'entity' => ['id' => 123]], ['poolId' => 'B', 'uniqueEntityId' => '456', 'nonUniqueEntityId' => 2, 'entity' => ['id' => 456]], ['poolId' => 'B', 'uniqueEntityId' => '678', 'nonUniqueEntityId' => 2, 'entity' => ['id' => 678]], ]; $output = EvenlyDistributeService::distributeByPools($input); $excepted = [ 'A' => [ ['poolId' => 'A', 'uniqueEntityId' => '123', 'nonUniqueEntityId' => 1, 'entity' => ['id' => 123]] ], 'B' => [ ['poolId' => 'B', 'uniqueEntityId' => '456', 'nonUniqueEntityId' => 2, 'entity' => ['id' => 456]] ], ]; echo $excepted === $output;
测试
# Run phpunit vendor/bin/phpunit tests # PhpStan composer run phpstan