From: Fabien Potencier Date: Tue, 12 Apr 2011 06:11:29 +0000 (+0200) Subject: removed line parameter from Twig_Template::getAttribute() and getContext() as the... X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=96f2261112161155087e87bab0f857c0d2c8f52a;p=web%2Fkonrad%2Ftwig.git removed line parameter from Twig_Template::getAttribute() and getContext() as the information is now gathered by Twig_Error_Wrapped --- diff --git a/lib/Twig/Error/Wrapped.php b/lib/Twig/Error/Wrapped.php index c4556c3..54190fd 100644 --- a/lib/Twig/Error/Wrapped.php +++ b/lib/Twig/Error/Wrapped.php @@ -19,7 +19,7 @@ class Twig_Error_Wrapped extends Twig_Error_Runtime { 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); diff --git a/lib/Twig/Node/Expression/GetAttr.php b/lib/Twig/Node/Expression/GetAttr.php index c8140b6..0ac04f6 100644 --- a/lib/Twig/Node/Expression/GetAttr.php +++ b/lib/Twig/Node/Expression/GetAttr.php @@ -37,7 +37,6 @@ class Twig_Node_Expression_GetAttr extends Twig_Node_Expression ->raw('), ') ->repr($this->getAttribute('type')) ->raw($this->hasAttribute('is_defined_test') ? ', true' : ', false') - ->raw(sprintf(', %d', $this->lineno)) ->raw(')'); } } diff --git a/lib/Twig/Node/Expression/Name.php b/lib/Twig/Node/Expression/Name.php index 6c03e93..a7194b7 100644 --- a/lib/Twig/Node/Expression/Name.php +++ b/lib/Twig/Node/Expression/Name.php @@ -25,7 +25,7 @@ class Twig_Node_Expression_Name extends Twig_Node_Expression } 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'))); } diff --git a/lib/Twig/Template.php b/lib/Twig/Template.php index b7bd325..6a6ff3b 100644 --- a/lib/Twig/Template.php +++ b/lib/Twig/Template.php @@ -213,16 +213,15 @@ abstract class Twig_Template implements Twig_TemplateInterface * * @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]; @@ -236,9 +235,8 @@ abstract class Twig_Template implements Twig_TemplateInterface * @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) { @@ -252,10 +250,10 @@ abstract class Twig_Template implements Twig_TemplateInterface } 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)))); } } } @@ -264,7 +262,7 @@ abstract class Twig_Template implements Twig_TemplateInterface 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 @@ -307,7 +305,7 @@ abstract class Twig_Template implements Twig_TemplateInterface 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')) { diff --git a/test/Twig/Tests/Node/Expression/GetAttrTest.php b/test/Twig/Tests/Node/Expression/GetAttrTest.php index 599d1fc..7b38e03 100644 --- a/test/Twig/Tests/Node/Expression/GetAttrTest.php +++ b/test/Twig/Tests/Node/Expression/GetAttrTest.php @@ -49,10 +49,10 @@ class Twig_Tests_Node_Expression_GetAttrTest extends Twig_Tests_Node_TestCase $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( @@ -60,7 +60,7 @@ class Twig_Tests_Node_Expression_GetAttrTest extends Twig_Tests_Node_TestCase 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; } diff --git a/test/Twig/Tests/Node/Expression/NameTest.php b/test/Twig/Tests/Node/Expression/NameTest.php index 70b6654..3d8e03a 100644 --- a/test/Twig/Tests/Node/Expression/NameTest.php +++ b/test/Twig/Tests/Node/Expression/NameTest.php @@ -41,7 +41,7 @@ class Twig_Tests_Node_Expression_NameTest extends Twig_Tests_Node_TestCase $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'),