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

Public Member Functions

 __construct (AssetInterface $asset, \Twig_Node $body, array $inputs, array $filters, $name, array $attributes=array(), $lineno=0, $tag=null)
 Constructor. More...
 
 compile (\Twig_Compiler $compiler)
 

Protected Member Functions

 compileDebug (\Twig_Compiler $compiler)
 
 compileAsset (\Twig_Compiler $compiler, AssetInterface $asset, $name)
 
 compileAssetUrl (\Twig_Compiler $compiler, AssetInterface $asset, $name)
 

Detailed Description

Definition at line 16 of file AsseticNode.php.

Constructor & Destructor Documentation

◆ __construct()

Assetic\Extension\Twig\AsseticNode::__construct ( AssetInterface  $asset,
\Twig_Node  $body,
array  $inputs,
array  $filters,
  $name,
array  $attributes = array(),
  $lineno = 0,
  $tag = null 
)

Constructor.

Available attributes:

  • debug: The debug mode
  • combine: Whether to combine assets
  • var_name: The name of the variable to expose to the body node
Parameters
AssetInterface$assetThe asset
\Twig_Node$bodyThe body node
array$inputsAn array of input strings
array$filtersAn array of filter strings
string$nameThe name of the asset
array$attributesAn array of attributes
integer$linenoThe line number
string$tagThe tag name

Definition at line 36 of file AsseticNode.php.

References array.

37  {
38  $nodes = array('body' => $body);
39 
40  $attributes = array_replace(
41  array('debug' => null, 'combine' => null, 'var_name' => 'asset_url'),
42  $attributes,
43  array('asset' => $asset, 'inputs' => $inputs, 'filters' => $filters, 'name' => $name)
44  );
45 
46  parent::__construct($nodes, $attributes, $lineno, $tag);
47  }
Create styles array
The data for the language used.

Member Function Documentation

◆ compile()

Assetic\Extension\Twig\AsseticNode::compile ( \Twig_Compiler  $compiler)

Definition at line 49 of file AsseticNode.php.

References Assetic\Extension\Twig\AsseticNode\compileAsset(), and Assetic\Extension\Twig\AsseticNode\compileDebug().

50  {
51  $compiler->addDebugInfo($this);
52 
53  $combine = $this->getAttribute('combine');
54  $debug = $this->getAttribute('debug');
55 
56  if (null === $combine && null !== $debug) {
57  $combine = !$debug;
58  }
59 
60  if (null === $combine) {
61  $compiler
62  ->write("if (isset(\$context['assetic']['debug']) && \$context['assetic']['debug']) {\n")
63  ->indent()
64  ;
65 
66  $this->compileDebug($compiler);
67 
68  $compiler
69  ->outdent()
70  ->write("} else {\n")
71  ->indent()
72  ;
73 
74  $this->compileAsset($compiler, $this->getAttribute('asset'), $this->getAttribute('name'));
75 
76  $compiler
77  ->outdent()
78  ->write("}\n")
79  ;
80  } elseif ($combine) {
81  $this->compileAsset($compiler, $this->getAttribute('asset'), $this->getAttribute('name'));
82  } else {
83  $this->compileDebug($compiler);
84  }
85 
86  $compiler
87  ->write('unset($context[')
88  ->repr($this->getAttribute('var_name'))
89  ->raw("]);\n")
90  ;
91  }
compileAsset(\Twig_Compiler $compiler, AssetInterface $asset, $name)
compileDebug(\Twig_Compiler $compiler)
Definition: AsseticNode.php:93
+ Here is the call graph for this function:

◆ compileAsset()

Assetic\Extension\Twig\AsseticNode::compileAsset ( \Twig_Compiler  $compiler,
AssetInterface  $asset,
  $name 
)
protected

Definition at line 102 of file AsseticNode.php.

References Assetic\Extension\Twig\AsseticNode\compileAssetUrl(), and Assetic\Asset\AssetInterface\getVars().

Referenced by Assetic\Extension\Twig\AsseticNode\compile(), and Assetic\Extension\Twig\AsseticNode\compileDebug().

103  {
104  if ($vars = $asset->getVars()) {
105  $compiler->write("// check variable conditions\n");
106 
107  foreach ($vars as $var) {
108  $compiler
109  ->write("if (!isset(\$context['assetic']['vars']['$var'])) {\n")
110  ->indent()
111  ->write("throw new \RuntimeException(sprintf('The asset \"".$name."\" expected variable \"".$var."\" to be set, but got only these vars: %s. Did you set-up a value supplier?', isset(\$context['assetic']['vars']) && \$context['assetic']['vars'] ? implode(', ', \$context['assetic']['vars']) : '# none #'));\n")
112  ->outdent()
113  ->write("}\n")
114  ;
115  }
116 
117  $compiler->raw("\n");
118  }
119 
120  $compiler
121  ->write("// asset \"$name\"\n")
122  ->write('$context[')
123  ->repr($this->getAttribute('var_name'))
124  ->raw('] = ')
125  ;
126 
127  $this->compileAssetUrl($compiler, $asset, $name);
128 
129  $compiler
130  ->raw(";\n")
131  ->subcompile($this->getNode('body'))
132  ;
133  }
compileAssetUrl(\Twig_Compiler $compiler, AssetInterface $asset, $name)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ compileAssetUrl()

Assetic\Extension\Twig\AsseticNode::compileAssetUrl ( \Twig_Compiler  $compiler,
AssetInterface  $asset,
  $name 
)
protected

Definition at line 135 of file AsseticNode.php.

References Assetic\Asset\AssetInterface\getTargetPath(), and Assetic\Asset\AssetInterface\getVars().

Referenced by Assetic\Extension\Twig\AsseticNode\compileAsset().

136  {
137  if (!$vars = $asset->getVars()) {
138  $compiler->repr($asset->getTargetPath());
139 
140  return;
141  }
142 
143  $compiler
144  ->raw("strtr(")
145  ->string($asset->getTargetPath())
146  ->raw(", array(");
147 
148  $first = true;
149  foreach ($vars as $var) {
150  if (!$first) {
151  $compiler->raw(", ");
152  }
153  $first = false;
154 
155  $compiler
156  ->string("{".$var."}")
157  ->raw(" => \$context['assetic']['vars']['$var']")
158  ;
159  }
160 
161  $compiler
162  ->raw("))")
163  ;
164  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ compileDebug()

Assetic\Extension\Twig\AsseticNode::compileDebug ( \Twig_Compiler  $compiler)
protected

Definition at line 93 of file AsseticNode.php.

References Assetic\Extension\Twig\AsseticNode\compileAsset().

Referenced by Assetic\Extension\Twig\AsseticNode\compile().

94  {
95  $i = 0;
96  foreach ($this->getAttribute('asset') as $leaf) {
97  $leafName = $this->getAttribute('name').'_'.$i++;
98  $this->compileAsset($compiler, $leaf, $leafName);
99  }
100  }
compileAsset(\Twig_Compiler $compiler, AssetInterface $asset, $name)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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