bug #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
-------
63a8aff2c8
Harden the debugging of Twig filters and functions
This commit is contained in:
commit
e33cdc2336
@ -159,14 +159,20 @@ EOF
|
||||
throw new \UnexpectedValueException('Unsupported callback type');
|
||||
}
|
||||
|
||||
$args = $refl->getParameters();
|
||||
|
||||
// filter out context/environment args
|
||||
$args = array_filter($refl->getParameters(), function ($param) use ($entity) {
|
||||
if ($entity->needsContext() && $param->getName() === 'context') {
|
||||
return false;
|
||||
if ($entity->needsEnvironment()) {
|
||||
array_shift($args);
|
||||
}
|
||||
if ($entity->needsContext()) {
|
||||
array_shift($args);
|
||||
}
|
||||
|
||||
return !$param->getClass() || $param->getClass()->getName() !== 'Twig_Environment';
|
||||
});
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user