Varien_Event_Observer_Cron Class Reference

Inheritance diagram for Varien_Event_Observer_Cron:

Varien_Event_Observer Varien_Object

List of all members.

Public Member Functions

 isValidFor (Varien_Event $event)
 getNow ()
 matchCronExpression ($expr, $num)
 getNumeric ($value)


Detailed Description

Definition at line 35 of file Cron.php.


Member Function Documentation

getNow (  ) 

Definition at line 61 of file Cron.php.

00062     {
00063         if (!$this->hasNow()) {
00064             $this->setNow(time());
00065         }
00066         return $this->getData('now');
00067     }

getNumeric ( value  ) 

Definition at line 120 of file Cron.php.

00121     {
00122         static $data = array(
00123             'jan'=>1,
00124             'feb'=>2,
00125             'mar'=>3,
00126             'apr'=>4,
00127             'may'=>5,
00128             'jun'=>6,
00129             'jul'=>7,
00130             'aug'=>8,
00131             'sep'=>9,
00132             'oct'=>10,
00133             'nov'=>11,
00134             'dec'=>12,
00135             
00136             'sun'=>0,
00137             'mon'=>1,
00138             'tue'=>2,
00139             'wed'=>3,
00140             'thu'=>4,
00141             'fri'=>5,
00142             'sat'=>6,
00143         );
00144         
00145         if (is_numeric($value)) {
00146             return $value;
00147         }
00148         
00149         if (is_string($value)) {
00150             $value = strtolower(substr($value,0,3));
00151             if (isset($data[$value])) {
00152                 return $data[$value];
00153             }
00154         }
00155                 
00156         return false;
00157     }

isValidFor ( Varien_Event event  ) 

Checkes the observer's cron string against event's name

Supports $this->setCronExpr('* 0-5,10-59/5 2-10,15-25 january-june/2 mon-fri')

Parameters:
Varien_Event $event
Returns:
boolean

Reimplemented from Varien_Event_Observer.

Definition at line 45 of file Cron.php.

00046     {
00047         $e = preg_split('#\s+#', $this->getCronExpr(), null, PREG_SPLIT_NO_EMPTY);
00048         if (sizeof($e)!==5) {
00049             return false;
00050         }
00051         
00052         $d = getdate($this->getNow());
00053         
00054         return $this->matchCronExpression($e[0], $d['minutes'])
00055             && $this->matchCronExpression($e[1], $d['hours'])
00056             && $this->matchCronExpression($e[2], $d['mday'])
00057             && $this->matchCronExpression($e[3], $d['mon'])
00058             && $this->matchCronExpression($e[4], $d['wday']);
00059     }

matchCronExpression ( expr,
num 
)

Definition at line 69 of file Cron.php.

00070     {
00071         // handle ALL match
00072         if ($expr==='*') {
00073             return true;
00074         }
00075         
00076         // handle multiple options
00077         if (strpos($expr,',')!==false) {
00078             foreach (explode(',',$expr) as $e) {
00079                 if ($this->matchCronExpression($e, $num)) {
00080                     return true;
00081                 }
00082             }
00083             return false;
00084         }
00085         
00086         // handle modulus
00087         if (strpos($expr,'/')!==false) {
00088             $e = explode('/', $expr);
00089             if (sizeof($e)!==2) {
00090                 return false;
00091             }
00092             $expr = $e[0];
00093             $mod = $e[1];
00094             if (!is_numeric($mod)) {
00095                 return false;
00096             }
00097         } else {
00098             $mod = 1;
00099         }
00100         
00101         // handle range
00102         if (strpos($expr,'-')!==false) {
00103             $e = explode('-', $expr);
00104             if (sizeof($e)!==2) {
00105                 return false;
00106             }
00107             
00108             $from = $this->getNumeric($e[0]);
00109             $to = $this->getNumeric($e[1]);
00110             
00111             return ($from!==false) && ($to!==false) 
00112                 && ($num>=$from) && ($num<=$to) && ($num%$mod===0);
00113         }
00114         
00115         // handle regular token
00116         $value = $this->getNumeric($expr);
00117         return ($value!==false) && ($num==$value) && ($num%$mod===0);
00118     }


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:25:02 2009 for Magento by  doxygen 1.5.8