diff --git a/src/Fenom.php b/src/Fenom.php index 4334b33..c0eb7bf 100644 --- a/src/Fenom.php +++ b/src/Fenom.php @@ -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' ) ); diff --git a/src/Fenom/Compiler.php b/src/Fenom/Compiler.php index d125856..30e390a 100644 --- a/src/Fenom/Compiler.php +++ b/src/Fenom/Compiler.php @@ -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).')'; + } }