定制 gryfoss/odds 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

gryfoss/odds

Composer 安装命令:

composer require gryfoss/odds

包简介

PHP package for dealing with different formats of betting odds: decimal (European), fractional (British), and moneyline (American)

README 文档

README

Tests Coverage PHP Version License

PHP package for dealing with different formats of betting odds: decimal (European), fractional (British), and moneyline (American).

🚀 New Architecture (v2.0)

This library has been completely redesigned with:

  • Immutable Odds class containing all formats and probability (not meant for direct instantiation - use OddsFactory)
  • OddsFactory with dependency injection for conversion strategies
  • String-based decimals for precision and security (no more float issues!)
  • bcmath calculations for exact mathematical operations
  • Extensible odds ladder system via interfaces
  • Fixed precision integer support for performance-critical applications

Features

  • Precision: String-based decimals with bcmath calculations
  • Immutable design: Thread-safe odds objects
  • All-in-one: Single object contains decimal, fractional, moneyline, and probability
  • Dependency injection: Configurable conversion strategies
  • Extensible: Custom odds ladder implementations
  • Comprehensive: Full test coverage

Requirements

  • PHP 8.4+ (required for bcmath precision functions)
  • bcmath extension (standard in most installations)
  • Composer

Installation

composer require gryfoss/odds

Quick Start

require 'vendor/autoload.php';

use GryfOSS\Odds\OddsFactory;

$factory = new OddsFactory();

// Create from string decimal (secure, precise)
$odds = $factory->fromDecimal('2.50');

echo $odds->getDecimal();     // "2.50"
echo $odds->getFractional();  // "3/2"
echo $odds->getMoneyline();   // "+150"
echo $odds->getProbability(); // 40 (integer percentage)

Usage Examples

Basic Conversions

$factory = new OddsFactory();

// From decimal
$odds = $factory->fromDecimal('1.75');

// From fractional
$odds = $factory->fromFractional(3, 4);

// From moneyline
$odds = $factory->fromMoneyline('-133');

// From fixed precision integer (advanced usage)
$odds = $factory->fromFixedPrecision(250); // Represents 2.50

With Odds Ladder

use GryfOSS\Odds\Utils\OddsLadder;

$oddsLadder = new OddsLadder();
$factory = new OddsFactory($oddsLadder);

$odds = $factory->fromDecimal('2.00');
echo $odds->getFractional(); // Uses odds ladder lookup

Custom Odds Ladder

use GryfOSS\Odds\Utils\OddsLadder;

class MyCustomLadder extends OddsLadder
{
    protected function getLadder(): array
    {
        return [
            '1.50' => 'evens',
            '2.00' => '1/1',
            '3.00' => '2/1',
        ];
    }
}

$factory = new OddsFactory(new MyCustomLadder());
$odds = $factory->fromDecimal('1.90');
echo $odds->getFractional(); // "evens"

Working with Fixed Precision Integers

For performance-critical applications, you can work directly with fixed precision integers (decimal * 100):

$factory = new OddsFactory();

// Create from already prepared integer (2.50 = 250)
$odds = $factory->fromFixedPrecision(250);
echo $odds->getDecimal();           // "2.50"
echo $odds->getFixedPrecisionOdds(); // 250

// Useful for database storage or API responses
$integerOdds = $odds->getFixedPrecisionOdds(); // Store as integer
$restoredOdds = $factory->fromFixedPrecision($integerOdds); // Restore later

Migration from old odds-formatter.

See STRING_DECIMAL_GUIDE.md for detailed migration instructions.

Key Changes:

  • Use OddsFactory instead of individual odd classes
  • Pass decimals as strings: '2.50' instead of 2.50
  • All return values are strings for precision (except getProbability() which returns integer)
  • Single Odds object contains all formats
  • Odds class is immutable and should not be instantiated directly

Documentation

License

This is an open-sourced software licensed under the MIT license.

gryfoss/odds 适用场景与选型建议

gryfoss/odds 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 35 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 08 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「betting」 「odds」 「decimal odd」 「european odd」 「fractional odd」 「british odd」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 gryfoss/odds 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 gryfoss/odds 我们能提供哪些服务?
定制开发 / 二次开发

基于 gryfoss/odds 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 35
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 22
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-08-19