From: Fabien Potencier Date: Fri, 28 May 2010 05:59:29 +0000 (+0200) Subject: renamed ignore_invalid_vars to strict_variables X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=28bbe6f2deff9f1ccbe4feaba060899c16b12827;p=konrad%2Ftwig.git renamed ignore_invalid_vars to strict_variables --- diff --git a/CHANGELOG b/CHANGELOG index d5adc45..f0a58e7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -5,7 +5,7 @@ Backward incompatibilities: * fixed iterator_to_array() usage * changed the date filter to support any date format supported by DateTime - * added ignore_invalid_variables setting to throw an exception when an invalid variable is used in a template (disabled automatically when debug is true) + * added strict_variable setting to throw an exception when an invalid variable is used in a template (disabled by default when debug is false) * added the lexer, parser, and compiler as arguments to the Twig_Environment constructor * changed the cache option to only accepts an explicit path to a cache directory or false * added a way to add token parsers, filters, and visitors without creating an extension diff --git a/doc/03-Twig-for-Developers.markdown b/doc/03-Twig-for-Developers.markdown index ee55dc1..5dfbceb 100644 --- a/doc/03-Twig-for-Developers.markdown +++ b/doc/03-Twig-for-Developers.markdown @@ -93,12 +93,12 @@ The following options are available: the `auto_reload` option, it will be determined automatically based on the `debug` value. - * `ignore_invalid_variables` (new in Twig 0.9.7): If set to `true`, Twig will + * `strict_variables` (new in Twig 0.9.7): If set to `false`, Twig will silently ignore invalid variables (variables and or attributes/methods that - do not exist) and replace them with a `null` value. When set to `false`, + do not exist) and replace them with a `null` value. When set to `true`, Twig throws an exception instead. If you don't provide a value for the - `ignore_invalid_variables` option, it will be determined automatically - based on the `debug` value (`false` when in debug mode, `true` otherwise). + `strict_variables` option, it will be determined automatically based on the + `debug` value. >**CAUTION** >Before Twig 0.9.3, the `cache` and `auto_reload` options did not exist. They diff --git a/lib/Twig/Environment.php b/lib/Twig/Environment.php index 87a8d4c..4a72e60 100644 --- a/lib/Twig/Environment.php +++ b/lib/Twig/Environment.php @@ -29,7 +29,7 @@ class Twig_Environment protected $filters; protected $runtimeInitialized; protected $loadedTemplates; - protected $ignoreInvalidVars; + protected $strictVariables; /** * Constructor. @@ -56,7 +56,7 @@ class Twig_Environment * If you don't provide the auto_reload option, it will be * determined automatically base on the debug value. * - * * ignore_invalid_variables: Whether to ignore invalid variables in templates (default to the opposite value of debug). + * * strict_variables: Whether to ignore invalid variables in templates (default to the opposite value of debug). * * @param Twig_LoaderInterface $loader A Twig_LoaderInterface instance * @param array $options An array of options @@ -77,7 +77,7 @@ class Twig_Environment $this->baseTemplateClass = isset($options['base_template_class']) ? $options['base_template_class'] : 'Twig_Template'; $this->autoReload = isset($options['auto_reload']) ? (bool) $options['auto_reload'] : $this->debug; $this->extensions = array('core' => new Twig_Extension_Core()); - $this->ignoreInvalidVars = isset($options['ignore_invalid_variables']) ? (bool) $options['ignore_invalid_variables'] : !$this->debug; + $this->strictVariables = isset($options['strict_variables']) ? (bool) $options['strict_variables'] : $this->debug; $this->runtimeInitialized = false; if (isset($options['cache']) && $options['cache']) { $this->setCache($options['cache']); @@ -119,19 +119,19 @@ class Twig_Environment $this->autoReload = (Boolean) $autoReload; } - public function enableignoreInvalidVars() + public function enableStrictVariables() { - $this->ignoreInvalidVars = true; + $this->strictVariables = true; } - public function disableignoreInvalidVars() + public function disableStrictVariables() { - $this->ignoreInvalidVars = false; + $this->strictVariables = false; } - public function ignoresInvalidVars() + public function isStrictVariables() { - return $this->ignoreInvalidVars; + return $this->strictVariables; } public function getCache() diff --git a/lib/Twig/Resource.php b/lib/Twig/Resource.php index bfef8be..588e11f 100644 --- a/lib/Twig/Resource.php +++ b/lib/Twig/Resource.php @@ -35,7 +35,7 @@ abstract class Twig_Resource return $context[$item]; } - if ($this->env->ignoresInvalidVars()) { + if (!$this->env->isStrictVariables()) { return null; } @@ -51,7 +51,7 @@ abstract class Twig_Resource } if ($arrayOnly || !is_object($object)) { - if ($this->env->ignoresInvalidVars()) { + if (!$this->env->isStrictVariables()) { return null; } @@ -84,7 +84,7 @@ abstract class Twig_Resource } elseif (isset($this->cache[$class]['__call'])) { $method = $item; } else { - if ($this->env->ignoresInvalidVars()) { + if (!$this->env->isStrictVariables()) { return null; }