Improve accessor: add writable condition

This commit is contained in:
bzick
2015-06-02 10:59:28 +03:00
parent ef4458ca10
commit e0fc70b751
3 changed files with 26 additions and 5 deletions

View File

@ -741,7 +741,16 @@ class Compiler
*/
public static function setOpen(Tokenizer $tokens, Tag $scope)
{
$var = $scope->tpl->parseVariable($tokens);
if($tokens->is(T_VARIABLE)) {
$var = $scope->tpl->parseVariable($tokens);
} elseif($tokens->is('$')) {
$var = $scope->tpl->parseAccessor($tokens, $is_var);
if(!$is_var) {
throw new InvalidUsageException("Accessor is not writable");
}
} else {
throw new InvalidUsageException("{set} and {add} accept only variable");
}
$before = $after = "";
if($scope->name == 'add') {
$before = "if(!isset($var)) {\n";