Permalink
Browse files

Help the developer when they specify an invalid filter by providing s…

…ome alternatives
  • Loading branch information...
1 parent 6e3a1c4 commit f880bab988129314378a32a3c5aaba1ae9c41ce4 @jonathaningram jonathaningram committed Dec 5, 2011
Showing with 16 additions and 1 deletion.
  1. +16 −1 lib/Twig/Node/Expression/Filter.php
@@ -19,8 +19,23 @@ public function __construct(Twig_NodeInterface $node, Twig_Node_Expression_Const
public function compile(Twig_Compiler $compiler)
{
$name = $this->getNode('filter')->getAttribute('value');
+
if (false === $filter = $compiler->getEnvironment()->getFilter($name)) {
- throw new Twig_Error_Syntax(sprintf('The filter "%s" does not exist', $name), $this->getLine());
+ $alternativeFilters = array();
+
+ foreach ($compiler->getEnvironment()->getFilters() as $filterName => $filter) {
+ if (false !== strpos($filterName, $name)) {
+ $alternativeFilters[] = $filterName;
+ }
+ }
+
+ $exceptionMessage = sprintf('The filter "%s" does not exist', $name);
+
+ if (count($alternativeFilters)) {
+ $exceptionMessage = sprintf('%s. Did you mean "%s"?', $exceptionMessage, implode('", "', $alternativeFilters));
+ }
+
+ throw new Twig_Error_Syntax($exceptionMessage, $this->getLine());
}
$this->compileFilter($compiler, $filter);

0 comments on commit f880bab

Please sign in to comment.