removed usage of deprecated constants

This commit is contained in:
Fabien Potencier
2013-08-05 18:21:48 +02:00
parent 696ef2daaa
commit 7b80c942e2
7 changed files with 28 additions and 26 deletions
+3 -1
View File
@@ -88,7 +88,9 @@ Interfaces
* ``Twig_NodeInterface`` (use ``Twig_Node`` instead) * ``Twig_NodeInterface`` (use ``Twig_Node`` instead)
* ``Twig_ParserInterface`` (use ``Twig_Parser`` instead) * ``Twig_ParserInterface`` (use ``Twig_Parser`` instead)
* ``Twig_ExistsLoaderInterface`` (merged with ``Twig_LoaderInterface``) * ``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 Globals
------- -------
+4 -4
View File
@@ -775,7 +775,7 @@ PHP_FUNCTION(twig_template_get_attributes)
/* /*
// array // array
if (Twig_TemplateInterface::METHOD_CALL !== $type) { if (Twig_Template::METHOD_CALL !== $type) {
$arrayItem = is_bool($item) || is_float($item) ? (int) $item : $item; $arrayItem = is_bool($item) || is_float($item) ? (int) $item : $item;
if ((is_array($object) && array_key_exists($arrayItem, $object)) if ((is_array($object) && array_key_exists($arrayItem, $object))
@@ -811,7 +811,7 @@ PHP_FUNCTION(twig_template_get_attributes)
return; return;
} }
/* /*
if (Twig_TemplateInterface::ARRAY_CALL === $type) { if (Twig_Template::ARRAY_CALL === $type) {
if ($isDefinedTest) { if ($isDefinedTest) {
return false; 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()); 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)) { } 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()); 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()); 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 { } 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()); 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 // 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 (isset($object->$item) || array_key_exists((string) $item, $object)) {
if ($isDefinedTest) { if ($isDefinedTest) {
return true; return true;
+4 -4
View File
@@ -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()); 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: default:
$args = $this->parseArguments(true); $args = $this->parseArguments(true);
if (null !== $alias = $this->parser->getImportedSymbol('macro', $name)) { if (null !== $alias = $this->parser->getImportedSymbol('macro', $name)) {
@@ -343,7 +343,7 @@ class Twig_ExpressionParser
$token = $stream->next(); $token = $stream->next();
$lineno = $token->getLine(); $lineno = $token->getLine();
$arguments = new Twig_Node_Expression_Array(array(), $lineno); $arguments = new Twig_Node_Expression_Array(array(), $lineno);
$type = Twig_TemplateInterface::ANY_CALL; $type = Twig_Template::ANY_CALL;
if ($token->getValue() == '.') { if ($token->getValue() == '.') {
$token = $stream->next(); $token = $stream->next();
if ( if (
@@ -369,11 +369,11 @@ class Twig_ExpressionParser
} }
if ($stream->test(Twig_Token::PUNCTUATION_TYPE, '(')) { if ($stream->test(Twig_Token::PUNCTUATION_TYPE, '(')) {
$type = Twig_TemplateInterface::METHOD_CALL; $type = Twig_Template::METHOD_CALL;
$arguments = $this->createArrayFromArguments($this->parseArguments()); $arguments = $this->createArrayFromArguments($this->parseArguments());
} }
} else { } else {
$type = Twig_TemplateInterface::ARRAY_CALL; $type = Twig_Template::ARRAY_CALL;
// slice? // slice?
$slice = false; $slice = false;
+2 -2
View File
@@ -32,10 +32,10 @@ class Twig_Node_Expression_GetAttr extends Twig_Node_Expression
$compiler->raw(', ')->subcompile($this->getNode('attribute')); $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')); $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')); $compiler->raw(', ')->repr($this->getAttribute('type'));
} }
+6 -6
View File
@@ -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 $object The object or array from where to get the item
* @param mixed $item The item to get from the array or object * @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 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 $isDefinedTest Whether this is only a defined check
* @param Boolean $ignoreStrictCheck Whether to ignore the strict attribute check or not * @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 * @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 // array
if (Twig_TemplateInterface::METHOD_CALL !== $type) { if (Twig_Template::METHOD_CALL !== $type) {
$arrayItem = is_bool($item) || is_float($item) ? (int) $item : $item; $arrayItem = is_bool($item) || is_float($item) ? (int) $item : $item;
if ((is_array($object) && array_key_exists($arrayItem, $object)) if ((is_array($object) && array_key_exists($arrayItem, $object))
@@ -352,7 +352,7 @@ abstract class Twig_Template implements Twig_TemplateInterface
return $object[$arrayItem]; return $object[$arrayItem];
} }
if (Twig_TemplateInterface::ARRAY_CALL === $type || !is_object($object)) { if (Twig_Template::ARRAY_CALL === $type || !is_object($object)) {
if ($isDefinedTest) { if ($isDefinedTest) {
return false; 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()); 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)) { } 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()); 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()); 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 { } 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()); 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); $class = get_class($object);
// object property // 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 (isset($object->$item) || array_key_exists((string) $item, $object)) {
if ($isDefinedTest) { if ($isDefinedTest) {
return true; return true;
@@ -21,12 +21,12 @@ class Twig_Tests_Node_Expression_GetAttrTest extends Twig_Test_NodeTestCase
$args = new Twig_Node_Expression_Array(array(), 1); $args = new Twig_Node_Expression_Array(array(), 1);
$args->addElement(new Twig_Node_Expression_Name('foo', 1)); $args->addElement(new Twig_Node_Expression_Name('foo', 1));
$args->addElement(new Twig_Node_Expression_Constant('bar', 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($expr, $node->getNode('node'));
$this->assertEquals($attr, $node->getNode('attribute')); $this->assertEquals($attr, $node->getNode('attribute'));
$this->assertEquals($args, $node->getNode('arguments')); $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); $expr = new Twig_Node_Expression_Name('foo', 1);
$attr = new Twig_Node_Expression_Constant('bar', 1); $attr = new Twig_Node_Expression_Constant('bar', 1);
$args = new Twig_Node_Expression_Array(array(), 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'))); $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'))); $tests[] = array($node, sprintf('%s%s, "bar", array(), "array")', $this->getAttributeGetter(), $this->getVariableGetter('foo')));
$args = new Twig_Node_Expression_Array(array(), 1); $args = new Twig_Node_Expression_Array(array(), 1);
$args->addElement(new Twig_Node_Expression_Name('foo', 1)); $args->addElement(new Twig_Node_Expression_Name('foo', 1));
$args->addElement(new Twig_Node_Expression_Constant('bar', 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'))); $tests[] = array($node, sprintf('%s%s, "bar", array(0 => %s, 1 => "bar"), "method")', $this->getAttributeGetter(), $this->getVariableGetter('foo'), $this->getVariableGetter('foo')));
return $tests; return $tests;
+4 -4
View File
@@ -257,9 +257,9 @@ class Twig_Tests_TemplateTest extends PHPUnit_Framework_TestCase
$methodObject = new Twig_TemplateMethodObject(); $methodObject = new Twig_TemplateMethodObject();
$magicMethodObject = new Twig_TemplateMagicMethodObject(); $magicMethodObject = new Twig_TemplateMagicMethodObject();
$anyType = Twig_TemplateInterface::ANY_CALL; $anyType = Twig_Template::ANY_CALL;
$methodType = Twig_TemplateInterface::METHOD_CALL; $methodType = Twig_Template::METHOD_CALL;
$arrayType = Twig_TemplateInterface::ARRAY_CALL; $arrayType = Twig_Template::ARRAY_CALL;
$basicTests = array( $basicTests = array(
// array(defined, value, property to fetch) // 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) { if ($this->useExtGetAttribute) {
return twig_template_get_attributes($this, $object, $item, $arguments, $type, $isDefinedTest, $ignoreStrictCheck); return twig_template_get_attributes($this, $object, $item, $arguments, $type, $isDefinedTest, $ignoreStrictCheck);