Beispiel #1
0
 public function pushControlWord(RTFToken $token)
 {
     if ($token->getType() != RTFToken::T_CONTROL_WORD) {
         throw new Exception("Incorrect token type");
     }
     array_push($this->controls, $token);
 }
Beispiel #2
0
 /**
  * @param RTFToken $token
  * @throws \Exception
  */
 protected function parseToken($token)
 {
     switch ($token->getType()) {
         // Start a new Group
         case RTFToken::T_START_GROUP:
             $group = new RTFGroup();
             $parent = end($this->groupStack);
             if ($parent) {
                 $parent->pushGroup($group);
             } else {
                 $this->rootGroup = $group;
             }
             $this->groupStack[] = $group;
             break;
             // End the active group
         // End the active group
         case RTFToken::T_END_GROUP:
             if (empty($this->groupStack)) {
                 throw new \Exception("Can not close group when open group doesn't exist");
             }
             array_pop($this->groupStack);
             break;
             // Attach a control word to the active group
         // Attach a control word to the active group
         case RTFToken::T_CONTROL_WORD:
             if (empty($this->groupStack)) {
                 throw new \Exception("Can not use control word when open group doesn't exist");
             }
             $group = end($this->groupStack);
             if (isset(RTFTokenizer::$contentControlWords[$token->getName()])) {
                 $group->pushContent($token);
             } else {
                 $group->pushControlWord($token);
             }
             break;
             // Add content into the active group
         // Add content into the active group
         case RTFToken::T_CONTROL_SYMBOL:
         case RTFToken::T_TEXT:
             if (empty($this->groupStack)) {
                 throw new \Exception("Can not use content when open group doesn't exist");
             }
             $group = end($this->groupStack);
             $group->pushContent($token);
             break;
     }
 }