bkuhl/scripture-ranges 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

bkuhl/scripture-ranges

Composer 安装命令:

composer require bkuhl/scripture-ranges

包简介

A PHP library for handling scripture ranges with exclusions and JSON serialization

README 文档

README

A PHP library for handling scripture ranges with exclusions and JSON serialization. Create complex scripture ranges with a clean, fluent API.

Installation

composer require bkuhl/scripture-ranges

Creating Ranges (Recommended)

Use the ScriptureRangeBuilder with multiple syntax options:

use BKuhl\ScriptureRanges\ScriptureRangeBuilder;
use BKuhl\ScriptureRanges\ChapterRange;

$builder = new ScriptureRangeBuilder([$myBookResolver]);

// 1. Traditional parameter syntax
$collection = $builder
    ->with(BookEnum::JOHN, chapter: 3, verse: 1, toVerse: 36)
    ->without(BookEnum::JOHN, chapter: 3, verse: 16, toVerse: 17)
    ->build();

// 2. Chapter range syntax
$collection = $builder
    ->with(BookEnum::JOHN, chapter: 3, chapterEnd: 5)      // Multiple chapters
    ->with('Matthew', chapter: 5, verse: 1, toVerse: 48)   // Mixed with verse ranges
    ->build();

// 3. ChapterRange object syntax (cleanest for chapter ranges!)
$collection = $builder
    ->with(BookEnum::JOHN, ChapterRange::range(3, 5))      // Chapters 3-5
    ->with('Matthew', chapter: 5, verse: 1, toVerse: 48)   // Use traditional syntax for verses
    ->without(BookEnum::JOHN, chapter: 3, verse: 16)       // Use traditional syntax for single verses
    ->build();

// ChapterRange factory method:
ChapterRange::range(3, 5)             // Chapters 3-5 (full chapters)

Book Resolvers

To use flexible input types (strings, enums, integers), implement a BookResolverInterface:

use BKuhl\ScriptureRanges\Interfaces\BookResolverInterface;

class MyBookResolver implements BookResolverInterface
{
    public function resolve(mixed $book): BookInterface
    {
        if (is_string($book)) {
            return $this->getBookFromString($book);
        }
        
        if ($book instanceof MyBookEnum) {
            return $this->getBookFromEnum($book);
        }
        
        throw new InvalidArgumentException('Unable to resolve book');
    }

    public function canResolve(mixed $book): bool
    {
        return is_string($book) || $book instanceof MyBookEnum;
    }
}

// Use with builder
$builder = new ScriptureRangeBuilder([$myResolver]);

Working with Collections

// Create a collection with ID and name
$collection = new RangeCollection('reading-plan-123', 'Daily Reading');

// Or create without metadata
$collection = new RangeCollection();

// Set or update name and ID
$collection->setName('Morning Reading');
$collection->setId('morning-plan-456');

// Get name and ID
echo $collection->getName(); // "Morning Reading"
echo $collection->getId();   // "morning-plan-456"

// Check if a verse is in any range
echo $collection->contains($verse); // true/false

// Get formatted reference
echo $collection->reference(); // "John 3:16-17, Matthew 5:1-12"

// JSON serialization includes name and ID
$json = $collection->toJson();
// {
//   "name": "Morning Reading",
//   "id": "morning-plan-456", 
//   "ranges": [...]
// }

ChapterRange Quick Example

For working with chapter ranges, use the ChapterRange class:

use BKuhl\ScriptureRanges\ChapterRange;

// Create a chapter range
$range = ChapterRange::range(3, 5);  // Chapters 3-5

// Get start and end chapters
$start = $range->getStart();  // 3
$end = $range->getEnd();      // 5

// Use with ScriptureRangeBuilder
$collection = $builder
    ->with($book, ChapterRange::range(1, 3))    // Full chapters 1-3
    ->with($book, chapter: 4, verse: 1, toVerse: 10)  // Specific verses
    ->build();

Combining Ranges

Combine multiple ranges in the same book into a single range:

use BKuhl\ScriptureRanges\ScriptureRange;

$range1 = new ScriptureRange($book, 1, 2, 1, 25);
$range2 = new ScriptureRange($book, 3, 4, 1, 24);

$combined = ScriptureRange::combine([$range1, $range2]);
// Result: Genesis 1-4 with gaps between ranges excluded

Checking Consecutive Chapters

Check if ranges contain a minimum number of consecutive full chapters:

// Check a single range
$range = new ScriptureRange($book, 1, 3, 1, 24);
$range->hasConsecutiveChapters(3); // true if chapters 1, 2, 3 are all full

// Check across multiple ranges in a collection
$collection = (new ScriptureRangeBuilder())
    ->with($book, chapter: 1, chapterEnd: 2)
    ->with($book, chapter: 3, chapterEnd: 4)
    ->build();

$collection->hasConsecutiveChapters(4); // true if chapters 1-4 are all full across ranges

bkuhl/scripture-ranges 适用场景与选型建议

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

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

围绕 bkuhl/scripture-ranges 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

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