From: Fabien Potencier Date: Wed, 25 Apr 2012 06:23:58 +0000 (+0200) Subject: added a way to change the default escaping strategy after creating the Twig environment X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=67c71201e6096a3ef03d10bcd67a28d928352a81;p=web%2Fkonrad%2Ftwig.git added a way to change the default escaping strategy after creating the Twig environment --- diff --git a/lib/Twig/Extension/Escaper.php b/lib/Twig/Extension/Escaper.php index 2eedef9..b0aa8b1 100644 --- a/lib/Twig/Extension/Escaper.php +++ b/lib/Twig/Extension/Escaper.php @@ -14,12 +14,7 @@ class Twig_Extension_Escaper extends Twig_Extension public function __construct($defaultStrategy = 'html') { - // for BC - if (true === $defaultStrategy) { - $defaultStrategy = 'html'; - } - - $this->defaultStrategy = $defaultStrategy; + $this->setDefaultStrategy($defaultStrategy); } /** @@ -54,6 +49,31 @@ class Twig_Extension_Escaper extends Twig_Extension ); } + /** + * Sets the default strategy to use when not defined by the user. + * + * The strategy can be a valid PHP callback that takes the template + * "filename" as an argument and returns the strategy to use. + * + * @param mixed $defaultStrategy An escaping strategy + */ + public function setDefaultStrategy($defaultStrategy) + { + // for BC + if (true === $defaultStrategy) { + $defaultStrategy = 'html'; + } + + $this->defaultStrategy = $defaultStrategy; + } + + /** + * Gets the default strategy to use when not defined by the user. + * + * @param string $filename The template "filename" + * + * @return string The default strategy to use for the template + */ public function getDefaultStrategy($filename) { if (is_callable($this->defaultStrategy)) {