Beispiel #1
0
 /**
  * Parses a control symbol token
  * 
  * @param  Jstewnc\Rtf\Token\Control\Symbol $token  the control symbol token
  * @param  Jstewmc\Rtf\Element\Group        $group  the current group
  * @return  void
  * @since  0.1.0
  */
 protected function parseControlSymbol(Token\Control\Symbol $token, Element\Group $group)
 {
     // if a class exists for the symbol, instantiate it; otherwise, instantiate
     //     a generic control symbol element
     // keep in mind, class_exists() requires a fully-qualified namespace
     //
     if (array_key_exists($token->getSymbol(), self::$symbols)) {
         // get the symbol's name
         $name = self::$symbols[$token->getSymbol()];
         $name = ucfirst($name);
         $classname = "Jstewmc\\Rtf\\Element\\Control\\Symbol\\{$name}";
         if (class_exists($classname)) {
             $symbol = new $classname();
         } else {
             $symbol = new Element\Control\Symbol\Symbol();
             $symbol->setSymbol($token->getSymbol());
         }
     } else {
         $symbol = new Element\Control\Symbol\Symbol();
         $symbol->setSymbol($token->getSymbol());
     }
     // set the symbol's parameter
     $symbol->setParameter($token->getParameter());
     $symbol->setIsSpaceDelimited($token->getIsSpaceDelimited());
     // append the element
     $symbol->setParent($group);
     $group->appendChild($symbol);
     return;
 }
Beispiel #2
0
 /**
  * parse() should skip undefined control symbols
  */
 public function testParse_parsesControlSymbolsUndefined()
 {
     $tokens = [new Token\Group\Open(), new Token\Control\Symbol('#'), new Token\Group\Close()];
     // parse the tokens
     $parser = new Parser();
     $root = $parser->parse($tokens);
     $group = new Element\Group();
     $symbol = new Element\Control\Symbol\Symbol();
     $symbol->setSymbol('#');
     $symbol->setParent($group);
     $group->appendChild($symbol);
     $this->assertEquals($group, $root);
     return;
 }