mirror of
https://github.com/fenom-template/fenom.git
synced 2023-08-10 21:13:07 +03:00
Fix #105 + tests
This commit is contained in:
@@ -780,14 +780,7 @@ class Template extends Render
|
||||
if ($this->_options & Fenom::DENY_METHODS) {
|
||||
throw new \LogicException("Forbidden to call methods");
|
||||
}
|
||||
do { // parse call-chunks: $var->func()->func()->prop->func()->...
|
||||
if ($tokens->is('(')) {
|
||||
$code .= $this->parseArgs($tokens);
|
||||
}
|
||||
if ($tokens->is(T_OBJECT_OPERATOR) && $tokens->isNext(T_STRING)) {
|
||||
$code .= '->' . $tokens->next()->getAndNext();
|
||||
}
|
||||
} while ($tokens->is('(', T_OBJECT_OPERATOR));
|
||||
$code = $this->parseChain($tokens, $code);
|
||||
} elseif ($tokens->is(Tokenizer::MACRO_INCDEC)) {
|
||||
$code .= $tokens->getAndNext();
|
||||
} else {
|
||||
@@ -812,11 +805,11 @@ class Template extends Render
|
||||
if (!$func) {
|
||||
throw new \Exception("Function " . $tokens->getAndNext() . " not found");
|
||||
}
|
||||
return $unary . $func . $this->parseArgs($tokens->next());
|
||||
return $unary . $this->parseChain($tokens, $func . $this->parseArgs($tokens->next()));
|
||||
} elseif ($tokens->isNext(T_NS_SEPARATOR, T_DOUBLE_COLON)) {
|
||||
$method = $this->parseStatic($tokens);
|
||||
$args = $this->parseArgs($tokens);
|
||||
return $unary . $method . $args;
|
||||
return $unary . $this->parseChain($tokens, $method . $args);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@@ -841,6 +834,25 @@ class Template extends Render
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse call-chunks: $var->func()->func()->prop->func()->...
|
||||
* @param Tokenizer $tokens
|
||||
* @param string $code start point (it is $var)
|
||||
* @return string
|
||||
*/
|
||||
public function parseChain(Tokenizer $tokens, $code) {
|
||||
do {
|
||||
if ($tokens->is('(')) {
|
||||
$code .= $this->parseArgs($tokens);
|
||||
}
|
||||
if ($tokens->is(T_OBJECT_OPERATOR) && $tokens->isNext(T_STRING)) {
|
||||
$code .= '->' . $tokens->next()->getAndNext();
|
||||
}
|
||||
} while ($tokens->is('(', T_OBJECT_OPERATOR));
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse variable name: $a, $a.b, $a.b['c']
|
||||
* @param Tokenizer $tokens
|
||||
|
||||
Reference in New Issue
Block a user