From b8a2140b3973d2a650a4d1c11a1ade331502bb95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20L=C3=B8vgaard?= Date: Fri, 16 Aug 2024 15:13:52 +0200 Subject: [PATCH] Validate cron schedule --- composer.json | 2 +- src/CronJob.php | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index c7780cc..0828f9e 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "require": { "php": ">=8.1", "ext-mbstring": "*", - "dragonmantank/cron-expression": "^2.0 || ^3.0" + "dragonmantank/cron-expression": "^2.3 || ^3.0" }, "require-dev": { "infection/infection": "^0.27.11", diff --git a/src/CronJob.php b/src/CronJob.php index 40b0dd1..150fad8 100644 --- a/src/CronJob.php +++ b/src/CronJob.php @@ -4,13 +4,20 @@ namespace Setono\CronBuilder; +use Cron\CronExpression; + final class CronJob implements \Stringable { + public readonly string $schedule; + public function __construct( - public readonly string $schedule, + string $schedule, public readonly string $command, public readonly ?string $description = null, ) { + new CronExpression($schedule); + + $this->schedule = $schedule; } public function toString(): string