src/TaskManager.php
public static function parseCrontab($cron, $task_class)
    {
        $cron_array = explode(PHP_EOL, $cron);
        $comment = null;
        $result = array();
        foreach ($cron_array as $c) {
            $c = trim($c);
            if (empty($c)) {
                continue;
            }
            $r = array($c);
            if (preg_match(self::CRON_LINE_REGEXP, $c, $matches)) {
                try {
                    CronExpression::factory($matches[2]);
                } catch (\Exception $e) {
                    $r[1] = 'Time expression is not valid';
                    $r[2] = $matches[2];
                    $result[] = $r;
                    continue;
                }
                $task = self::createTaskWithCrontabLine($task_class, $matches, $comment);

                $r [1] = 'Saved';
                $r [2] = $task;

                $comment = null;
            } elseif (preg_match('/#([\w\d\s]+)/i', $c, $matches)) {
                $comment = trim($matches[1]);
                $r [1] = 'Comment';
                $r [2] = $comment;
            } else {
                $r [1] = 'Not matched';
            }
            $result[] = $r;
        }

        return $result;
    }
public static function parseCrontab($cron, $task_class)
    {
        $cron_array = explode(PHP_EOL, $cron);
        $comment = null;
        $result = array();
        foreach ($cron_array as $c) {
            $c = trim($c);
            if (empty($c)) {
                continue;
            }
            $r = array($c);
            if (preg_match(self::CRON_LINE_REGEXP, $c, $matches)) {
                try {
                    CronExpression::factory($matches[2]);
                } catch (\Exception $e) {
                    $r[1] = 'Time expression is not valid';
                    $r[2] = $matches[2];
                    $result[] = $r;
                    continue;
                }
                $task = self::createTaskWithCrontabLine($task_class, $matches, $comment);

                $r [1] = 'Saved';
                $r [2] = $task;

                $comment = null;
            } elseif (preg_match('/#([\w\d\s]+)/i', $c, $matches)) {
                $comment = trim($matches[1]);
                $r [1] = 'Comment';
                $r [2] = $comment;
            } else {
                $r [1] = 'Not matched';
            }
            $result[] = $r;
        }

        return $result;
    }
public static function parseCrontab ( $ cron , $ task_class ) { $ cron_array = explode ( PHP_EOL , $ cron ) ; $ comment = null ; $ result = array ( ) ; foreach ( $ cron_array as $ c ) { $ c = trim ( $ c ) ; if ( empty ( $ c ) ) { continue ; } $ r = array ( $ c ) ; if ( preg_match ( self :: CRON_LINE_REGEXP , $ c , $ matches ) ) { try { CronExpression :: factory ( $ matches [ 2 ] ) ; } catch ( \ Exception $ e ) { $ r [ 1 ] = 'Time expression is not valid' ; $ r [ 2 ] = $ matches [ 2 ] ; $ result [ ] = $ r ; continue ; } $ task = self :: createTaskWithCrontabLine ( $ task_class , $ matches , $ comment ) ; $ r [ 1 ] = 'Saved' ; $ r [ 2 ] = $ task ; $ comment = null ; } elseif ( preg_match ( '/#([\w\d\s]+)/i' , $ c , $ matches ) ) { $ comment = trim ( $ matches [ 1 ] ) ; $ r [ 1 ] = 'Comment' ; $ r [ 2 ] = $ comment ; } else { $ r [ 1 ] = 'Not matched' ; } $ result [ ] = $ r ; } return $ result ; }
Parses each line of crontab content and creates new TaskInterface objects
@param string $cron
@param TaskInterface $task_class
@return array
Parses each line of crontab content and creates new TaskInterface objects