Skip to content

Commit e33cdc2

Browse files
committed
bug symfony#22994 Harden the debugging of Twig filters and functions (stof)
This PR was merged into the 2.7 branch. Discussion ---------- Harden the debugging of Twig filters and functions | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a Removing the environment and context arguments is now based on Twig metadata rather than on some wild guessing which might go wrong: - the environment argument may not be typehinted - the context argument may not be named `$context` - an argument may be named `$context` without being the special context argument Commits ------- 63a8aff Harden the debugging of Twig filters and functions
2 parents aa04f35 + 63a8aff commit e33cdc2

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/Symfony/Bridge/Twig/Command/DebugCommand.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,20 @@ private function getMetadata($type, $entity)
159159
throw new \UnexpectedValueException('Unsupported callback type');
160160
}
161161

162+
$args = $refl->getParameters();
163+
162164
// filter out context/environment args
163-
$args = array_filter($refl->getParameters(), function ($param) use ($entity) {
164-
if ($entity->needsContext() && $param->getName() === 'context') {
165-
return false;
166-
}
165+
if ($entity->needsEnvironment()) {
166+
array_shift($args);
167+
}
168+
if ($entity->needsContext()) {
169+
array_shift($args);
170+
}
167171

168-
return !$param->getClass() || $param->getClass()->getName() !== 'Twig_Environment';
169-
});
172+
if ($type === 'filters') {
173+
// remove the value the filter is applied on
174+
array_shift($args);
175+
}
170176

171177
// format args
172178
$args = array_map(function ($param) {
@@ -177,11 +183,6 @@ private function getMetadata($type, $entity)
177183
return $param->getName();
178184
}, $args);
179185

180-
if ($type === 'filters') {
181-
// remove the value the filter is applied on
182-
array_shift($args);
183-
}
184-
185186
return $args;
186187
}
187188
}

0 commit comments

Comments
 (0)