Example #1
0
 private function expect($filename, \Twig_Token $token, $type, $value = null)
 {
     if ($token->getType() !== $type) {
         throw new \RuntimeException(sprintf('Parse error in %s at line %d. Expected %s%s, got %s.', $filename, $token->getLine(), \Twig_Token::typeToEnglish($type), $value !== null ? ' "' . $value . '"' : '', \Twig_Token::typeToEnglish($token->getType())));
     }
 }
 /**
  * Parses a string attribute token, saving it as either the title, link URL, or link text
  *
  * @param \Twig_Token $token The token to parse
  * @param \Twig_TokenStream $stream The token stream being traversed
  * @return void
  */
 protected function parseStringAttribute(\Twig_Token $token, \Twig_TokenStream $stream)
 {
     if (!$token->test(\Twig_Token::STRING_TYPE)) {
         throw new RuntimeException(sprintf("Expected string token but received '%s' instead", \Twig_Token::typeToEnglish($token->getType())), $stream->getCurrent()->getLine(), $stream->getFilename());
     }
     // If any of these values has already been set, then set the next
     // property with this string. The string order that must be followed
     // in the codeblock tag is: title, url, link text
     if (empty($this->attributes['title'])) {
         $this->attributes['title'] = $token->getValue();
     } elseif (empty($this->attributes['linkUrl'])) {
         $this->attributes['linkUrl'] = $token->getValue();
     } elseif (empty($this->attributes['linkText'])) {
         $this->attributes['linkText'] = $token->getValue();
     }
 }