Skip to content

Commit

Permalink
feat(expr): add ::instance() api
Browse files Browse the repository at this point in the history
  • Loading branch information
adhocore committed Aug 16, 2018
1 parent cee9bf7 commit b8aa4ce
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/Expression.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ class Expression
'dec' => 12,
];

public function instance()
{
if (null === static::$instance) {
static::$instance = new static;
}

return static::$instance;
}

/**
* Parse cron expression to decide if it can be run on given time (or default now).
*
Expand All @@ -70,11 +79,7 @@ class Expression
*/
public static function isDue($expr, $time = null)
{
if (null === static::$instance) {
static::$instance = new static;
}

return static::$instance->isCronDue($expr, $time);
return static::instance()->isCronDue($expr, $time);
}

/**
Expand All @@ -87,11 +92,7 @@ public static function isDue($expr, $time = null)
*/
public static function getDues(array $jobs, $time = null)
{
if (null === static::$instance) {
static::$instance = new static;
}

return static::$instance->filter($jobs, $time);
return static::instance()->filter($jobs, $time);
}

/**
Expand Down

0 comments on commit b8aa4ce

Please sign in to comment.