CronLingo\Parser::evaluate PHP Method

evaluate() protected method

Evaluate tokens and build CRON expression
protected evaluate ( )
    protected function evaluate()
    {
        if ($this->position >= count($this->tokens)) {
            return;
            // Finished parsing
        }
        $token = $this->current()['token'];
        $value = $this->current()['value'];
        switch ($token) {
            case 'T_EVERY':
                $this->expects($this->next(), array('T_INTERVAL', 'T_FIELD', 'T_DAYOFWEEK', 'T_ONAT', 'T_WEEKDAYWEEKEND'));
                break;
            case 'T_INTERVAL':
                $this->expects($this->next(), array('T_FIELD', 'T_TO'));
                break;
            case 'T_EXACTTIME':
                $meridiem = '';
                if ($this->is($this->next(), array('T_MERIDIEM'))) {
                    $meridiem = $this->next()['value'];
                }
                $hours = $minutes = 0;
                $parts = explode(':', $value);
                if (isset($parts[0])) {
                    $hours = $parts[0];
                }
                if (isset($parts[1])) {
                    $minutes = $parts[1];
                }
                if ($meridiem == 'pm' || strpos($value, 'pm') || strpos($value, 'p') !== false) {
                    $hours += 12;
                }
                if ($this->is($this->previous(), 'T_ONAT')) {
                    $this->cron->hour->setSpecific([intval($hours)]);
                    $this->cron->minute->setSpecific([intval($minutes)]);
                } else {
                    $this->cron->hour->addSpecific(intval($hours));
                    $this->cron->minute->addSpecific(intval($minutes));
                }
                break;
            case 'T_WEEKDAYWEEKEND':
                $this->expects($this->previous(), array('T_ONAT', 'T_EVERY'));
                $this->cron->dayOfWeek->setSpecific($this->weekdayWeekendMap[$value]);
                $this->nilTime($this->cron->dayOfWeek);
                break;
            case 'T_DAYOFWEEK':
                $this->expects($this->previous(), array('T_ONAT', 'T_INTERVAL', 'T_EVERY', 'T_DAYOFWEEK'));
                $this->cron->dayOfWeek->addSpecific($this->dayOfWeekMap[$value]);
                $this->nilTime($this->cron->dayOfWeek);
                break;
            case 'T_TO':
                $this->expects($this->next(), 'T_INTERVAL');
                $this->expects($this->previous(), 'T_INTERVAL');
                break;
            case 'T_TIMEOFDAY':
                $this->expects($this->previous(), array('T_ONAT'));
                $this->cron->hour->setSpecific([$this->timeOfDayMap[$value]]);
                $this->nilTime($this->cron->hour);
                break;
            case 'T_MONTH':
                $this->expects($this->previous(), array('T_ONAT', 'T_IN'));
                $this->cron->month->addSpecific($this->monthMap[$value]);
                $this->nilTime($this->cron->month);
                break;
            case 'T_FIELD':
                $this->expects($this->previous(), array('T_INTERVAL', 'T_EVERY'));
                if (isset($this->fieldMap[$value])) {
                    if ($this->is($this->previous(), 'T_INTERVAL')) {
                        $value = $this->fieldMap[$value];
                    } else {
                        break;
                    }
                }
                $field = $this->cron->{$value};
                if ($this->is($this->previous(2), 'T_TO')) {
                    $this->expects($this->previous(3), array('T_INTERVAL'));
                    // Range
                    $field->setRange($this->previous(3)['value'], $this->previous()['value']);
                } else {
                    if ($this->is($this->previous(), array('T_INTERVAL', 'T_EVERY'))) {
                        $previous = $this->previous()['value'];
                        if ($this->is($this->previous(), 'T_EVERY')) {
                            $method = 'addSpecific';
                            $amt = '*';
                        } else {
                            $method = $this->is($this->previous(2), 'T_EVERY') ? 'repeatsOn' : 'addSpecific';
                            $amt = isset($this->intervalMap[$previous]) ? $this->intervalMap[$previous] : intval($previous);
                        }
                        $field->{$method}($amt);
                    }
                }
                $this->nilTime($field);
                break;
            default:
                break;
        }
        $this->position++;
        $this->evaluate();
    }