From 7b80c942e21793ed6f8bf235015c447e508eac60 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 5 Aug 2013 18:21:48 +0200 Subject: [PATCH] removed usage of deprecated constants --- doc/deprecated.rst | 4 +++- ext/twig/twig.c | 8 ++++---- lib/Twig/ExpressionParser.php | 8 ++++---- lib/Twig/Node/Expression/GetAttr.php | 4 ++-- lib/Twig/Template.php | 12 ++++++------ test/Twig/Tests/Node/Expression/GetAttrTest.php | 10 +++++----- test/Twig/Tests/TemplateTest.php | 8 ++++---- 7 files changed, 28 insertions(+), 26 deletions(-) diff --git a/doc/deprecated.rst b/doc/deprecated.rst index f0a3a0f..ff50f0d 100644 --- a/doc/deprecated.rst +++ b/doc/deprecated.rst @@ -88,7 +88,9 @@ Interfaces * ``Twig_NodeInterface`` (use ``Twig_Node`` instead) * ``Twig_ParserInterface`` (use ``Twig_Parser`` instead) * ``Twig_ExistsLoaderInterface`` (merged with ``Twig_LoaderInterface``) -* ``Twig_TemplateInterface`` (use ``Twig_Template`` instead) +* ``Twig_TemplateInterface`` (use ``Twig_Template`` instead, and use + those constants Twig_Template::ANY_CALL, Twig_Template::ARRAY_CALL, + Twig_Template::METHOD_CALL) Globals ------- diff --git a/ext/twig/twig.c b/ext/twig/twig.c index d71ed35..d41e2a8 100644 --- a/ext/twig/twig.c +++ b/ext/twig/twig.c @@ -775,7 +775,7 @@ PHP_FUNCTION(twig_template_get_attributes) /* // array - if (Twig_TemplateInterface::METHOD_CALL !== $type) { + if (Twig_Template::METHOD_CALL !== $type) { $arrayItem = is_bool($item) || is_float($item) ? (int) $item : $item; if ((is_array($object) && array_key_exists($arrayItem, $object)) @@ -811,7 +811,7 @@ PHP_FUNCTION(twig_template_get_attributes) return; } /* - if (Twig_TemplateInterface::ARRAY_CALL === $type) { + if (Twig_Template::ARRAY_CALL === $type) { if ($isDefinedTest) { return false; } @@ -831,7 +831,7 @@ PHP_FUNCTION(twig_template_get_attributes) throw new Twig_Error_Runtime(sprintf('Key "%s" in object (with ArrayAccess) of type "%s" does not exist', $arrayItem, get_class($object)), -1, $this->getTemplateName()); } elseif (is_array($object)) { throw new Twig_Error_Runtime(sprintf('Key "%s" for array with keys "%s" does not exist', $arrayItem, implode(', ', array_keys($object))), -1, $this->getTemplateName()); - } elseif (Twig_TemplateInterface::ARRAY_CALL === $type) { + } elseif (Twig_Template::ARRAY_CALL === $type) { throw new Twig_Error_Runtime(sprintf('Impossible to access a key ("%s") on a %s variable ("%s")', $item, gettype($object), $object), -1, $this->getTemplateName()); } else { throw new Twig_Error_Runtime(sprintf('Impossible to access an attribute ("%s") on a %s variable ("%s")', $item, gettype($object), $object), -1, $this->getTemplateName()); @@ -908,7 +908,7 @@ PHP_FUNCTION(twig_template_get_attributes) /* // object property - if (Twig_TemplateInterface::METHOD_CALL !== $type) { + if (Twig_Template::METHOD_CALL !== $type) { if (isset($object->$item) || array_key_exists((string) $item, $object)) { if ($isDefinedTest) { return true; diff --git a/lib/Twig/ExpressionParser.php b/lib/Twig/ExpressionParser.php index 1687e11..9deab09 100644 --- a/lib/Twig/ExpressionParser.php +++ b/lib/Twig/ExpressionParser.php @@ -316,7 +316,7 @@ class Twig_ExpressionParser throw new Twig_Error_Syntax('The "attribute" function takes at least two arguments (the variable and the attributes)', $line, $this->parser->getFilename()); } - return new Twig_Node_Expression_GetAttr($args->getNode(0), $args->getNode(1), count($args) > 2 ? $args->getNode(2) : new Twig_Node_Expression_Array(array(), $line), Twig_TemplateInterface::ANY_CALL, $line); + return new Twig_Node_Expression_GetAttr($args->getNode(0), $args->getNode(1), count($args) > 2 ? $args->getNode(2) : new Twig_Node_Expression_Array(array(), $line), Twig_Template::ANY_CALL, $line); default: $args = $this->parseArguments(true); if (null !== $alias = $this->parser->getImportedSymbol('macro', $name)) { @@ -343,7 +343,7 @@ class Twig_ExpressionParser $token = $stream->next(); $lineno = $token->getLine(); $arguments = new Twig_Node_Expression_Array(array(), $lineno); - $type = Twig_TemplateInterface::ANY_CALL; + $type = Twig_Template::ANY_CALL; if ($token->getValue() == '.') { $token = $stream->next(); if ( @@ -369,11 +369,11 @@ class Twig_ExpressionParser } if ($stream->test(Twig_Token::PUNCTUATION_TYPE, '(')) { - $type = Twig_TemplateInterface::METHOD_CALL; + $type = Twig_Template::METHOD_CALL; $arguments = $this->createArrayFromArguments($this->parseArguments()); } } else { - $type = Twig_TemplateInterface::ARRAY_CALL; + $type = Twig_Template::ARRAY_CALL; // slice? $slice = false; diff --git a/lib/Twig/Node/Expression/GetAttr.php b/lib/Twig/Node/Expression/GetAttr.php index 81a9b13..55d9fcc 100644 --- a/lib/Twig/Node/Expression/GetAttr.php +++ b/lib/Twig/Node/Expression/GetAttr.php @@ -32,10 +32,10 @@ class Twig_Node_Expression_GetAttr extends Twig_Node_Expression $compiler->raw(', ')->subcompile($this->getNode('attribute')); - if (count($this->getNode('arguments')) || Twig_TemplateInterface::ANY_CALL !== $this->getAttribute('type') || $this->getAttribute('is_defined_test') || $this->getAttribute('ignore_strict_check')) { + if (count($this->getNode('arguments')) || Twig_Template::ANY_CALL !== $this->getAttribute('type') || $this->getAttribute('is_defined_test') || $this->getAttribute('ignore_strict_check')) { $compiler->raw(', ')->subcompile($this->getNode('arguments')); - if (Twig_TemplateInterface::ANY_CALL !== $this->getAttribute('type') || $this->getAttribute('is_defined_test') || $this->getAttribute('ignore_strict_check')) { + if (Twig_Template::ANY_CALL !== $this->getAttribute('type') || $this->getAttribute('is_defined_test') || $this->getAttribute('ignore_strict_check')) { $compiler->raw(', ')->repr($this->getAttribute('type')); } diff --git a/lib/Twig/Template.php b/lib/Twig/Template.php index 22a7e58..a42fab2 100644 --- a/lib/Twig/Template.php +++ b/lib/Twig/Template.php @@ -328,7 +328,7 @@ abstract class Twig_Template implements Twig_TemplateInterface * @param mixed $object The object or array from where to get the item * @param mixed $item The item to get from the array or object * @param array $arguments An array of arguments to pass if the item is an object method - * @param string $type The type of attribute (@see Twig_TemplateInterface) + * @param string $type The type of attribute (@see Twig_Template constants) * @param Boolean $isDefinedTest Whether this is only a defined check * @param Boolean $ignoreStrictCheck Whether to ignore the strict attribute check or not * @@ -336,10 +336,10 @@ abstract class Twig_Template implements Twig_TemplateInterface * * @throws Twig_Error_Runtime if the attribute does not exist and Twig is running in strict mode and $isDefinedTest is false */ - protected function getAttribute($object, $item, array $arguments = array(), $type = Twig_TemplateInterface::ANY_CALL, $isDefinedTest = false, $ignoreStrictCheck = false) + protected function getAttribute($object, $item, array $arguments = array(), $type = Twig_Template::ANY_CALL, $isDefinedTest = false, $ignoreStrictCheck = false) { // array - if (Twig_TemplateInterface::METHOD_CALL !== $type) { + if (Twig_Template::METHOD_CALL !== $type) { $arrayItem = is_bool($item) || is_float($item) ? (int) $item : $item; if ((is_array($object) && array_key_exists($arrayItem, $object)) @@ -352,7 +352,7 @@ abstract class Twig_Template implements Twig_TemplateInterface return $object[$arrayItem]; } - if (Twig_TemplateInterface::ARRAY_CALL === $type || !is_object($object)) { + if (Twig_Template::ARRAY_CALL === $type || !is_object($object)) { if ($isDefinedTest) { return false; } @@ -365,7 +365,7 @@ abstract class Twig_Template implements Twig_TemplateInterface throw new Twig_Error_Runtime(sprintf('Key "%s" in object (with ArrayAccess) of type "%s" does not exist', $arrayItem, get_class($object)), -1, $this->getTemplateName()); } elseif (is_array($object)) { throw new Twig_Error_Runtime(sprintf('Key "%s" for array with keys "%s" does not exist', $arrayItem, implode(', ', array_keys($object))), -1, $this->getTemplateName()); - } elseif (Twig_TemplateInterface::ARRAY_CALL === $type) { + } elseif (Twig_Template::ARRAY_CALL === $type) { throw new Twig_Error_Runtime(sprintf('Impossible to access a key ("%s") on a %s variable ("%s")', $item, gettype($object), $object), -1, $this->getTemplateName()); } else { throw new Twig_Error_Runtime(sprintf('Impossible to access an attribute ("%s") on a %s variable ("%s")', $item, gettype($object), $object), -1, $this->getTemplateName()); @@ -388,7 +388,7 @@ abstract class Twig_Template implements Twig_TemplateInterface $class = get_class($object); // object property - if (Twig_TemplateInterface::METHOD_CALL !== $type) { + if (Twig_Template::METHOD_CALL !== $type) { if (isset($object->$item) || array_key_exists((string) $item, $object)) { if ($isDefinedTest) { return true; diff --git a/test/Twig/Tests/Node/Expression/GetAttrTest.php b/test/Twig/Tests/Node/Expression/GetAttrTest.php index 6a63cce..62fb0d3 100644 --- a/test/Twig/Tests/Node/Expression/GetAttrTest.php +++ b/test/Twig/Tests/Node/Expression/GetAttrTest.php @@ -21,12 +21,12 @@ class Twig_Tests_Node_Expression_GetAttrTest extends Twig_Test_NodeTestCase $args = new Twig_Node_Expression_Array(array(), 1); $args->addElement(new Twig_Node_Expression_Name('foo', 1)); $args->addElement(new Twig_Node_Expression_Constant('bar', 1)); - $node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_TemplateInterface::ARRAY_CALL, 1); + $node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_Template::ARRAY_CALL, 1); $this->assertEquals($expr, $node->getNode('node')); $this->assertEquals($attr, $node->getNode('attribute')); $this->assertEquals($args, $node->getNode('arguments')); - $this->assertEquals(Twig_TemplateInterface::ARRAY_CALL, $node->getAttribute('type')); + $this->assertEquals(Twig_Template::ARRAY_CALL, $node->getAttribute('type')); } /** @@ -45,16 +45,16 @@ class Twig_Tests_Node_Expression_GetAttrTest extends Twig_Test_NodeTestCase $expr = new Twig_Node_Expression_Name('foo', 1); $attr = new Twig_Node_Expression_Constant('bar', 1); $args = new Twig_Node_Expression_Array(array(), 1); - $node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_TemplateInterface::ANY_CALL, 1); + $node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_Template::ANY_CALL, 1); $tests[] = array($node, sprintf('%s%s, "bar")', $this->getAttributeGetter(), $this->getVariableGetter('foo'))); - $node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_TemplateInterface::ARRAY_CALL, 1); + $node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_Template::ARRAY_CALL, 1); $tests[] = array($node, sprintf('%s%s, "bar", array(), "array")', $this->getAttributeGetter(), $this->getVariableGetter('foo'))); $args = new Twig_Node_Expression_Array(array(), 1); $args->addElement(new Twig_Node_Expression_Name('foo', 1)); $args->addElement(new Twig_Node_Expression_Constant('bar', 1)); - $node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_TemplateInterface::METHOD_CALL, 1); + $node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_Template::METHOD_CALL, 1); $tests[] = array($node, sprintf('%s%s, "bar", array(0 => %s, 1 => "bar"), "method")', $this->getAttributeGetter(), $this->getVariableGetter('foo'), $this->getVariableGetter('foo'))); return $tests; diff --git a/test/Twig/Tests/TemplateTest.php b/test/Twig/Tests/TemplateTest.php index f267b1a..876718d 100644 --- a/test/Twig/Tests/TemplateTest.php +++ b/test/Twig/Tests/TemplateTest.php @@ -257,9 +257,9 @@ class Twig_Tests_TemplateTest extends PHPUnit_Framework_TestCase $methodObject = new Twig_TemplateMethodObject(); $magicMethodObject = new Twig_TemplateMagicMethodObject(); - $anyType = Twig_TemplateInterface::ANY_CALL; - $methodType = Twig_TemplateInterface::METHOD_CALL; - $arrayType = Twig_TemplateInterface::ARRAY_CALL; + $anyType = Twig_Template::ANY_CALL; + $methodType = Twig_Template::METHOD_CALL; + $arrayType = Twig_Template::ARRAY_CALL; $basicTests = array( // array(defined, value, property to fetch) @@ -462,7 +462,7 @@ class Twig_TemplateTest extends Twig_Template { } - public function getAttribute($object, $item, array $arguments = array(), $type = Twig_TemplateInterface::ANY_CALL, $isDefinedTest = false, $ignoreStrictCheck = false) + public function getAttribute($object, $item, array $arguments = array(), $type = Twig_Template::ANY_CALL, $isDefinedTest = false, $ignoreStrictCheck = false) { if ($this->useExtGetAttribute) { return twig_template_get_attributes($this, $object, $item, $arguments, $type, $isDefinedTest, $ignoreStrictCheck); -- 1.7.2.5