class SyntaxError
\Exception thrown when a syntax error occurs during lexing or parsing of a template.
@author Fabien Potencier <fabien@symfony.com>
Hierarchy
- class \Twig\Error\Error extends \Twig\Error\Exception
- class \Twig\Error\SyntaxError extends \Twig\Error\Error
Expanded class hierarchy of SyntaxError
31 files declare their use of SyntaxError
- AssignNameExpression.php in vendor/
twig/ twig/ src/ Node/ Expression/ AssignNameExpression.php - AutoEscapeTokenParser.php in vendor/
twig/ twig/ src/ TokenParser/ AutoEscapeTokenParser.php - BlockTokenParser.php in vendor/
twig/ twig/ src/ TokenParser/ BlockTokenParser.php - CallableArgumentsExtractor.php in vendor/
twig/ twig/ src/ Util/ CallableArgumentsExtractor.php - CallExpression.php in vendor/
twig/ twig/ src/ Node/ Expression/ CallExpression.php
File
-
vendor/
twig/ twig/ src/ Error/ SyntaxError.php, line 20
Namespace
Twig\ErrorView source
class SyntaxError extends Error {
/**
* Tweaks the error message to include suggestions.
*
* @param string $name The original name of the item that does not exist
* @param array $items An array of possible items
*/
public function addSuggestions(string $name, array $items) : void {
$alternatives = [];
foreach ($items as $item) {
$lev = levenshtein($name, $item);
if ($lev <= \strlen($name) / 3 || str_contains($item, $name)) {
$alternatives[$item] = $lev;
}
}
if (!$alternatives) {
return;
}
asort($alternatives);
$this->appendMessage(\sprintf(' Did you mean "%s"?', implode('", "', array_keys($alternatives))));
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
Error::$lineno | private | property | |
Error::$name | private | property | |
Error::$rawMessage | private | property | |
Error::$sourceCode | private | property | |
Error::$sourcePath | private | property | |
Error::appendMessage | public | function | |
Error::getRawMessage | public | function | |
Error::getSourceContext | public | function | |
Error::getTemplateLine | public | function | |
Error::guess | public | function | |
Error::guessTemplateInfo | private | function | |
Error::setSourceContext | public | function | |
Error::setTemplateLine | public | function | |
Error::updateRepr | private | function | |
Error::__construct | public | function | Constructor. |
SyntaxError::addSuggestions | public | function | Tweaks the error message to include suggestions. |