Example #1
0
 /**
  * Returns an array of Cron Jobs based on the contents of a file.
  *
  * @param string $input
  *
  * @return Job[]
  */
 protected function parseString($input)
 {
     $jobs = array();
     $lines = array_filter(explode(PHP_EOL, $input), function ($line) {
         return '' != trim($line);
     });
     foreach ($lines as $line) {
         $trimmed = trim($line);
         // if line is not a comment, convert it to a cron
         if (0 !== \strpos($trimmed, '#')) {
             $jobs[] = Job::parse($line);
         }
     }
     return $jobs;
 }
Example #2
0
 public function testParseJobLine()
 {
     $jobLine = '1 2 3 4 5 cmd >> test.log 2>&1 # some comments';
     $job = Job::parse($jobLine);
     $this->assertEquals('1', $job->getMinute());
     $this->assertEquals('2', $job->getHour());
     $this->assertEquals('3', $job->getDayOfMonth());
     $this->assertEquals('4', $job->getMonth());
     $this->assertEquals('5', $job->getDayOfWeek());
     $this->assertEquals('cmd', $job->getCommand());
     $this->assertEquals('test.log', $job->getLogFile());
     $this->assertEquals('some comments', $job->getComments());
 }
Example #3
0
 /**
  * Returns an array of Cron Jobs based on the contents of a file.
  *
  * @param string $input
  *
  * @return array of Variable and Job instances
  */
 protected function parseString($input)
 {
     $elements = array();
     $lines = array_filter(explode(PHP_EOL, $input), function ($line) {
         return '' != trim($line);
     });
     foreach ($lines as $line) {
         $trimmed = trim($line);
         // if line is not a comment, convert it to a cron
         if (0 !== \strpos($trimmed, '#')) {
             if (preg_match('/^[^\\s]+\\s?=/', $line)) {
                 $elements[] = Variable::parse($line);
             } else {
                 $elements[] = Job::parse($line);
             }
         }
     }
     return $elements;
 }