]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - inc/3rdparty/Twig/Extension/Escaper.php
4 * This file is part of Twig.
6 * (c) 2009 Fabien Potencier
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
11 class Twig_Extension_Escaper
extends Twig_Extension
13 protected $defaultStrategy;
15 public function __construct($defaultStrategy = 'html')
17 $this->setDefaultStrategy($defaultStrategy);
21 * Returns the token parser instances to add to the existing list.
23 * @return array An array of Twig_TokenParserInterface or Twig_TokenParserBrokerInterface instances
25 public function getTokenParsers()
27 return array(new Twig_TokenParser_AutoEscape());
31 * Returns the node visitor instances to add to the existing list.
33 * @return array An array of Twig_NodeVisitorInterface instances
35 public function getNodeVisitors()
37 return array(new Twig_NodeVisitor_Escaper());
41 * Returns a list of filters to add to the existing list.
43 * @return array An array of filters
45 public function getFilters()
48 new Twig_SimpleFilter('raw', 'twig_raw_filter', array('is_safe' => array('all'))),
53 * Sets the default strategy to use when not defined by the user.
55 * The strategy can be a valid PHP callback that takes the template
56 * "filename" as an argument and returns the strategy to use.
58 * @param mixed $defaultStrategy An escaping strategy
60 public function setDefaultStrategy($defaultStrategy)
63 if (true === $defaultStrategy) {
64 $defaultStrategy = 'html';
67 $this->defaultStrategy
= $defaultStrategy;
71 * Gets the default strategy to use when not defined by the user.
73 * @param string $filename The template "filename"
75 * @return string The default strategy to use for the template
77 public function getDefaultStrategy($filename)
79 // disable string callables to avoid calling a function named html or js,
80 // or any other upcoming escaping strategy
81 if (!is_string($this->defaultStrategy
) && is_callable($this->defaultStrategy
)) {
82 return call_user_func($this->defaultStrategy
, $filename);
85 return $this->defaultStrategy
;
89 * Returns the name of the extension.
91 * @return string The extension name
93 public function getName()
100 * Marks a variable as being safe.
102 * @param string $string A PHP variable
104 function twig_raw_filter($string)