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

Default autoescaping strategy based on file names. More...

+ Collaboration diagram for Twig_FileExtensionEscapingStrategy:

Static Public Member Functions

static guess ($name)
 Guesses the best autoescaping strategy based on the file name. More...
 

Detailed Description

Default autoescaping strategy based on file names.

This strategy sets the HTML as the default autoescaping strategy, but changes it based on the template name.

Note that there is no runtime performance impact as the default autoescaping strategy is set at compilation time.

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

Definition at line 23 of file FileExtensionEscapingStrategy.php.

Member Function Documentation

◆ guess()

static Twig_FileExtensionEscapingStrategy::guess (   $name)
static

Guesses the best autoescaping strategy based on the file name.

Parameters
string$nameThe template name
Returns
string|false The escaping strategy name to use or false to disable

Definition at line 32 of file FileExtensionEscapingStrategy.php.

References $name.

Referenced by Twig_Tests_FileExtensionEscapingStrategyTest\testGuess().

33  {
34  if (in_array(substr($name, -1), array('/', '\\'))) {
35  return 'html'; // return html for directories
36  }
37 
38  if ('.twig' === substr($name, -5)) {
39  $name = substr($name, 0, -5);
40  }
41 
42  $extension = pathinfo($name, PATHINFO_EXTENSION);
43 
44  switch ($extension) {
45  case 'js':
46  return 'js';
47 
48  case 'css':
49  return 'css';
50 
51  case 'txt':
52  return false;
53 
54  default:
55  return 'html';
56  }
57  }
+ Here is the caller graph for this function:

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