*/ class TwigFormulaLoader implements FormulaLoaderInterface { private $twig; public function __construct(\Twig_Environment $twig) { $this->twig = $twig; } public function load(ResourceInterface $resource) { try { $tokens = $this->twig->tokenize($resource->getContent()); $nodes = $this->twig->parse($tokens); } catch (\Exception $e) { return array(); } return $this->loadNode($nodes); } /** * Loads assets from the supplied node. * * @return array An array of asset formulae indexed by name */ private function loadNode(\Twig_Node $node) { $assets = array(); if ($node instanceof AsseticNode) { $assets[$node->getAttribute('asset_name')] = array( $node->getAttribute('source_urls'), $node->getAttribute('filter_names'), array( 'output' => $node->getAttribute('target_url'), 'name' => $node->getAttribute('asset_name'), 'debug' => $node->getAttribute('debug'), ), ); } foreach ($node as $child) { if ($child instanceof \Twig_Node) { $assets += $this->loadNode($child); } } return $assets; } }