ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Twig_Error_Syntax Class Reference

Exception thrown when a syntax error occurs during lexing or parsing of a template. More...

+ Inheritance diagram for Twig_Error_Syntax:
+ Collaboration diagram for Twig_Error_Syntax:

Public Member Functions

 addSuggestions ($name, array $items)
 Tweaks the error message to include suggestions. More...
 
- Public Member Functions inherited from Twig_Error
 __construct ($message, $lineno=-1, $source=null, Exception $previous=null)
 Constructor. More...
 
 getRawMessage ()
 Gets the raw message. More...
 
 getTemplateFile ()
 Gets the logical name where the error occurred. More...
 
 setTemplateFile ($name)
 Sets the logical name where the error occurred. More...
 
 getTemplateName ()
 Gets the logical name where the error occurred. More...
 
 setTemplateName ($name)
 Sets the logical name where the error occurred. More...
 
 getTemplateLine ()
 Gets the template line where the error occurred. More...
 
 setTemplateLine ($lineno)
 Sets the template line where the error occurred. More...
 
 getSourceContext ()
 Gets the source context of the Twig template where the error occurred. More...
 
 setSourceContext (Twig_Source $source=null)
 Sets the source context of the Twig template where the error occurred. More...
 
 guess ()
 
 __call ($method, $arguments)
 For PHP < 5.3.0, provides access to the getPrevious() method. More...
 
 appendMessage ($rawMessage)
 

Static Public Member Functions

static computeAlternatives ($name, $items)
 

Additional Inherited Members

- Protected Member Functions inherited from Twig_Error
 updateRepr ()
 
 guessTemplateInfo ()
 
- Protected Attributes inherited from Twig_Error
 $lineno
 
 $filename
 
 $rawMessage
 
 $previous
 

Detailed Description

Exception thrown when a syntax error occurs during lexing or parsing of a template.

Author
Fabien Potencier fabie.nosp@m.n@sy.nosp@m.mfony.nosp@m..com

Definition at line 18 of file Syntax.php.

Member Function Documentation

◆ addSuggestions()

Twig_Error_Syntax::addSuggestions (   $name,
array  $items 
)

Tweaks the error message to include suggestions.

Parameters
string$nameThe original name of the item that does not exist
array$itemsAn array of possible items

Definition at line 26 of file Syntax.php.

27 {
28 if (!$alternatives = self::computeAlternatives($name, $items)) {
29 return;
30 }
31
32 $this->appendMessage(sprintf(' Did you mean "%s"?', implode('", "', $alternatives)));
33 }
appendMessage($rawMessage)
Definition: Error.php:237

References $name, and Twig_Error\appendMessage().

+ Here is the call graph for this function:

◆ computeAlternatives()

static Twig_Error_Syntax::computeAlternatives (   $name,
  $items 
)
static

Definition at line 40 of file Syntax.php.

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 }

References $name.

Referenced by Twig_Environment\computeAlternatives().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: