$lineno
$lineno :
Exception thrown when a syntax error occurs during lexing or parsing of a template.
This exception class and its children must only be used when an error occurs during the loading of a template, when a syntax error is detected in a template, or when rendering a template. Other errors must use regular PHP exception classes (like when the template cache directory is not writable for instance).
To help debugging template issues, this class tracks the original template name and line where the error occurred.
Whenever possible, you must set these information (original template name and line number) yourself by passing them to the constructor. If some or all these information are not available from where you throw the exception, then this class will guess them automatically (when the line number is set to -1 and/or the name is set to null). As this is a costly operation, this can be disabled by passing false for both the name and the line number when creating a new instance of this class.
__construct(string $message, integer $lineno = -1, \Twig_Source|string|null $source = null, \Exception $previous = null)
Constructor.
Set both the line number and the name to false to disable automatic guessing of the original template name and line number.
Set the line number to -1 to enable its automatic guessing. Set the name to null to enable its automatic guessing.
By default, automatic guessing is enabled.
string | $message | The error message |
integer | $lineno | The template line where the error occurred |
\Twig_Source|string|null | $source | The source context where the error occurred |
\Exception | $previous | The previous exception |
getSourceContext() : \Twig_Source|null
Gets the source context of the Twig template where the error occurred.
setSourceContext(\Twig_Source $source = null)
Sets the source context of the Twig template where the error occurred.
\Twig_Source | $source |
<?php
/*
* This file is part of Twig.
*
* (c) Fabien Potencier
* (c) Armin Ronacher
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Exception thrown when a syntax error occurs during lexing or parsing of a template.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class Twig_Error_Syntax extends Twig_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($name, array $items)
{
$alternatives = [];
foreach ($items as $item) {
$lev = levenshtein($name, $item);
if ($lev <= strlen($name) / 3 || false !== strpos($item, $name)) {
$alternatives[$item] = $lev;
}
}
if (!$alternatives) {
return;
}
asort($alternatives);
$this->appendMessage(sprintf(' Did you mean "%s"?', implode('", "', array_keys($alternatives))));
}
}
class_alias('Twig_Error_Syntax', 'Twig\Error\SyntaxError', false);