Security update to Drupal 8.4.6
[yaffs-website] / vendor / twig / twig / lib / Twig / FileExtensionEscapingStrategy.php
1 <?php
2
3 /*
4  * This file is part of Twig.
5  *
6  * (c) Fabien Potencier
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 /**
13  * Default autoescaping strategy based on file names.
14  *
15  * This strategy sets the HTML as the default autoescaping strategy,
16  * but changes it based on the template name.
17  *
18  * Note that there is no runtime performance impact as the
19  * default autoescaping strategy is set at compilation time.
20  *
21  * @author Fabien Potencier <fabien@symfony.com>
22  */
23 class Twig_FileExtensionEscapingStrategy
24 {
25     /**
26      * Guesses the best autoescaping strategy based on the file name.
27      *
28      * @param string $name The template name
29      *
30      * @return string|false The escaping strategy name to use or false to disable
31      */
32     public static function guess($name)
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     }
58 }
59
60 class_alias('Twig_FileExtensionEscapingStrategy', 'Twig\FileExtensionEscapingStrategy', false);