mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-13 02:46:29 +00:00
Use Template->getContext in non-strict mode too
This commit is contained in:
@@ -34,10 +34,8 @@ class Twig_Node_Expression_Name extends Twig_Node_Expression
|
||||
}
|
||||
} elseif (isset($specialVars[$name])) {
|
||||
$compiler->raw($specialVars[$name]);
|
||||
} elseif ($compiler->getEnvironment()->isStrictVariables()) {
|
||||
$compiler->raw(sprintf('$this->getContext($context, \'%s\')', $name));
|
||||
} else {
|
||||
$compiler->raw(sprintf('(isset($context[\'%s\']) ? $context[\'%s\'] : null)', $name, $name));
|
||||
$compiler->raw(sprintf('$this->getContext($context, \'%s\')', $name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,11 +224,17 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
||||
* @param array $context The context
|
||||
* @param string $item The variable to return from the context
|
||||
*
|
||||
* @throws Twig_Error_Runtime if the variable does not exist
|
||||
* @return The content of the context variable
|
||||
*
|
||||
* @throws Twig_Error_Runtime if the variable does not exist and Twig is running in strict mode
|
||||
*/
|
||||
protected function getContext($context, $item)
|
||||
{
|
||||
if (!array_key_exists($item, $context)) {
|
||||
if (!$this->env->isStrictVariables()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
throw new Twig_Error_Runtime(sprintf('Variable "%s" does not exist', $item));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user