38 $nodes =
array(
'body' => $body);
40 $attributes = array_replace(
41 array(
'debug' => null,
'combine' => null,
'var_name' =>
'asset_url'),
43 array(
'asset' => $asset,
'inputs' => $inputs,
'filters' => $filters,
'name' => $name)
46 parent::__construct($nodes, $attributes, $lineno, $tag);
49 public function compile(\Twig_Compiler $compiler)
51 $compiler->addDebugInfo($this);
53 $combine = $this->getAttribute(
'combine');
54 $debug = $this->getAttribute(
'debug');
56 if (null === $combine && null !== $debug) {
60 if (null === $combine) {
62 ->write(
"if (isset(\$context['assetic']['debug']) && \$context['assetic']['debug']) {\n")
74 $this->
compileAsset($compiler, $this->getAttribute(
'asset'), $this->getAttribute(
'name'));
81 $this->
compileAsset($compiler, $this->getAttribute(
'asset'), $this->getAttribute(
'name'));
87 ->write(
'unset($context[')
88 ->repr($this->getAttribute(
'var_name'))
96 foreach ($this->getAttribute(
'asset') as $leaf) {
97 $leafName = $this->getAttribute(
'name').
'_'.$i++;
104 if ($vars = $asset->
getVars()) {
105 $compiler->write(
"// check variable conditions\n");
107 foreach ($vars as $var) {
109 ->write(
"if (!isset(\$context['assetic']['vars']['$var'])) {\n")
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")
117 $compiler->raw(
"\n");
121 ->write(
"// asset \"$name\"\n")
123 ->repr($this->getAttribute(
'var_name'))
131 ->subcompile($this->getNode(
'body'))
137 if (!$vars = $asset->
getVars()) {
149 foreach ($vars as $var) {
151 $compiler->raw(
", ");
156 ->string(
"{".$var.
"}")
157 ->raw(
" => \$context['assetic']['vars']['$var']")
compileAsset(\Twig_Compiler $compiler, AssetInterface $asset, $name)
compile(\Twig_Compiler $compiler)
compileAssetUrl(\Twig_Compiler $compiler, AssetInterface $asset, $name)
__construct(AssetInterface $asset, \Twig_Node $body, array $inputs, array $filters, $name, array $attributes=array(), $lineno=0, $tag=null)
Constructor.
getVars()
Returns an array of variable names for this asset.
An asset has a mutable URL and content and can be loaded and dumped.
Create styles array
The data for the language used.
compileDebug(\Twig_Compiler $compiler)
getTargetPath()
Returns the URL for the current asset.