@@ -24,6 +24,9 @@ class Expression
2424 /** @var Expression */
2525 protected static $ instance ;
2626
27+ /** @var SegmentChecker */
28+ protected $ checker ;
29+
2730 protected static $ expressions = [
2831 '@yearly ' => '0 0 1 1 * ' ,
2932 '@annually ' => '0 0 1 1 * ' ,
@@ -60,6 +63,15 @@ class Expression
6063 'dec ' => 12 ,
6164 ];
6265
66+ public function __construct (SegmentChecker $ checker = null )
67+ {
68+ $ this ->checker = $ checker ?: new SegmentChecker ;
69+
70+ if (null === static ::$ instance ) {
71+ static ::$ instance = $ this ;
72+ }
73+ }
74+
6375 public function instance ()
6476 {
6577 if (null === static ::$ instance ) {
@@ -109,13 +121,12 @@ public function isCronDue($expr, $time = null)
109121 {
110122 list ($ expr , $ times ) = $ this ->process ($ expr , $ time );
111123
112- $ checker = new SegmentChecker ;
113124 foreach ($ expr as $ pos => $ segment ) {
114125 if ($ segment === '* ' || $ segment === '? ' ) {
115126 continue ;
116127 }
117128
118- if (!$ checker ->checkDue ($ segment , $ pos , $ times )) {
129+ if (!$ this -> checker ->checkDue ($ segment , $ pos , $ times )) {
119130 return false ;
120131 }
121132 }
0 commit comments