ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Twig_Extensions_Grammar_Optional Class Reference
+ Inheritance diagram for Twig_Extensions_Grammar_Optional:
+ Collaboration diagram for Twig_Extensions_Grammar_Optional:

Public Member Functions

 __construct ()
 
 __toString ()
 
 addGrammar (Twig_Extensions_GrammarInterface $grammar)
 
 parse (Twig_Token $token)
 
- Public Member Functions inherited from Twig_Extensions_Grammar
 __construct ($name)
 
 setParser (Twig_Parser $parser)
 
 getName ()
 

Protected Attributes

 $grammar
 
- Protected Attributes inherited from Twig_Extensions_Grammar
 $name
 
 $parser
 

Detailed Description

Deprecated:
since version 1.5

Definition at line 15 of file Optional.php.

Constructor & Destructor Documentation

◆ __construct()

Twig_Extensions_Grammar_Optional::__construct ( )

Definition at line 19 of file Optional.php.

References $grammar, and addGrammar().

20  {
21  $this->grammar = array();
22  foreach (func_get_args() as $grammar) {
23  $this->addGrammar($grammar);
24  }
25  }
addGrammar(Twig_Extensions_GrammarInterface $grammar)
Definition: Optional.php:37
+ Here is the call graph for this function:

Member Function Documentation

◆ __toString()

Twig_Extensions_Grammar_Optional::__toString ( )

Definition at line 27 of file Optional.php.

References $grammar.

28  {
29  $repr = array();
30  foreach ($this->grammar as $grammar) {
31  $repr[] = (string) $grammar;
32  }
33 
34  return sprintf('[%s]', implode(' ', $repr));
35  }

◆ addGrammar()

Twig_Extensions_Grammar_Optional::addGrammar ( Twig_Extensions_GrammarInterface  $grammar)

Definition at line 37 of file Optional.php.

References $grammar.

Referenced by __construct().

38  {
39  $this->grammar[] = $grammar;
40  }
+ Here is the caller graph for this function:

◆ parse()

Twig_Extensions_Grammar_Optional::parse ( Twig_Token  $token)

Implements Twig_Extensions_GrammarInterface.

Definition at line 42 of file Optional.php.

References $grammar, Twig_Token\BLOCK_END_TYPE, Twig_Extensions_Grammar\getName(), and Twig_Token\NAME_TYPE.

43  {
44  // test if we have the optional element before consuming it
45  if ($this->grammar[0] instanceof Twig_Extensions_Grammar_Constant) {
46  if (!$this->parser->getStream()->test($this->grammar[0]->getType(), $this->grammar[0]->getName())) {
47  return array();
48  }
49  } elseif ($this->grammar[0] instanceof Twig_Extensions_Grammar_Name) {
50  if (!$this->parser->getStream()->test(Twig_Token::NAME_TYPE)) {
51  return array();
52  }
53  } elseif ($this->parser->getStream()->test(Twig_Token::BLOCK_END_TYPE)) {
54  // if this is not a Constant or a Name, it must be the last element of the tag
55 
56  return array();
57  }
58 
59  $elements = array();
60  foreach ($this->grammar as $grammar) {
61  $grammar->setParser($this->parser);
62 
63  $element = $grammar->parse($token);
64  if (is_array($element)) {
65  $elements = array_merge($elements, $element);
66  } else {
67  $elements[$grammar->getName()] = $element;
68  }
69  }
70 
71  return $elements;
72  }
const NAME_TYPE
Definition: Token.php:32
const BLOCK_END_TYPE
Definition: Token.php:30
+ Here is the call graph for this function:

Field Documentation

◆ $grammar

Twig_Extensions_Grammar_Optional::$grammar
protected

Definition at line 17 of file Optional.php.

Referenced by __construct(), __toString(), addGrammar(), and parse().


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