ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
Assetic\Extension\Twig\AsseticTokenParser Class Reference
+ Inheritance diagram for Assetic\Extension\Twig\AsseticTokenParser:
+ Collaboration diagram for Assetic\Extension\Twig\AsseticTokenParser:

Public Member Functions

 __construct (AssetFactory $factory, $tag, $output, $single=false, array $extensions=array())
 Constructor. More...
 
 parse (\Twig_Token $token)
 
 getTag ()
 
 testEndTag (\Twig_Token $token)
 

Protected Member Functions

 createBodyNode (AssetInterface $asset, \Twig_Node $body, array $inputs, array $filters, $name, array $attributes=array(), $lineno=0, $tag=null)
 
 createNode (AssetInterface $asset, \Twig_NodeInterface $body, array $inputs, array $filters, $name, array $attributes=array(), $lineno=0, $tag=null)
 

Private Attributes

 $factory
 
 $tag
 
 $output
 
 $single
 
 $extensions
 

Detailed Description

Definition at line 17 of file AsseticTokenParser.php.

Constructor & Destructor Documentation

◆ __construct()

Assetic\Extension\Twig\AsseticTokenParser::__construct ( AssetFactory  $factory,
  $tag,
  $output,
  $single = false,
array  $extensions = array() 
)

Constructor.

Attributes can be added to the tag by passing names as the options array. These values, if found, will be passed to the factory and node.

Parameters
AssetFactory$factoryThe asset factory
string$tagThe tag name
string$outputThe default output string
Boolean$singleWhether to force a single asset
array$extensionsAdditional attribute names to look for

Definition at line 37 of file AsseticTokenParser.php.

References Assetic\Extension\Twig\AsseticTokenParser\$extensions, Assetic\Extension\Twig\AsseticTokenParser\$factory, Assetic\Extension\Twig\AsseticTokenParser\$output, Assetic\Extension\Twig\AsseticTokenParser\$single, and Assetic\Extension\Twig\AsseticTokenParser\$tag.

Member Function Documentation

◆ createBodyNode()

Assetic\Extension\Twig\AsseticTokenParser::createBodyNode ( AssetInterface  $asset,
\Twig_Node  $body,
array  $inputs,
array  $filters,
  $name,
array  $attributes = array(),
  $lineno = 0,
  $tag = null 
)
protected
Parameters
AssetInterface$asset
\Twig_Node$body
array$inputs
array$filters
string$name
array$attributes
int$lineno
string$tag
Returns

Definition at line 161 of file AsseticTokenParser.php.

References Assetic\Extension\Twig\AsseticTokenParser\$tag, and Assetic\Extension\Twig\AsseticTokenParser\createNode().

Referenced by Assetic\Extension\Twig\AsseticTokenParser\parse().

162  {
163  $reflector = new \ReflectionMethod($this, 'createNode');
164 
165  if (__CLASS__ !== $reflector->getDeclaringClass()->name) {
166  @trigger_error(sprintf('Overwriting %s::createNode is deprecated since 1.3. Overwrite %s instead.', __CLASS__, __METHOD__), E_USER_DEPRECATED);
167 
168  return $this->createNode($asset, $body, $inputs, $filters, $name, $attributes, $lineno, $tag);
169  }
170 
171  return new AsseticNode($asset, $body, $inputs, $filters, $name, $attributes, $lineno, $tag);
172  }
createNode(AssetInterface $asset, \Twig_NodeInterface $body, array $inputs, array $filters, $name, array $attributes=array(), $lineno=0, $tag=null)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createNode()

Assetic\Extension\Twig\AsseticTokenParser::createNode ( AssetInterface  $asset,
\Twig_NodeInterface  $body,
array  $inputs,
array  $filters,
  $name,
array  $attributes = array(),
  $lineno = 0,
  $tag = null 
)
protected
Parameters
AssetInterface$asset
\Twig_NodeInterface$body
array$inputs
array$filters
string$name
array$attributes
int$lineno
string$tag
Returns
Deprecated:
since 1.3.0, to be removed in 2.0. Use createBodyNode instead.

Definition at line 188 of file AsseticTokenParser.php.

References Assetic\Extension\Twig\AsseticTokenParser\$tag.

Referenced by Assetic\Extension\Twig\AsseticTokenParser\createBodyNode().

189  {
190  @trigger_error(sprintf('The %s method is deprecated since 1.3 and will be removed in 2.0. Use createBodyNode instead.', __METHOD__), E_USER_DEPRECATED);
191 
192  if (!$body instanceof \Twig_Node) {
193  throw new \InvalidArgumentException('The body must be a Twig_Node. Custom implementations of Twig_NodeInterface are not supported.');
194  }
195 
196  return new AsseticNode($asset, $body, $inputs, $filters, $name, $attributes, $lineno, $tag);
197  }
+ Here is the caller graph for this function:

◆ getTag()

Assetic\Extension\Twig\AsseticTokenParser::getTag ( )

◆ parse()

Assetic\Extension\Twig\AsseticTokenParser::parse ( \Twig_Token  $token)

Definition at line 46 of file AsseticTokenParser.php.

References array, Assetic\Extension\Twig\AsseticTokenParser\createBodyNode(), and Assetic\Extension\Twig\AsseticTokenParser\getTag().

47  {
48  $inputs = array();
49  $filters = array();
50  $name = null;
51  $attributes = array(
52  'output' => $this->output,
53  'var_name' => 'asset_url',
54  'vars' => array(),
55  );
56 
57  $stream = $this->parser->getStream();
58  while (!$stream->test(\Twig_Token::BLOCK_END_TYPE)) {
59  if ($stream->test(\Twig_Token::STRING_TYPE)) {
60  // '@jquery', 'js/src/core/*', 'js/src/extra.js'
61  $inputs[] = $stream->next()->getValue();
62  } elseif ($stream->test(\Twig_Token::NAME_TYPE, 'filter')) {
63  // filter='yui_js'
64  $stream->next();
65  $stream->expect(\Twig_Token::OPERATOR_TYPE, '=');
66  $filters = array_merge($filters, array_filter(array_map('trim', explode(',', $stream->expect(\Twig_Token::STRING_TYPE)->getValue()))));
67  } elseif ($stream->test(\Twig_Token::NAME_TYPE, 'output')) {
68  // output='js/packed/*.js' OR output='js/core.js'
69  $stream->next();
70  $stream->expect(\Twig_Token::OPERATOR_TYPE, '=');
71  $attributes['output'] = $stream->expect(\Twig_Token::STRING_TYPE)->getValue();
72  } elseif ($stream->test(\Twig_Token::NAME_TYPE, 'name')) {
73  // name='core_js'
74  $stream->next();
75  $stream->expect(\Twig_Token::OPERATOR_TYPE, '=');
76  $name = $stream->expect(\Twig_Token::STRING_TYPE)->getValue();
77  } elseif ($stream->test(\Twig_Token::NAME_TYPE, 'as')) {
78  // as='the_url'
79  $stream->next();
80  $stream->expect(\Twig_Token::OPERATOR_TYPE, '=');
81  $attributes['var_name'] = $stream->expect(\Twig_Token::STRING_TYPE)->getValue();
82  } elseif ($stream->test(\Twig_Token::NAME_TYPE, 'debug')) {
83  // debug=true
84  $stream->next();
85  $stream->expect(\Twig_Token::OPERATOR_TYPE, '=');
86  $attributes['debug'] = 'true' == $stream->expect(\Twig_Token::NAME_TYPE, array('true', 'false'))->getValue();
87  } elseif ($stream->test(\Twig_Token::NAME_TYPE, 'combine')) {
88  // combine=true
89  $stream->next();
90  $stream->expect(\Twig_Token::OPERATOR_TYPE, '=');
91  $attributes['combine'] = 'true' == $stream->expect(\Twig_Token::NAME_TYPE, array('true', 'false'))->getValue();
92  } elseif ($stream->test(\Twig_Token::NAME_TYPE, 'vars')) {
93  // vars=['locale','browser']
94  $stream->next();
95  $stream->expect(\Twig_Token::OPERATOR_TYPE, '=');
96  $stream->expect(\Twig_Token::PUNCTUATION_TYPE, '[');
97 
98  while ($stream->test(\Twig_Token::STRING_TYPE)) {
99  $attributes['vars'][] = $stream->expect(\Twig_Token::STRING_TYPE)->getValue();
100 
101  if (!$stream->test(\Twig_Token::PUNCTUATION_TYPE, ',')) {
102  break;
103  }
104 
105  $stream->next();
106  }
107 
108  $stream->expect(\Twig_Token::PUNCTUATION_TYPE, ']');
109  } elseif ($stream->test(\Twig_Token::NAME_TYPE, $this->extensions)) {
110  // an arbitrary configured attribute
111  $key = $stream->next()->getValue();
112  $stream->expect(\Twig_Token::OPERATOR_TYPE, '=');
113  $attributes[$key] = $stream->expect(\Twig_Token::STRING_TYPE)->getValue();
114  } else {
115  $token = $stream->getCurrent();
116  throw new \Twig_Error_Syntax(sprintf('Unexpected token "%s" of value "%s"', \Twig_Token::typeToEnglish($token->getType()), $token->getValue()), $token->getLine(), $stream->getFilename());
117  }
118  }
119 
120  $stream->expect(\Twig_Token::BLOCK_END_TYPE);
121 
122  $body = $this->parser->subparse(array($this, 'testEndTag'), true);
123 
124  $stream->expect(\Twig_Token::BLOCK_END_TYPE);
125 
126  if ($this->single && 1 < count($inputs)) {
127  $inputs = array_slice($inputs, -1);
128  }
129 
130  if (!$name) {
131  $name = $this->factory->generateAssetName($inputs, $filters, $attributes);
132  }
133 
134  $asset = $this->factory->createAsset($inputs, $filters, $attributes + array('name' => $name));
135 
136  return $this->createBodyNode($asset, $body, $inputs, $filters, $name, $attributes, $token->getLine(), $this->getTag());
137  }
createBodyNode(AssetInterface $asset, \Twig_Node $body, array $inputs, array $filters, $name, array $attributes=array(), $lineno=0, $tag=null)
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ testEndTag()

Assetic\Extension\Twig\AsseticTokenParser::testEndTag ( \Twig_Token  $token)

Definition at line 144 of file AsseticTokenParser.php.

References array, and Assetic\Extension\Twig\AsseticTokenParser\getTag().

145  {
146  return $token->test(array('end'.$this->getTag()));
147  }
Create styles array
The data for the language used.
+ Here is the call graph for this function:

Field Documentation

◆ $extensions

Assetic\Extension\Twig\AsseticTokenParser::$extensions
private

◆ $factory

Assetic\Extension\Twig\AsseticTokenParser::$factory
private

◆ $output

Assetic\Extension\Twig\AsseticTokenParser::$output
private

◆ $single

Assetic\Extension\Twig\AsseticTokenParser::$single
private

◆ $tag


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