From 2fb20cdf7769942384971002b28f5971d97a9800 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 19 Feb 2012 11:09:47 +0100 Subject: [PATCH] added some information about Twig_Template::getContext() and made it final --- CHANGELOG | 1 - lib/Twig/Node/Expression/Name.php | 3 +++ lib/Twig/Template.php | 10 +++++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 0b69230..34af8c9 100644 --- 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 diff --git a/lib/Twig/Node/Expression/Name.php b/lib/Twig/Node/Expression/Name.php index 4b8d541..8f5a1ea 100644 --- a/lib/Twig/Node/Expression/Name.php +++ b/lib/Twig/Node/Expression/Name.php @@ -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 diff --git a/lib/Twig/Template.php b/lib/Twig/Template.php index 8bc64f0..7cb36c9 100644 --- a/lib/Twig/Template.php +++ b/lib/Twig/Template.php @@ -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()) { -- 1.7.2.5