Harden the debugging of Twig filters and functions

Removing the environment and context arguments is now based on Twig metadata
rather than on some wild guessing which might go wrong.
This commit is contained in:
Christophe Coevoet 2017-05-31 17:20:46 +02:00
parent aa04f35092
commit 63a8aff2c8

View File

@ -159,14 +159,20 @@ EOF
throw new \UnexpectedValueException('Unsupported callback type');
}
// filter out context/environment args
$args = array_filter($refl->getParameters(), function ($param) use ($entity) {
if ($entity->needsContext() && $param->getName() === 'context') {
return false;
}
$args = $refl->getParameters();
return !$param->getClass() || $param->getClass()->getName() !== 'Twig_Environment';
});
// filter out context/environment args
if ($entity->needsEnvironment()) {
array_shift($args);
}
if ($entity->needsContext()) {
array_shift($args);
}
if ($type === 'filters') {
// remove the value the filter is applied on
array_shift($args);
}
// format args
$args = array_map(function ($param) {
@ -177,11 +183,6 @@ EOF
return $param->getName();
}, $args);
if ($type === 'filters') {
// remove the value the filter is applied on
array_shift($args);
}
return $args;
}
}