Skip to content

Commit b8aa4ce

Browse files
committed
feat(expr): add ::instance() api
1 parent cee9bf7 commit b8aa4ce

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/Expression.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ class Expression
6060
'dec' => 12,
6161
];
6262

63+
public function instance()
64+
{
65+
if (null === static::$instance) {
66+
static::$instance = new static;
67+
}
68+
69+
return static::$instance;
70+
}
71+
6372
/**
6473
* Parse cron expression to decide if it can be run on given time (or default now).
6574
*
@@ -70,11 +79,7 @@ class Expression
7079
*/
7180
public static function isDue($expr, $time = null)
7281
{
73-
if (null === static::$instance) {
74-
static::$instance = new static;
75-
}
76-
77-
return static::$instance->isCronDue($expr, $time);
82+
return static::instance()->isCronDue($expr, $time);
7883
}
7984

8085
/**
@@ -87,11 +92,7 @@ public static function isDue($expr, $time = null)
8792
*/
8893
public static function getDues(array $jobs, $time = null)
8994
{
90-
if (null === static::$instance) {
91-
static::$instance = new static;
92-
}
93-
94-
return static::$instance->filter($jobs, $time);
95+
return static::instance()->filter($jobs, $time);
9596
}
9697

9798
/**

0 commit comments

Comments
 (0)