ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Twig_Extensions_TokenParser_Trans Class Reference
+ Inheritance diagram for Twig_Extensions_TokenParser_Trans:
+ Collaboration diagram for Twig_Extensions_TokenParser_Trans:

Public Member Functions

 parse (Twig_Token $token)
 {Parses a token and returns a node.
Returns
Twig_NodeInterface
Exceptions
Twig_Error_Syntax
} More...
 
 decideForFork (Twig_Token $token)
 
 decideForEnd (Twig_Token $token)
 
 getTag ()
 {Gets the tag name associated with this token parser.
Returns
string The tag name
} More...
 
- Public Member Functions inherited from Twig_TokenParser
 setParser (Twig_Parser $parser)
 Sets the parser associated with this token parser. More...
 

Protected Member Functions

 checkTransString (Twig_Node $body, $lineno)
 

Additional Inherited Members

- Protected Attributes inherited from Twig_TokenParser
 $parser
 

Detailed Description

Definition at line 12 of file Trans.php.

Member Function Documentation

◆ checkTransString()

Twig_Extensions_TokenParser_Trans::checkTransString ( Twig_Node  $body,
  $lineno 
)
protected

Definition at line 72 of file Trans.php.

References $i, and Twig_Node\getNode().

Referenced by parse().

73  {
74  foreach ($body as $i => $node) {
75  if (
76  $node instanceof Twig_Node_Text
77  ||
78  ($node instanceof Twig_Node_Print && $node->getNode('expr') instanceof Twig_Node_Expression_Name)
79  ) {
80  continue;
81  }
82 
83  throw new Twig_Error_Syntax(sprintf('The text to be translated with "trans" can only contain references to simple variables'), $lineno);
84  }
85  }
Exception thrown when a syntax error occurs during lexing or parsing of a template.
Definition: Syntax.php:18
Represents a node that outputs an expression.
Definition: Print.php:18
getNode($name)
Definition: Node.php:186
Represents a text node.
Definition: Text.php:18
$i
Definition: disco.tpl.php:19
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ decideForEnd()

Twig_Extensions_TokenParser_Trans::decideForEnd ( Twig_Token  $token)

Definition at line 59 of file Trans.php.

References Twig_Token\test().

60  {
61  return $token->test('endtrans');
62  }
test($type, $values=null)
Tests the current token for a type and/or a value.
Definition: Token.php:70
+ Here is the call graph for this function:

◆ decideForFork()

Twig_Extensions_TokenParser_Trans::decideForFork ( Twig_Token  $token)

Definition at line 54 of file Trans.php.

References array, and Twig_Token\test().

55  {
56  return $token->test(array('plural', 'notes', 'endtrans'));
57  }
test($type, $values=null)
Tests the current token for a type and/or a value.
Definition: Token.php:70
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ getTag()

Twig_Extensions_TokenParser_Trans::getTag ( )

{Gets the tag name associated with this token parser.

Returns
string The tag name
}

Implements Twig_TokenParserInterface.

Definition at line 67 of file Trans.php.

Referenced by parse().

68  {
69  return 'trans';
70  }
+ Here is the caller graph for this function:

◆ parse()

Twig_Extensions_TokenParser_Trans::parse ( Twig_Token  $token)

{Parses a token and returns a node.

Returns
Twig_NodeInterface
Exceptions
Twig_Error_Syntax
}

Implements Twig_TokenParserInterface.

Definition at line 17 of file Trans.php.

References GuzzleHttp\Psr7\$stream, array, Twig_Token\BLOCK_END_TYPE, checkTransString(), Twig_Token\getLine(), and getTag().

18  {
19  $lineno = $token->getLine();
20  $stream = $this->parser->getStream();
21  $count = null;
22  $plural = null;
23  $notes = null;
24 
25  if (!$stream->test(Twig_Token::BLOCK_END_TYPE)) {
26  $body = $this->parser->getExpressionParser()->parseExpression();
27  } else {
29  $body = $this->parser->subparse(array($this, 'decideForFork'));
30  $next = $stream->next()->getValue();
31 
32  if ('plural' === $next) {
33  $count = $this->parser->getExpressionParser()->parseExpression();
35  $plural = $this->parser->subparse(array($this, 'decideForFork'));
36 
37  if ('notes' === $stream->next()->getValue()) {
39  $notes = $this->parser->subparse(array($this, 'decideForEnd'), true);
40  }
41  } elseif ('notes' === $next) {
43  $notes = $this->parser->subparse(array($this, 'decideForEnd'), true);
44  }
45  }
46 
48 
49  $this->checkTransString($body, $lineno);
50 
51  return new Twig_Extensions_Node_Trans($body, $plural, $count, $notes, $lineno, $this->getTag());
52  }
checkTransString(Twig_Node $body, $lineno)
Definition: Trans.php:72
getTag()
{Gets the tag name associated with this token parser.string The tag name}
Definition: Trans.php:67
$stream
PHP stream implementation.
Create styles array
The data for the language used.
getLine()
Definition: Token.php:87
const BLOCK_END_TYPE
Definition: Token.php:30
+ Here is the call graph for this function:

The documentation for this class was generated from the following file: