6 const REGEXP_SECTION_BEGIN =
'/^#\s+BEGIN:FREEDOM_CRONTAB:(?P<contextRoot>[^:]+):(?P<file>.*)$/';
7 const REGEXP_SECTION_END =
'/^#\s+END:FREEDOM_CRONTAB:(?P<contextRoot>[^:]+):(?P<file>.*)$/';
15 public function parse($crontab)
17 $lines = explode(
"\n", $crontab);
21 $currentSection = null;
24 while ($i < count($lines)) {
26 if ($currentSection !== null) {
27 if (preg_match(self::REGEXP_SECTION_END, $line, $m)) {
28 if (!$currentSection->match($m[
'contextRoot'], $m[
'file'])) {
29 throw new CrontabParserException(sprintf(
"Section end mismatch at line #%d: expecting '%s:%s', found '%s:%s'", ($i + 1) , $currentSection->contextRoot, $currentSection->file, $m[
'contextRoot'], $m[
'file']));
31 $crontabDocument->appendChild($currentSection);
32 $currentSection = null;
35 $currentSection->appendChild($newTextElement);
38 if (preg_match(self::REGEXP_SECTION_BEGIN, $line, $m)) {
39 if ($currentSection !== null) {
40 throw new CrontabParserException(sprintf(
"Beginning of section found while already in a section at line #%d", ($i+1)));
45 $crontabDocument->appendChild($newTextElement);
50 if ($currentSection !== null) {
54 return $crontabDocument;