2017 © Pedro Peláez
 

project utility-cron

Cron PHP library

image

sivaschenko/utility-cron

Cron PHP library

  • Monday, January 8, 2018
  • by sivashchenko
  • Repository
  • 1 Watchers
  • 0 Stars
  • 10,221 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 2 Versions
  • 30 % Grown

The README.md

PHP Cron Library

Codacy Badge Build Status StyleCI codecov, (*1)

The PHP Cron Library can be used to get human readable cron expression description and detailed validation messages. Any level of expression complexity is handled., (*2)

Code examples

Human readable cron expression description example:, (*3)

$expression = \Sivaschenko\Utility\Cron\ExpressionFactory::getExpression('5 4 8 * *');

echo $expression->getVerbalString(); // "At 04:05, on 8th day of month."

Cron expression validation example:, (*4)

$expression = \Sivaschenko\Utility\Cron\ExpressionFactory::getExpression('60 * * * 2- *');

if (!$expression->isValid()) {
    print_r($expression->getValidationMessages());
}

/*
Array
(
    [0] => Minute expression part value "60" is greater than max allowed "59"
    [1] => Missing second part of "range" expression ("2-")
)
*/

Functionality examples

Examples of expression translation to verbal format:, (*5)

Cron Expression Description
* * * * * At every minute.
@weekly On Monday at midnight
5 4 8 * * At 04:05, on 8th day of month.
* * * * FRIL * At every minute, on last Friday of the month.
* * * 2/2 mon/3 At every minute, every 2nd month starting from February, every 3rd day of week starting from Monday.
30/5 2-6 ? jan,feb 2#4 2017 Every 5th minute starting from 30th, every hour from 2nd through 6th, in January and February, every 4th Tuesday, in 2017

Examples of cron expression validation:, (*6)

Invalid Cron Expression Validation Messages
fd * * * * * Minute expression part value "fd" is not valid! Allowed values are integers from 0 to 59, keywords: "*", "?"
60 * * * 2# * Minute expression part value "60" is greater than max allowed "59", Missing second part of "each" expression ("2#")
* * * * mon/tue * Second part of expression "mon/tue" can only be integer!
* * 4L * * * Day of month expression part value "4L" is not valid! Allowed values are integers from 1 to 31, keywords: "*", "?", "W", "L" Allowed suffixes: "W"
@invalid Unknown shortcut expression "@invalid"! List of valid shortcut expressions: "@reboot", "@midnight", "@daily", "@yearly", "@annually", "@monthly", "@weekly", "@hourly".

Installation

Add dependency on library to composer.json and update or execute the following command:, (*7)

composer require sivaschenko/utility-cron

Be sure to require composer generated autoload in your project:, (*8)

require 'vendor/autoload.php';

Now see "Code examples" for usage instructions., (*9)

Test Coverage

Verbal translation, validation and even exceptions are covered with integration tests., (*10)

See \Sivaschenko\Utility\Cron\Test\ExpressionTest for details., (*11)


Crafted with ♥ for developers., (*12)

The Versions

08/01 2018

dev-master

9999999-dev

Cron PHP library

  Sources   Download

MIT

The Development Requires

20/11 2016

1.0.0

1.0.0.0

Cron PHP library

  Sources   Download

MIT

The Development Requires