承接 ez-php/support 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固