Twig_FileExtensionEscapingStrategy

Default autoescaping strategy based on file names.

Defined (1)

The class is defined in the following location(s).

/vendor/twig/twig/lib/Twig/FileExtensionEscapingStrategy.php  
  1. class Twig_FileExtensionEscapingStrategy 
  2. /** 
  3. * Guesses the best autoescaping strategy based on the file name. 
  4. * @param string $name The template name 
  5. * @return string|false The escaping strategy name to use or false to disable 
  6. */ 
  7. public static function guess($name) 
  8. if (in_array(substr($name, -1), array('/', '\\'))) { 
  9. return 'html'; // return html for directories 
  10.  
  11. if ('.twig' === substr($name, -5)) { 
  12. $name = substr($name, 0, -5); 
  13.  
  14. $extension = pathinfo($name, PATHINFO_EXTENSION); 
  15.  
  16. switch ($extension) { 
  17. case 'js': 
  18. return 'js'; 
  19.  
  20. case 'css': 
  21. return 'css'; 
  22.  
  23. case 'txt': 
  24. return false; 
  25.  
  26. default: 
  27. return 'html';