{
public function __construct(Exception $e)
{
- if ($e instanceof Twig_Error) {
+ if ($e instanceof Twig_Error && -1 !== $e->getTemplateLine() && null === $e->getTemplateFile()) {
parent::__construct($e->getMessage(), $e->getTemplateLine(), $e->getTemplateFile(), $e);
} else {
list($lineno, $filename) = $this->findTemplateInfo($e);
->raw('), ')
->repr($this->getAttribute('type'))
->raw($this->hasAttribute('is_defined_test') ? ', true' : ', false')
- ->raw(sprintf(', %d', $this->lineno))
->raw(')');
}
}
} elseif ('_charset' === $this->getAttribute('name')) {
$compiler->raw('$this->env->getCharset()');
} elseif ($compiler->getEnvironment()->isStrictVariables()) {
- $compiler->raw(sprintf('$this->getContext($context, \'%s\', \'%s\')', $this->getAttribute('name'), $this->lineno));
+ $compiler->raw(sprintf('$this->getContext($context, \'%s\')', $this->getAttribute('name')));
} else {
$compiler->raw(sprintf('(isset($context[\'%s\']) ? $context[\'%s\'] : null)', $this->getAttribute('name'), $this->getAttribute('name')));
}
*
* @param array $context The context
* @param string $item The variable to return from the context
- * @param integer $line The line where the variable is get
*
* @param mixed The variable value in the context
*
* @throws Twig_Error_Runtime if the variable does not exist
*/
- protected function getContext($context, $item, $line = -1)
+ protected function getContext($context, $item)
{
if (!array_key_exists($item, $context)) {
- throw new Twig_Error_Runtime(sprintf('Variable "%s" does not exist', $item), $line, $this->getTemplateName());
+ throw new Twig_Error_Runtime(sprintf('Variable "%s" does not exist', $item));
}
return $context[$item];
* @param array $arguments An array of arguments to pass if the item is an object method
* @param integer $type The type of attribute (@see Twig_TemplateInterface)
* @param Boolean $noStrictCheck Whether to throw an exception if the item does not exist ot not
- * @param integer $line The line where the attribute is get
*/
- protected function getAttribute($object, $item, array $arguments = array(), $type = Twig_TemplateInterface::ANY_CALL, $noStrictCheck = false, $line = -1)
+ protected function getAttribute($object, $item, array $arguments = array(), $type = Twig_TemplateInterface::ANY_CALL, $noStrictCheck = false)
{
// array
if (Twig_TemplateInterface::METHOD_CALL !== $type) {
}
if (is_object($object)) {
- throw new Twig_Error_Runtime(sprintf('Key "%s" in object (with ArrayAccess) of type "%s" does not exist', $item, get_class($object)), $line, $this->getTemplateName());
+ throw new Twig_Error_Runtime(sprintf('Key "%s" in object (with ArrayAccess) of type "%s" does not exist', $item, get_class($object)));
// array
} else {
- throw new Twig_Error_Runtime(sprintf('Key "%s" for array with keys "%s" does not exist', $item, implode(', ', array_keys($object))), $line, $this->getTemplateName());
+ throw new Twig_Error_Runtime(sprintf('Key "%s" for array with keys "%s" does not exist', $item, implode(', ', array_keys($object))));
}
}
}
if (!$this->env->isStrictVariables() || $noStrictCheck) {
return null;
}
- throw new Twig_Error_Runtime(sprintf('Item "%s" for "%s" does not exist', $item, $object), $line, $this->getTemplateName());
+ throw new Twig_Error_Runtime(sprintf('Item "%s" for "%s" does not exist', $item, $object));
}
// get some information about the object
return null;
}
- throw new Twig_Error_Runtime(sprintf('Method "%s" for object "%s" does not exist', $item, get_class($object)), $line, $this->getTemplateName());
+ throw new Twig_Error_Runtime(sprintf('Method "%s" for object "%s" does not exist', $item, get_class($object)));
}
if ($this->env->hasExtension('sandbox')) {
$attr = new Twig_Node_Expression_Constant('bar', 0);
$args = new Twig_Node();
$node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_TemplateInterface::ANY_CALL, 0);
- $tests[] = array($node, '$this->getAttribute((isset($context[\'foo\']) ? $context[\'foo\'] : null), "bar", array(), "any", false, 0)');
+ $tests[] = array($node, '$this->getAttribute((isset($context[\'foo\']) ? $context[\'foo\'] : null), "bar", array(), "any", false)');
$node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_TemplateInterface::ARRAY_CALL, 0);
- $tests[] = array($node, '$this->getAttribute((isset($context[\'foo\']) ? $context[\'foo\'] : null), "bar", array(), "array", false, 0)');
+ $tests[] = array($node, '$this->getAttribute((isset($context[\'foo\']) ? $context[\'foo\'] : null), "bar", array(), "array", false)');
$args = new Twig_Node(array(
new Twig_Node_Expression_Constant('bar', 0),
));
$node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_TemplateInterface::METHOD_CALL, 0);
- $tests[] = array($node, '$this->getAttribute((isset($context[\'foo\']) ? $context[\'foo\'] : null), "bar", array((isset($context[\'foo\']) ? $context[\'foo\'] : null), "bar", ), "method", false, 0)');
+ $tests[] = array($node, '$this->getAttribute((isset($context[\'foo\']) ? $context[\'foo\'] : null), "bar", array((isset($context[\'foo\']) ? $context[\'foo\'] : null), "bar", ), "method", false)');
return $tests;
}
$env = new Twig_Environment(null, array('strict_variables' => true));
return array(
- array($node, '$this->getContext($context, \'foo\', \'0\')', $env),
+ array($node, '$this->getContext($context, \'foo\')', $env),
array($node, '(isset($context[\'foo\']) ? $context[\'foo\'] : null)'),
array($self, '$this'),
array($context, '$context'),