Changes:
+ * removed coupling between Twig_Node and Twig_Template
* fixed the ternary operator precedence rule
* 1.0.0-RC1 (2011-01-09)
}
if (null !== $alias = $this->parser->getImportedFunction($node->getAttribute('name'))) {
- return new Twig_Node_Expression_GetAttr($alias['node'], new Twig_Node_Expression_Constant($alias['name'], $node->getLine()), $args, $node->getLine(), Twig_Node_Expression_GetAttr::TYPE_METHOD);
+ return new Twig_Node_Expression_GetAttr($alias['node'], new Twig_Node_Expression_Constant($alias['name'], $node->getLine()), $args, $node->getLine(), Twig_TemplateInterface::METHOD_CALL);
}
return new Twig_Node_Expression_Function($node, $args, $node->getLine());
$token = $this->parser->getStream()->next();
$lineno = $token->getLine();
$arguments = new Twig_Node();
- $type = Twig_Node_Expression_GetAttr::TYPE_ANY;
+ $type = Twig_TemplateInterface::ANY_CALL;
if ($token->getValue() == '.') {
$token = $this->parser->getStream()->next();
if (
$arg = new Twig_Node_Expression_Constant($token->getValue(), $lineno);
if ($this->parser->getStream()->test(Twig_Token::PUNCTUATION_TYPE, '(')) {
- $type = Twig_Node_Expression_GetAttr::TYPE_METHOD;
+ $type = Twig_TemplateInterface::METHOD_CALL;
$arguments = $this->parseArguments();
} else {
$arguments = new Twig_Node();
throw new Twig_Error_Syntax('Expected name or number', $lineno);
}
} else {
- $type = Twig_Node_Expression_GetAttr::TYPE_ARRAY;
+ $type = Twig_TemplateInterface::ARRAY_CALL;
$arg = $this->parseExpression();
$this->parser->getStream()->expect(Twig_Token::PUNCTUATION_TYPE, ']');
*/
class Twig_Node_Expression_GetAttr extends Twig_Node_Expression
{
- const TYPE_ANY = 'any';
- const TYPE_ARRAY = 'array';
- const TYPE_METHOD = 'method';
-
public function __construct(Twig_Node_Expression $node, Twig_Node_Expression $attribute, Twig_NodeInterface $arguments, $type, $lineno)
{
parent::__construct(array('node' => $node, 'attribute' => $attribute, 'arguments' => $arguments), array('type' => $type), $lineno);
* @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 integer $type The type of attribute (@see Twig_Node_Expression_GetAttr)
+ * @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_Node_Expression_GetAttr::TYPE_ANY, $noStrictCheck = false, $line = -1)
+ protected function getAttribute($object, $item, array $arguments = array(), $type = Twig_TemplateInterface::ANY_CALL, $noStrictCheck = false, $line = -1)
{
// array
- if (Twig_Node_Expression_GetAttr::TYPE_METHOD !== $type) {
+ if (Twig_TemplateInterface::METHOD_CALL !== $type) {
if ((is_array($object) || is_object($object) && $object instanceof ArrayAccess) && isset($object[$item])) {
return $object[$item];
}
- if (Twig_Node_Expression_GetAttr::TYPE_ARRAY === $type) {
+ if (Twig_TemplateInterface::ARRAY_CALL === $type) {
if (!$this->env->isStrictVariables() || $noStrictCheck) {
return null;
}
}
// object property
- if (Twig_Node_Expression_GetAttr::TYPE_METHOD !== $type) {
+ if (Twig_TemplateInterface::METHOD_CALL !== $type) {
if (isset(self::$cache[$class]['properties'][$item]) || isset($object->$item)) {
if ($this->env->hasExtension('sandbox')) {
$this->env->getExtension('sandbox')->checkPropertyAllowed($object, $item);
*/
interface Twig_TemplateInterface
{
+ const ANY_CALL = 'any';
+ const ARRAY_CALL = 'array';
+ const METHOD_CALL = 'method';
+
/**
* Renders the template with the given context and returns it as string.
*
new Twig_Node_Expression_Name('foo', 0),
new Twig_Node_Expression_Constant('bar', 0),
));
- $node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_Node_Expression_GetAttr::TYPE_ARRAY, 0);
+ $node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_TemplateInterface::ARRAY_CALL, 0);
$this->assertEquals($expr, $node->getNode('node'));
$this->assertEquals($attr, $node->getNode('attribute'));
$this->assertEquals($args, $node->getNode('arguments'));
- $this->assertEquals(Twig_Node_Expression_GetAttr::TYPE_ARRAY, $node->getAttribute('type'));
+ $this->assertEquals(Twig_TemplateInterface::ARRAY_CALL, $node->getAttribute('type'));
}
/**
$expr = new Twig_Node_Expression_Name('foo', 0);
$attr = new Twig_Node_Expression_Constant('bar', 0);
$args = new Twig_Node();
- $node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_Node_Expression_GetAttr::TYPE_ANY, 0);
+ $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)');
- $node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_Node_Expression_GetAttr::TYPE_ARRAY, 0);
+ $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)');
new Twig_Node_Expression_Name('foo', 0),
new Twig_Node_Expression_Constant('bar', 0),
));
- $node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_Node_Expression_GetAttr::TYPE_METHOD, 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)');
return $tests;
$env = new Twig_Environment(null, array('strict_variables' => true));
$template = new Twig_TemplateTest($env);
- $template->getAttribute($array, 'unknown', array(), Twig_Node_Expression_GetAttr::TYPE_ARRAY);
+ $template->getAttribute($array, 'unknown', array(), Twig_TemplateInterface::ARRAY_CALL);
}
/**
$objectArray = new Twig_TemplateObjectArrayAccess();
$objectMagic = new Twig_TemplateObjectMagic();
- $anyType = Twig_Node_Expression_GetAttr::TYPE_ANY;
- $methodType = Twig_Node_Expression_GetAttr::TYPE_METHOD;
- $arrayType = Twig_Node_Expression_GetAttr::TYPE_ARRAY;
+ $anyType = Twig_TemplateInterface::ANY_CALL;
+ $methodType = Twig_TemplateInterface::METHOD_CALL;
+ $arrayType = Twig_TemplateInterface::ARRAY_CALL;
$tests = array(
// ARRAY
{
}
- public function getAttribute($object, $item, array $arguments = array(), $type = Twig_Node_Expression_GetAttr::TYPE_ANY, $noStrictCheck = false, $lineno = -1)
+ public function getAttribute($object, $item, array $arguments = array(), $type = Twig_TemplateInterface::ANY_CALL, $noStrictCheck = false, $lineno = -1)
{
return parent::getAttribute($object, $item, $arguments, $type);
}