4 * This file is part of Twig.
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
13 * Default autoescaping strategy based on file names.
15 * This strategy sets the HTML as the default autoescaping strategy,
16 * but changes it based on the template name.
18 * Note that there is no runtime performance impact as the
19 * default autoescaping strategy is set at compilation time.
21 * @author Fabien Potencier <fabien@symfony.com>
23 class Twig_FileExtensionEscapingStrategy
26 * Guesses the best autoescaping strategy based on the file name.
28 * @param string $name The template name
30 * @return string|false The escaping strategy name to use or false to disable
32 public static function guess($name)
34 if (in_array(substr($name, -1), array('/', '\\'))) {
35 return 'html'; // return html for directories
38 if ('.twig' === substr($name, -5)) {
39 $name = substr($name, 0, -5);
42 $extension = pathinfo($name, PATHINFO_EXTENSION);
60 class_alias('Twig_FileExtensionEscapingStrategy', 'Twig\FileExtensionEscapingStrategy', false);