hollodotme/crontab-validator
最新稳定版本:v2.0.1
Composer 安装命令:
composer require hollodotme/crontab-validator
包简介
A validator for crontab expressions.
README 文档
README
CrontabValidator
A validator for crontab expressions.
Sources used to determine the allowed expressions:
Features
- Validation of crontab expressions like 6,21,36,51 7-23/1 * FEB-NOV/2 *.
Requirements
- PHP >= 7.1
Installation
composer require "hollodotme/crontab-validator"
Usage
Boolean validation
<?php declare(strict_types=1); namespace MyVendor\MyProject; use hollodotme\CrontabValidator\CrontabValidator; $validator = new CrontabValidator(); if ( $validator->isExpressionValid( '6,21,36,51 7-23/1 * FEB-NOV/2 *' ) ) { echo 'Expression is valid.'; } else { echo 'Expression is invalid.'; }
Guarding
<?php declare(strict_types=1); namespace MyVendor\MyProject; use hollodotme\CrontabValidator\CrontabValidator; use hollodotme\CrontabValidator\Exceptions\InvalidExpressionException; $validator = new CrontabValidator(); try { # => All fine, execution continues $validator->guardExpressionIsValid( '6,21,36,51 7-23/1 * FEB-NOV/2 *' ); # => This will raise an InvalidExpressionException $validator->guardExpressionIsValid( 'this is not a valid interval' ); } catch ( InvalidExpressionException $e ) { echo $e->getMessage(); }
Prints:
Invalid crontab expression: "this is not a valid interval"
Feedback and contributions welcome!
统计信息
- 总下载量: 204.52k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 11
- 点击次数: 1
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-08-29