ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Syntax.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of Twig.
5  *
6  * (c) Fabien Potencier
7  * (c) Armin Ronacher
8  *
9  * For the full copyright and license information, please view the LICENSE
10  * file that was distributed with this source code.
11  */
12 
19 {
26  public function addSuggestions($name, array $items)
27  {
28  if (!$alternatives = self::computeAlternatives($name, $items)) {
29  return;
30  }
31 
32  $this->appendMessage(sprintf(' Did you mean "%s"?', implode('", "', $alternatives)));
33  }
34 
40  public static function computeAlternatives($name, $items)
41  {
42  $alternatives = array();
43  foreach ($items as $item) {
44  $lev = levenshtein($name, $item);
45  if ($lev <= strlen($name) / 3 || false !== strpos($item, $name)) {
46  $alternatives[$item] = $lev;
47  }
48  }
49  asort($alternatives);
50 
51  return array_keys($alternatives);
52  }
53 }
54 
55 class_alias('Twig_Error_Syntax', 'Twig\Error\SyntaxError', false);
static computeAlternatives($name, $items)
Definition: Syntax.php:40
Twig base exception.
Definition: Error.php:34
addSuggestions($name, array $items)
Tweaks the error message to include suggestions.
Definition: Syntax.php:26
Exception thrown when a syntax error occurs during lexing or parsing of a template.
Definition: Syntax.php:18
appendMessage($rawMessage)
Definition: Error.php:237