From 67c71201e6096a3ef03d10bcd67a28d928352a81 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 25 Apr 2012 08:23:58 +0200 Subject: [PATCH] added a way to change the default escaping strategy after creating the Twig environment --- lib/Twig/Extension/Escaper.php | 32 ++++++++++++++++++++++++++------ 1 files changed, 26 insertions(+), 6 deletions(-) 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)) { -- 1.7.2.5