[ Index ] |
PHP Cross Reference of phpBB-3.3.14-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 3 /* 4 * This file is part of the Symfony package. 5 * 6 * (c) Fabien Potencier <fabien@symfony.com> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12 namespace Symfony\Bridge\Twig\TokenParser; 13 14 use Symfony\Bridge\Twig\Node\TransNode; 15 use Twig\Error\SyntaxError; 16 use Twig\Node\Expression\AbstractExpression; 17 use Twig\Node\Expression\ArrayExpression; 18 use Twig\Node\TextNode; 19 use Twig\Token; 20 21 /** 22 * Token Parser for the 'transchoice' tag. 23 * 24 * @author Fabien Potencier <fabien@symfony.com> 25 */ 26 class TransChoiceTokenParser extends TransTokenParser 27 { 28 /** 29 * {@inheritdoc} 30 */ 31 public function parse(Token $token) 32 { 33 $lineno = $token->getLine(); 34 $stream = $this->parser->getStream(); 35 36 $vars = new ArrayExpression([], $lineno); 37 38 $count = $this->parser->getExpressionParser()->parseExpression(); 39 40 $domain = null; 41 $locale = null; 42 43 if ($stream->test('with')) { 44 // {% transchoice count with vars %} 45 $stream->next(); 46 $vars = $this->parser->getExpressionParser()->parseExpression(); 47 } 48 49 if ($stream->test('from')) { 50 // {% transchoice count from "messages" %} 51 $stream->next(); 52 $domain = $this->parser->getExpressionParser()->parseExpression(); 53 } 54 55 if ($stream->test('into')) { 56 // {% transchoice count into "fr" %} 57 $stream->next(); 58 $locale = $this->parser->getExpressionParser()->parseExpression(); 59 } 60 61 $stream->expect(Token::BLOCK_END_TYPE); 62 63 $body = $this->parser->subparse([$this, 'decideTransChoiceFork'], true); 64 65 if (!$body instanceof TextNode && !$body instanceof AbstractExpression) { 66 throw new SyntaxError('A message inside a transchoice tag must be a simple text.', $body->getTemplateLine(), $stream->getSourceContext()); 67 } 68 69 $stream->expect(Token::BLOCK_END_TYPE); 70 71 return new TransNode($body, $domain, $count, $vars, $locale, $lineno, $this->getTag()); 72 } 73 74 public function decideTransChoiceFork($token) 75 { 76 return $token->test(['endtranschoice']); 77 } 78 79 /** 80 * {@inheritdoc} 81 */ 82 public function getTag() 83 { 84 return 'transchoice'; 85 } 86 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Mon Nov 25 19:05:08 2024 | Cross-referenced by PHPXref 0.7.1 |