Add {unset …} (#29)

This commit is contained in:
bzick 2013-07-24 16:16:20 +04:00
parent 050523f249
commit 8030c12923
2 changed files with 23 additions and 0 deletions

View File

@ -228,6 +228,10 @@ class Fenom {
'type' => self::BLOCK_COMPILER,
'open' => 'Fenom\Compiler::autoescapeOpen',
'close' => 'Fenom\Compiler::autoescapeClose'
),
'unset' => array(
'type' => self::INLINE_COMPILER,
'parser' => 'Fenom\Compiler::tagUnset'
)
);

View File

@ -914,4 +914,23 @@ class Compiler {
public static function autoescapeClose(Tokenizer $tokens, Scope $scope) {
$scope->tpl->escape = $scope["escape"];
}
/**
* Unset present variables
*
* @param Tokenizer $tokens
* @param Template $tpl
* @return string
* @throws InvalidUsageException
*/
public static function tagUnset(Tokenizer $tokens, Template $tpl) {
$vars = array();
while($tokens->valid()) {
$vars[] = $tpl->parseVar($tokens);
}
if(!$vars) {
throw new InvalidUsageException("Unset must accept variable(s)");
}
return 'unset('.implode(', ', $vars).')';
}
}