Skip to content

Harden the debugging of Twig filters and functions #22994

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 31, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions src/Symfony/Bridge/Twig/Command/DebugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,20 @@ private function getMetadata($type, $entity)
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') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's use yoda-style then :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

none of the conditions in this class are using yoda-style actually

// remove the value the filter is applied on
array_shift($args);
}

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

if ($type === 'filters') {
// remove the value the filter is applied on
array_shift($args);
}

return $args;
}
}
Expand Down