ez-php/support
最新稳定版本:1.11.1
Composer 安装命令:
composer require ez-php/support
包简介
General-purpose utility classes for the ez-php ecosystem — Range, WeightedRandom, TimeProbability, DailyQuota
关键字:
README 文档
README
General-purpose utility classes for the ez-php ecosystem. Zero external dependencies — pure PHP.
Classes
Range
Immutable value object for a bounded integer range.
$r = Range::of(0, 100); $r->contains(50); // true $r->clamp(150); // 100 $r->random(); // uniform draw in [0, 100] $r->weightedLow(); // min-of-two-draws, skewed towards 0
WeightedRandom
Stateless weighted random selection from a list of associative arrays.
$items = [ ['name' => 'common', 'weight' => 9], ['name' => 'rare', 'weight' => 1], ]; WeightedRandom::pick($items); // picks one, respecting weights WeightedRandom::pickN($items, 2); // picks 2 without replacement WeightedRandom::weightedLow(0, 100); // min-of-two-draws
Custom weight key:
WeightedRandom::pick($items, 'probability');
TimeProbability
Exponential time-based probability curve: P(t) = 1 − exp(−t / λ).
// Deterministic: just the probability value TimeProbability::probability(minutesSince: 5.0, lambda: 4.0); // ~0.713 // Stochastic: roll the curve TimeProbability::exponential(minutesSince: 5.0); // true/false
Always returns true once minutesSince >= hardCapMinutes (default 15).
DailyQuota
Immutable value object for "daily allowance + per-action growing cooldown + UTC midnight reset".
$quota = new DailyQuota(dailyLimit: 5, cooldownBaseSeconds: 300, cooldownStepSeconds: 300); $now = new DateTimeImmutable(); if ($quota->canPerform($now)) { $quota = $quota->perform($now); // persist $quota state } $quota->remaining(); // actions left today $quota->cooldownUntil(); // next available time $quota->usedToday(); // actions performed today
UTC midnight resets happen automatically inside canPerform() and perform(). Call
resetIfNeeded($now) explicitly to get a fresh instance without performing an action.
Installation
composer require ez-php/support
Testing
composer full
统计信息
- 总下载量: 17
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-25