An open API service indexing awesome lists of open source software.

https://github.com/hollodotme/crontab-validator

A validator for crontab expressions
https://github.com/hollodotme/crontab-validator

crontab crontab-syntax expression php validator

Last synced: 8 months ago
JSON representation

A validator for crontab expressions

Awesome Lists containing this project

README

          

[![Build Status](https://travis-ci.org/hollodotme/crontab-validator.svg?branch=master)](https://travis-ci.org/hollodotme/crontab-validator)
[![Coverage Status](https://coveralls.io/repos/github/hollodotme/crontab-validator/badge.svg?branch=master)](https://coveralls.io/github/hollodotme/crontab-validator?branch=master)
[![Latest Stable Version](https://poser.pugx.org/hollodotme/crontab-validator/v/stable)](https://packagist.org/packages/hollodotme/crontab-validator)
[![Total Downloads](https://poser.pugx.org/hollodotme/crontab-validator/downloads)](https://packagist.org/packages/hollodotme/crontab-validator)
[![License](https://poser.pugx.org/hollodotme/crontab-validator/license)](https://packagist.org/packages/hollodotme/crontab-validator)

# CrontabValidator

A validator for crontab expressions.

Sources used to determine the allowed expressions:

* https://crontab.guru/
* https://en.wikipedia.org/wiki/Cron

## 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
isExpressionValid( '6,21,36,51 7-23/1 * FEB-NOV/2 *' ) )
{
echo 'Expression is valid.';
}
else
{
echo 'Expression is invalid.';
}
```

### Guarding

```php
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!