Skip to content

Commit 4323603

Browse files
committed
minor kriswallsmith#791 Avoid using Twig_Environment::getFunction to identify Assetic functions (stof)
This PR was merged into the 1.4-dev branch. Discussion ---------- Avoid using Twig_Environment::getFunction to identify Assetic functions As of Assetic 1.3.0, the Twig functions are using a special node class, which can be used to identify them instead. The `getFunction` method is intended to be marked as an internal one in twigphp/Twig#1889 Commits ------- 39b99e8 Avoid using Twig_Environment::getFunction to identify Assetic functions
2 parents a9410a7 + 39b99e8 commit 4323603

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

src/Assetic/Extension/Twig/TwigFormulaLoader.php

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,27 +70,25 @@ private function loadNode(\Twig_Node $node)
7070
'vars' => $node->getAttribute('vars'),
7171
),
7272
);
73-
} elseif ($node instanceof \Twig_Node_Expression_Function) {
73+
} elseif ($node instanceof AsseticFilterNode) {
7474
$name = $node->getAttribute('name');
7575

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\\Extension\\Twig\\AsseticExtension')->getFilterInvoker($name);
76+
$arguments = array();
77+
foreach ($node->getNode('arguments') as $argument) {
78+
$arguments[] = eval('return '.$this->twig->compile($argument).';');
79+
}
8380

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());
81+
$invoker = $this->twig->getExtension('Assetic\Extension\Twig\AsseticExtension')->getFilterInvoker($name);
8782

88-
if (!isset($options['name'])) {
89-
$options['name'] = $invoker->getFactory()->generateAssetName($inputs, $filters, $options);
90-
}
83+
$inputs = isset($arguments[0]) ? (array) $arguments[0] : array();
84+
$filters = $invoker->getFilters();
85+
$options = array_replace($invoker->getOptions(), isset($arguments[1]) ? $arguments[1] : array());
9186

92-
$formulae[$options['name']] = array($inputs, $filters, $options);
87+
if (!isset($options['name'])) {
88+
$options['name'] = $invoker->getFactory()->generateAssetName($inputs, $filters, $options);
9389
}
90+
91+
$formulae[$options['name']] = array($inputs, $filters, $options);
9492
}
9593

9694
foreach ($node as $child) {

0 commit comments

Comments
 (0)