Example #1
0
 private function parseCurrentLine()
 {
     switch ($this->currentState) {
         case self::STATE_UNKNOWN:
             $this->deriveStateFromCurrentLine();
             $this->previousState = self::STATE_UNKNOWN;
             break;
         case self::STATE_STARTING_RECORD:
             $this->currentRecord = new \webignition\RobotsTxt\Record\Record();
             $this->currentState = self::STATE_ADDING_TO_RECORD;
             $this->previousState = self::STATE_STARTING_RECORD;
             break;
         case self::STATE_ADDING_TO_RECORD:
             if ($this->isCurrentLineARecordlessDirective()) {
                 $this->currentState = self::STATE_ADDING_TO_FILE;
                 $this->previousState = self::STATE_ADDING_TO_RECORD;
                 return;
             }
             if ($this->isCurrentLineADirective()) {
                 $directive = $this->directiveFactory()->getDirective($this->getCurrentLine());
                 if ($directive->is(self::USER_AGENT_FIELD_NAME)) {
                     $this->currentRecord->userAgentDirectiveList()->add($directive->getValue());
                 } else {
                     $this->currentRecord->directiveList()->add($this->getCurrentLine());
                 }
             } else {
                 if ($this->isCurrentLineBlank()) {
                     $this->file->addRecord($this->currentRecord);
                     $this->currentRecord = null;
                 }
                 $this->currentState = self::STATE_UNKNOWN;
             }
             $this->sourceLineIndex++;
             break;
         case self::STATE_ADDING_TO_FILE:
             $this->file->directiveList()->add($this->getCurrentLine());
             $this->currentState = $this->previousState == self::STATE_ADDING_TO_RECORD ? self::STATE_ADDING_TO_RECORD : self::STATE_UNKNOWN;
             $this->previousState = self::STATE_ADDING_TO_FILE;
             $this->sourceLineIndex++;
             break;
         default:
     }
 }