From 63a8aff2c887a4358529ebe7adb851725515e4eb Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Wed, 31 May 2017 17:20:46 +0200 Subject: [PATCH] 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. --- .../Bridge/Twig/Command/DebugCommand.php | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/Symfony/Bridge/Twig/Command/DebugCommand.php b/src/Symfony/Bridge/Twig/Command/DebugCommand.php index 349a8b81b8..7473221277 100644 --- a/src/Symfony/Bridge/Twig/Command/DebugCommand.php +++ b/src/Symfony/Bridge/Twig/Command/DebugCommand.php @@ -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; } }