ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
55class_alias('Twig_Error_Syntax', 'Twig\Error\SyntaxError', false);
sprintf('%.4f', $callTime)
An exception for terminatinating execution or to throw for unit testing.
Exception thrown when a syntax error occurs during lexing or parsing of a template.
Definition: Syntax.php:19
addSuggestions($name, array $items)
Tweaks the error message to include suggestions.
Definition: Syntax.php:26
static computeAlternatives($name, $items)
Definition: Syntax.php:40
Twig base exception.
Definition: Error.php:35
appendMessage($rawMessage)
Definition: Error.php:237
if($format !==null) $name
Definition: metadata.php:146