ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
Assetic\Extension\Twig\TwigFormulaLoader Class Reference

Loads asset formulae from Twig templates. More...

+ Inheritance diagram for Assetic\Extension\Twig\TwigFormulaLoader:
+ Collaboration diagram for Assetic\Extension\Twig\TwigFormulaLoader:

Public Member Functions

 __construct (\Twig_Environment $twig, LoggerInterface $logger=null)
 
 load (ResourceInterface $resource)
 Loads formulae from a resource. More...
 
 load (ResourceInterface $resource)
 Loads formulae from a resource. More...
 

Private Member Functions

 loadNode (\Twig_Node $node)
 Loads assets from the supplied node. More...
 

Private Attributes

 $twig
 
 $logger
 

Detailed Description

Loads asset formulae from Twig templates.

Author
Kris Wallsmith kris..nosp@m.wall.nosp@m.smith.nosp@m.@gma.nosp@m.il.co.nosp@m.m

Definition at line 23 of file TwigFormulaLoader.php.

Constructor & Destructor Documentation

◆ __construct()

Assetic\Extension\Twig\TwigFormulaLoader::__construct ( \Twig_Environment  $twig,
LoggerInterface  $logger = null 
)

Member Function Documentation

◆ load()

Assetic\Extension\Twig\TwigFormulaLoader::load ( ResourceInterface  $resource)

Loads formulae from a resource.

Formulae should be loaded the same regardless of the current debug mode. Debug considerations should happen downstream.

Parameters
ResourceInterface$resourceA resource
Returns
array An array of formulae

Implements Assetic\Factory\Loader\FormulaLoaderInterface.

Definition at line 34 of file TwigFormulaLoader.php.

35 {
36 try {
37 $tokens = $this->twig->tokenize($resource->getContent(), (string) $resource);
38 $nodes = $this->twig->parse($tokens);
39 } catch (\Exception $e) {
40 if ($this->logger) {
41 $this->logger->error(sprintf('The template "%s" contains an error: %s', $resource, $e->getMessage()));
42 }
43
44 return array();
45 }
46
47 return $this->loadNode($nodes);
48 }
sprintf('%.4f', $callTime)
loadNode(\Twig_Node $node)
Loads assets from the supplied node.

References Assetic\Factory\Resource\ResourceInterface\getContent(), Assetic\Extension\Twig\TwigFormulaLoader\loadNode(), and sprintf.

+ Here is the call graph for this function:

◆ loadNode()

Assetic\Extension\Twig\TwigFormulaLoader::loadNode ( \Twig_Node  $node)
private

Loads assets from the supplied node.

Parameters
\Twig_Node$node
Returns
array An array of asset formulae indexed by name

Definition at line 57 of file TwigFormulaLoader.php.

58 {
59 $formulae = array();
60
61 if ($node instanceof AsseticNode) {
62 $formulae[$node->getAttribute('name')] = array(
63 $node->getAttribute('inputs'),
64 $node->getAttribute('filters'),
65 array(
66 'output' => $node->getAttribute('asset')->getTargetPath(),
67 'name' => $node->getAttribute('name'),
68 'debug' => $node->getAttribute('debug'),
69 'combine' => $node->getAttribute('combine'),
70 'vars' => $node->getAttribute('vars'),
71 ),
72 );
73 } elseif ($node instanceof \Twig_Node_Expression_Function) {
74 $name = $node->getAttribute('name');
75
76 if ($this->twig->getFunction($name) instanceof AsseticFilterFunction) {
77 $arguments = array();
78 foreach ($node->getNode('arguments') as $argument) {
79 $arguments[] = eval('return '.$this->twig->compile($argument).';');
80 }
81
82 $invoker = $this->twig->getExtension('assetic')->getFilterInvoker($name);
83
84 $inputs = isset($arguments[0]) ? (array) $arguments[0] : array();
85 $filters = $invoker->getFilters();
86 $options = array_replace($invoker->getOptions(), isset($arguments[1]) ? $arguments[1] : array());
87
88 if (!isset($options['name'])) {
89 $options['name'] = $invoker->getFactory()->generateAssetName($inputs, $filters, $options);
90 }
91
92 $formulae[$options['name']] = array($inputs, $filters, $options);
93 }
94 }
95
96 foreach ($node as $child) {
97 if ($child instanceof \Twig_Node) {
98 $formulae += $this->loadNode($child);
99 }
100 }
101
102 if ($node->hasAttribute('embedded_templates')) {
103 foreach ($node->getAttribute('embedded_templates') as $child) {
104 $formulae += $this->loadNode($child);
105 }
106 }
107
108 return $formulae;
109 }
if(!is_array($argv)) $options

References $options, and Assetic\Extension\Twig\TwigFormulaLoader\loadNode().

Referenced by Assetic\Extension\Twig\TwigFormulaLoader\load(), and Assetic\Extension\Twig\TwigFormulaLoader\loadNode().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $logger

Assetic\Extension\Twig\TwigFormulaLoader::$logger
private

◆ $twig

Assetic\Extension\Twig\TwigFormulaLoader::$twig
private

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