wilianx7/php-recurring
Composer 安装命令:
composer require wilianx7/php-recurring
包简介
PHP library for generating recurring dates, schedules, and repeated task recurrences.
关键字:
README 文档
README
PHP library for generating recurring dates for schedules, repeated tasks, and calendar-like recurrence rules.
Supports daily, weekly, monthly, and yearly recurrences with custom intervals, end conditions, skipped dates, and Carbon or DateTimeInterface inputs.
Useful for:
- recurring tasks
- recurring events
- appointment schedules
- reminder schedules
- repeated billing dates
- calendar-style date generation
Installation
You can install the package via composer:
composer require wilianx7/php-recurring
Features
- Generate recurring dates for daily, weekly, monthly, and yearly schedules
- Set recurrence end rules with
NEVER,IN, orAFTER - Skip specific dates with
exceptDates - Optionally include the start date in the generated collection
- Use
Carbon,DateTime, orDateTimeImmutablein configuration
Basic usage
RecurringConfig accepts any DateTimeInterface in its date setters, so you can use Carbon, DateTime, or DateTimeImmutable.
- Configuration for every day recurrence ending never:
$startDate = new DateTimeImmutable('2019-12-26 08:00:00'); $endDate = new DateTimeImmutable('2019-12-31 23:59:59'); $recurringConfig = new RecurringConfig(); $recurringConfig->setStartDate($startDate) ->setFrequencyType(FrequencyTypeEnum::DAY()) ->setFrequencyInterval(1) ->setFrequencyEndType(FrequencyEndTypeEnum::NEVER()) ->setEndDate($endDate); $dates = RecurringBuilder::forConfig($recurringConfig)->startRecurring();
- Configuration for weekly recurrence (Monday and Sunday) ending after 5 occurrences:
$recurringConfig = new RecurringConfig(); $recurringConfig->setStartDate(new DateTimeImmutable('2019-01-01 08:00:00')) ->setFrequencyType(FrequencyTypeEnum::WEEK()) ->setFrequencyInterval(1) ->setFrequencyEndType(FrequencyEndTypeEnum::AFTER()) ->setFrequencyEndValue(5) ->setRepeatIn([WeekdayEnum::MONDAY(), WeekdayEnum::SUNDAY()]) ->setEndDate(new DateTimeImmutable('2019-12-31 23:59:59')); $dates = RecurringBuilder::forConfig($recurringConfig)->startRecurring();
- Configuration for monthly recurrence (day 27) ending in 2019-11-30:
$recurringConfig = new RecurringConfig(); $recurringConfig->setStartDate(new DateTimeImmutable('2019-01-01 08:00:00')) ->setFrequencyType(FrequencyTypeEnum::MONTH()) ->setFrequencyInterval(1) ->setFrequencyEndType(FrequencyEndTypeEnum::IN()) ->setFrequencyEndValue(new DateTimeImmutable('2019-11-30 00:00:00')) ->setRepeatIn(27) ->setEndDate(new DateTimeImmutable('2019-12-31 23:59:59')); $dates = RecurringBuilder::forConfig($recurringConfig)->startRecurring();
- Configuration for yearly recurrence (day 27 and month 10) ending in 2019-11-30:
$recurringConfig = new RecurringConfig(); $recurringConfig->setStartDate(new DateTimeImmutable('2019-01-01 08:00:00')) ->setFrequencyType(FrequencyTypeEnum::YEAR()) ->setFrequencyInterval(1) ->setFrequencyEndType(FrequencyEndTypeEnum::IN()) ->setFrequencyEndValue(new DateTimeImmutable('2019-11-30 00:00:00')) ->setRepeatIn(['day' => 27, 'month' => 10]) ->setEndDate(new DateTimeImmutable('2019-12-31 23:59:59')); $dates = RecurringBuilder::forConfig($recurringConfig)->startRecurring();
Recurring Config
| Attribute | Description | Default |
|---|---|---|
startDate |
Date the search will start for find the dates the recurrence should be generated. | Start of current year |
endDate |
Date the search for the dates will ended. | End of current year |
frequencyType |
How often the recurrence will be generated accord of the enum FrequencyTypeEnum. Can be setted as: DAY, WEEK, MONTH or YEAR. | FrequencyTypeEnum::DAY() |
frequencyInterval |
Determines the interval between recurrences according to the chosen frequency type. | 1 |
repeatIn |
Determines when recurrence should be generated according to the frequency type chosen. Can be setted, for example, as: null (for DAY); [ WeekdayEnum::MONDAY(), WeekdayEnum::SUNDAY() ] (for WEEK); 31 (for MONTH); ['day' => 31, 'month' => 2] (for YEAR)." | Null |
frequencyEndType |
Determines what will be the stopping criterion for recurrence generation according of the enum FrequencyEndTypeEnum. Can be setted as: NEVER, IN or AFTER. | FrequencyEndTypeEnum::NEVER() |
frequencyEndValue |
Determines a value according to the chosen stop criterion. Can be setted, for example, as: null (for NEVER); 3 (for AFTER); any DateTimeInterface instance such as DateTimeImmutable or Carbon (for IN). |
Null |
lastRepeatedDate |
Date the last recurrence was generated. It is used to avoid unnecessary date generation by calling the generation method more than once. | Null |
repeatedCount |
How many recurrences have already been generated. It is used to avoid unnecessary date generation by calling the generation method more than once. | Null |
exceptDates |
Dates when recurrence should not be generated even if the date conforms to the specified setting. Accepts native array. | Null |
includeStartDate |
Defines whether the start date should be included in the return array | false |
- includeStartDate: By default, the start date is not included in the return array, as it assumes that this date is already in use, requiring only the return of subsequent dates. However, you can override this behavior by setting "includeStartDate" property as true.
Recurring Builder
| Method | Description | Return |
|---|---|---|
forConfig |
Used to construct the recurrence according to setting passed by parameter. | Self |
startRecurring |
Start generating dates for recurrence | An array with all the dates generated |
Enums
| Enum | Values |
|---|---|
FrequencyEndTypeEnum |
NEVER, IN, AFTER |
FrequencyTypeEnum |
DAY, WEEK, MONTH, YEAR |
WeekdayEnum |
SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY |
Testing
composer run test
wilianx7/php-recurring 适用场景与选型建议
wilianx7/php-recurring 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 49.26k 次下载、GitHub Stars 达 10, 最近一次更新时间为 2019 年 12 月 31 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「schedule」 「calendar」 「recurring」 「scheduling」 「rrule」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 wilianx7/php-recurring 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 wilianx7/php-recurring 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 wilianx7/php-recurring 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Enables the creation of cron-jobs tasks to be consumed by symfony/messenger
A modern PHP library for generating iCalendar v2.0 events
A Deployment/Change Log Schedule and Notes system for SilverStripe sites
A powerful event calendar Tool for Laravel's Nova 5.
Check for holidays - localeaware
Monitoring for scheduled jobs
统计信息
- 总下载量: 49.26k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 10
- 点击次数: 26
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-12-31