Skip to content

Commit

Permalink
removed usage of deprecated constants
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Aug 5, 2013
1 parent 696ef2d commit 7b80c94
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 26 deletions.
4 changes: 3 additions & 1 deletion doc/deprecated.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------
Expand Down
8 changes: 4 additions & 4 deletions ext/twig/twig.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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;
}
Expand All @@ -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());
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions lib/Twig/ExpressionParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public function getFunctionNode($name, $line)
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)) {
Expand All @@ -343,7 +343,7 @@ public function parseSubscriptExpression($node)
$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 (
Expand All @@ -369,11 +369,11 @@ public function parseSubscriptExpression($node)
}

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;
Expand Down
4 changes: 2 additions & 2 deletions lib/Twig/Node/Expression/GetAttr.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public function compile(Twig_Compiler $compiler)

$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'));
}

Expand Down
12 changes: 6 additions & 6 deletions lib/Twig/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,18 +328,18 @@ final protected function getContext($context, $item, $ignoreStrictCheck = false)
* @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
*
* @return mixed The attribute value, or a Boolean when $isDefinedTest is true, or null when the attribute is not set and $ignoreStrictCheck is true
*
* @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))
Expand All @@ -352,7 +352,7 @@ protected function getAttribute($object, $item, array $arguments = array(), $typ
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;
}
Expand All @@ -365,7 +365,7 @@ protected function getAttribute($object, $item, array $arguments = array(), $typ
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());
Expand All @@ -388,7 +388,7 @@ protected function getAttribute($object, $item, array $arguments = array(), $typ
$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;
Expand Down
10 changes: 5 additions & 5 deletions test/Twig/Tests/Node/Expression/GetAttrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ public function testConstructor()
$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'));
}

/**
Expand All @@ -45,16 +45,16 @@ public function getTests()
$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;
Expand Down
8 changes: 4 additions & 4 deletions test/Twig/Tests/TemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,9 @@ public function getGetAttributeTests()
$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)
Expand Down Expand Up @@ -462,7 +462,7 @@ protected function doDisplay(array $context, array $blocks = array())
{
}

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);
Expand Down

0 comments on commit 7b80c94

Please sign in to comment.