定制 akki-io/cron-expression-generator 二次开发

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

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

akki-io/cron-expression-generator

最新稳定版本:v1.0

Composer 安装命令:

composer require akki-io/cron-expression-generator

包简介

Create a cron expression based on user input

README 文档

README

Hero

Cron Expression Generator

Latest Version Build Status Quality Score Software License StyleCI Total Downloads

Generate cron expressions based on user inputs.

Installation

You can install the package via composer:

composer require akki-io/cron-expression-generator

Introduction

A CRON expression is a string representing the schedule for a particular command to execute. The parts of a CRON schedule are as follows:

*    *    *    *    *
-    -    -    -    -
|    |    |    |    |
|    |    |    |    |
|    |    |    |    +----- day of week (0 - 6) (Sunday=0)
|    |    |    +---------- month (1 - 12)
|    |    +--------------- day of month (1 - 31)
|    +-------------------- hour (0 - 23)
+------------------------- min (0 - 59)
Cron Schedule Package Request Mapping
min minute
hour hour
day of month day_month
month month
day of week day_week

This package supports the following different options for each schedule.

Option Type (*required) Description Nested Required Parameters
ONCE Generate cron once int at, b/t the range of schedule
EVERY Generate cron for every int every, b/t the range of schedule
LIST Generate cron based on the list of values array list and int list.*, b/t the range of schedule
RANGE Generate cron based on range int start and int end both b/t the range of schedule
STEP Generate cron based on step int every, int start and int end all b/t the range of schedule

Usage

You can set the $options array below based on the different options as outlined above.

    use AkkiIo\CronExpressionGenerator\CronExpressionGenerator;

    $options = [];

    $cronExpression = (new CronExpressionGenerator($options))->generate();

Examples

Generate cron expression for every minute

    $options = [];

    $cronExpression = (new CronExpressionGenerator($options))->generate();
      
    // * * * * *

Generate cron expression for once every hour

    $options = [
        'minute' => [
            'type' => 'ONCE',
            'at' => 0,
        ],
        'hour' => [
            'type' => 'EVERY',
            'every' => 1,
        ],
    ];

    $cronExpression = (new CronExpressionGenerator($options))->generate();
    
    // 0 */1 * * *

Generate cron expression for once every day at 10:15 AM

    $options = [
        'minute' => [
            'type' => 'ONCE',
            'at' => 15,
        ],
        'hour' => [
            'type' => 'ONCE',
            'at' => 10,
        ],
    ];

    $cronExpression = (new CronExpressionGenerator($options))->generate();
    
    // 15 10 * * *

Generate cron expression for once every weekday at 10:15 AM

    $options = [
        'minute' => [
            'type' => 'ONCE',
            'at' => 15,
        ],
        'hour' => [
            'type' => 'ONCE',
            'at' => 10,
        ],
        'day_week' => [
            'type' => 'RANGE',
            'start' => 1,
            'end' => 5,
        ],
    ];

    $cronExpression = (new CronExpressionGenerator($options))->generate();
    
    // 15 10 * * 1-5

Generate cron expression for once every month of day 22 at 10:15 AM

    $options = [
        'minute' => [
            'type' => 'ONCE',
            'at' => 15,
        ],
        'hour' => [
            'type' => 'ONCE',
            'at' => 10,
        ],
        'day_month' => [
            'type' => 'ONCE',
            'at' => 22,
        ],
    ];

    $cronExpression = (new CronExpressionGenerator($options))->generate();
      
    // 15 10 22 * *

Generate cron expression for every Sunday at 10:15 AM

    $options = [
        'minute' => [
            'type' => 'ONCE',
            'at' => 15,
        ],
        'hour' => [
            'type' => 'ONCE',
            'at' => 10,
        ],
        'day_week' => [
            'type' => 'ONCE',
            'at' => 0,
        ],
    ];

    $cronExpression = (new CronExpressionGenerator($options))->generate();
      
    // 15 10 * * 0

Generate cron expression for every year on Oct 22 at 10:15 AM

    $options = [
        'minute' => [
            'type' => 'ONCE',
            'at' => 15
        ],
        'hour' => [
            'type' => 'ONCE',
            'at' => 10,
        ],
        'day_month' => [
            'type' => 'ONCE',
            'at' => 22,
        ],
        'month' => [
            'type' => 'ONCE',
            'at' => 10,
        ],
    ];

    $cronExpression = (new CronExpressionGenerator($options))->generate();
      
    // 15 10 22 10 *

Testing

composer test

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email hello@akki.io instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-05-26