forked from contributte/scheduler
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring: CronExpressionJob abstraction
- Loading branch information
1 parent
bf4592e
commit 2eb0169
Showing
2 changed files
with
49 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace Tlapnet\Scheduler; | ||
|
||
use Cron\CronExpression; | ||
use DateTime; | ||
|
||
abstract class CronJob implements IJob | ||
{ | ||
|
||
/** @var CronExpression */ | ||
protected $expression; | ||
|
||
/** | ||
* @param string $cron | ||
*/ | ||
public function __construct($cron) | ||
{ | ||
$this->expression = CronExpression::factory($cron); | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function isDue() | ||
{ | ||
return $this->expression->isDue(); | ||
} | ||
|
||
/** | ||
* @param DateTime $dateTime | ||
* @return bool | ||
*/ | ||
public function isDueByDate(DateTime $dateTime) | ||
{ | ||
return $this->expression->isDue($dateTime); | ||
} | ||
|
||
/** | ||
* @return CronExpression | ||
*/ | ||
public function getExpression() | ||
{ | ||
return $this->expression; | ||
} | ||
|
||
} |