{
$token = $this->parser->getStream()->next();
$lineno = $token->getLine();
+ $arguments = array();
if ($token->getValue() == '.')
{
$token = $this->parser->getStream()->next();
if ($token->getType() == Twig_Token::NAME_TYPE || $token->getType() == Twig_Token::NUMBER_TYPE)
{
$arg = new Twig_Node_Expression_Constant($token->getValue(), $lineno);
+
+ $arguments = $this->parseArguments();
}
else
{
$this->parser->getStream()->expect(Twig_Token::OPERATOR_TYPE, ']');
}
- return new Twig_Node_Expression_GetAttr($node, $arg, $lineno, $token->getValue());
+ return new Twig_Node_Expression_GetAttr($node, $arg, $arguments, $lineno, $token->getValue());
}
public function parseFilterExpression($node)
{
$this->parser->getStream()->next();
$token = $this->parser->getStream()->expect(Twig_Token::NAME_TYPE);
- $args = array();
- if ($this->parser->getStream()->test(Twig_Token::OPERATOR_TYPE, '('))
+
+ $filters[] = array($token->getValue(), $this->parseArguments());
+ }
+
+ return new Twig_Node_Expression_Filter($node, $filters, $lineno);
+ }
+
+ public function parseArguments()
+ {
+ if (!$this->parser->getStream()->test(Twig_Token::OPERATOR_TYPE, '('))
+ {
+ return array();
+ }
+
+ $args = array();
+ $this->parser->getStream()->next();
+ while (!$this->parser->getStream()->test(Twig_Token::OPERATOR_TYPE, ')'))
+ {
+ if (!empty($args))
{
- $this->parser->getStream()->next();
- while (!$this->parser->getStream()->test(Twig_Token::OPERATOR_TYPE, ')'))
- {
- if (!empty($args))
- {
- $this->parser->getStream()->expect(Twig_Token::OPERATOR_TYPE, ',');
- }
- $args[] = $this->parseExpression();
- }
- $this->parser->getStream()->expect(Twig_Token::OPERATOR_TYPE, ')');
+ $this->parser->getStream()->expect(Twig_Token::OPERATOR_TYPE, ',');
}
- $filters[] = array($token->getValue(), $args);
+ $args[] = $this->parseExpression();
}
+ $this->parser->getStream()->expect(Twig_Token::OPERATOR_TYPE, ')');
- return new Twig_Node_Expression_Filter($node, $filters, $lineno);
+ return $args;
}
public function parseAssignmentExpression()
{
protected $node;
protected $attr;
+ protected $arguments;
- public function __construct(Twig_Node $node, $attr, $lineno, $token_value)
+ public function __construct(Twig_Node $node, $attr, $arguments, $lineno, $token_value)
{
parent::__construct($lineno);
$this->node = $node;
$this->attr = $attr;
+ $this->arguments = $arguments;
$this->token_value = $token_value;
}
->subcompile($this->node)
->raw(', ')
->subcompile($this->attr)
+ ->raw(', array(')
;
- if ('[' == $this->token_value) # Don't look for functions if they're using foo[bar]
+ foreach ($this->arguments as $node)
{
- $compiler->raw(', false');
+ $compiler
+ ->subcompile($node)
+ ->raw(', ')
+ ;
+ }
+
+ $compiler->raw(')');
+
+ if ('[' == $this->token_value) // Don't look for functions if they're using foo[bar]
+ {
+ $compiler->raw(', true');
}
$compiler->raw(')');
throw new Twig_RuntimeError(sprintf('The filter "%s" does not exist', $name));
}
- protected function getAttribute($object, $item)
+ protected function getAttribute($object, $item, array $arguments = array(), $arrayOnly = false)
{
$item = (string) $item;
- if (is_array($object) && isset($object[$item]))
+ if (
+ is_array($object) && isset($object[$item])
+ ||
+ is_object($object) && $object instanceof ArrayAccess && isset($object[$item])
+ )
{
return $object[$item];
}
+ if ($arrayOnly)
+ {
+ return null;
+ }
+
if (
!is_object($object) ||
(
$this->env->getExtension('sandbox')->checkMethodAllowed($object, $method);
}
- return $object->$method();
+ return call_user_func_array(array($object, $method), $arguments);
}
}