added some information about Twig_Template::getContext() and made it final
authorFabien Potencier <fabien.potencier@gmail.com>
Sun, 19 Feb 2012 10:09:47 +0000 (11:09 +0100)
committerFabien Potencier <fabien.potencier@gmail.com>
Sun, 19 Feb 2012 10:09:47 +0000 (11:09 +0100)
CHANGELOG
lib/Twig/Node/Expression/Name.php
lib/Twig/Template.php

index 0b69230..34af8c9 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,5 @@
 * 1.7.0-DEV
 
- * removed hardcoded optimization in Twig_Expression_Node_Name as it is already covered by the Optimizer
  * removed the creation of Twig_Markup instances when not needed
  * added a way to set the default global timezone for dates
  * fixed the slice filter on strings when the length is not specified
index 4b8d541..8f5a1ea 100644 (file)
@@ -35,6 +35,9 @@ class Twig_Node_Expression_Name extends Twig_Node_Expression
         } elseif ($this->isSpecial()) {
             $compiler->raw($this->specialVars[$name]);
         } else {
+            // remove the non-PHP 5.4 version when PHP 5.3 support is dropped
+            // as the non-optimized version is just a workaround for slow ternary operator
+            // when the context has a lot of variables
             if (version_compare(phpversion(), '5.4.0RC1', '>=') && ($this->getAttribute('ignore_strict_check') || !$compiler->getEnvironment()->isStrictVariables())) {
                 // PHP 5.4 ternary operator performance was optimized
                 $compiler
index 8bc64f0..7cb36c9 100644 (file)
@@ -289,6 +289,14 @@ abstract class Twig_Template implements Twig_TemplateInterface
     /**
      * Returns a variable from the context.
      *
+     * This method is for internal use only and should never be called
+     * directly.
+     *
+     * This method should not be overriden in a sub-class as this is an
+     * implementation detail that has been introduced to optimize variable
+     * access for versions of PHP before 5.4. This is not a way to override
+     * the way to get a variable value.
+     *
      * @param array   $context           The context
      * @param string  $item              The variable to return from the context
      * @param Boolean $ignoreStrictCheck Whether to ignore the strict variable check or not
@@ -297,7 +305,7 @@ abstract class Twig_Template implements Twig_TemplateInterface
      *
      * @throws Twig_Error_Runtime if the variable does not exist and Twig is running in strict mode
      */
-    protected function getContext($context, $item, $ignoreStrictCheck = false)
+    final protected function getContext($context, $item, $ignoreStrictCheck = false)
     {
         if (!array_key_exists($item, $context)) {
             if ($ignoreStrictCheck || !$this->env->isStrictVariables()) {